fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::AsyncSocket< T > Class Template Reference

Half duplex async socket wrapper with thread. More...

#include <connection.hpp>

Public Member Functions

 AsyncSocket (Poco::Net::StreamSocket *sock, Session &session, const ProcessModel pmodel=pm_pipeline)
 
virtual ~AsyncSocket ()=default
 Dtor. More...
 
size_t queued () const
 
bool started () const
 
int operator() ()
 
virtual int execute (f8_thread_cancellation_token &cancellation_token)
 
virtual void start ()
 Start the processing thread. More...
 
virtual void request_stop ()
 Start the processing thread. More...
 
virtual void quit ()
 Stop the processing thread and quit. More...
 
Poco::Net::StreamSocket * socket ()
 
int join ()
 
f8_thread_cancellation_tokencancellation_token ()
 

Protected Attributes

coroutine _coro
 
Poco::Net::StreamSocket * _sock
 
f8_concurrent_queue< T > _msg_queue
 
Session_session
 
ProcessModel _pmodel
 
f8_thread_cancellation_token _cancellation_token
 
volatile bool _started
 
f8_mutex _start_mutex
 

Private Attributes

f8_thread< AsyncSocket_thread
 

Detailed Description

template<typename T>
class FIX8::AsyncSocket< T >

Half duplex async socket wrapper with thread.

Template Parameters
Tthe object type to queue

Definition at line 53 of file connection.hpp.

Constructor & Destructor Documentation

template<typename T>
FIX8::AsyncSocket< T >::AsyncSocket ( Poco::Net::StreamSocket *  sock,
Session session,
const ProcessModel  pmodel = pm_pipeline 
)
inline

Ctor.

Parameters
sockconnected socket
sessionsession
pmodelprocess model

Definition at line 73 of file connection.hpp.

74  : _sock(sock), _session(session), _pmodel(pmodel), _started(false), _thread(std::ref(*this)) {}
Session & _session
Definition: connection.hpp:59
ProcessModel _pmodel
Definition: connection.hpp:60
f8_thread< AsyncSocket > _thread
Definition: connection.hpp:66
Poco::Net::StreamSocket * _sock
Definition: connection.hpp:57
volatile bool _started
Definition: connection.hpp:62
template<typename T>
virtual FIX8::AsyncSocket< T >::~AsyncSocket ( )
virtualdefault

Dtor.

Member Function Documentation

template<typename T>
f8_thread_cancellation_token& FIX8::AsyncSocket< T >::cancellation_token ( )
inline

Obtain the thread cancellation token

Returns
the token

Definition at line 129 of file connection.hpp.

Referenced by FIX8::Connection::reader_execute(), and FIX8::Connection::writer_execute().

129 { return _cancellation_token; }
f8_thread_cancellation_token _cancellation_token
Definition: connection.hpp:61
template<typename T>
virtual int FIX8::AsyncSocket< T >::execute ( f8_thread_cancellation_token cancellation_token)
inlinevirtual

Execute the function operator

Returns
result of operator

Reimplemented in FIX8::FIXWriter, and FIX8::FIXReader.

Definition at line 93 of file connection.hpp.

Referenced by FIX8::AsyncSocket< f8String >::operator()().

93 { return 0; }
template<typename T>
int FIX8::AsyncSocket< T >::join ( )
inline

Wait till processing thread has finished.

Returns
0 on success

Definition at line 125 of file connection.hpp.

Referenced by FIX8::FIXReader::join(), FIX8::FIXWriter::join(), and FIX8::AsyncSocket< f8String >::quit().

125 { return _thread.join(); }
f8_thread< AsyncSocket > _thread
Definition: connection.hpp:66
template<typename T>
int FIX8::AsyncSocket< T >::operator() ( )
inline

Function operator. Called by thread to process message on queue.

Returns
0 on success

Definition at line 89 of file connection.hpp.

89 { return execute(_cancellation_token); }
virtual int execute(f8_thread_cancellation_token &cancellation_token)
Definition: connection.hpp:93
f8_thread_cancellation_token _cancellation_token
Definition: connection.hpp:61
template<typename T>
size_t FIX8::AsyncSocket< T >::queued ( ) const
inline

Get the number of messages queued on this socket.

Returns
number of queued messages

Definition at line 81 of file connection.hpp.

81 { return _msg_queue.size(); }
f8_concurrent_queue< T > _msg_queue
Definition: connection.hpp:58
template<typename T>
virtual void FIX8::AsyncSocket< T >::quit ( )
inlinevirtual

Stop the processing thread and quit.

Reimplemented in FIX8::FIXWriter, and FIX8::FIXReader.

Definition at line 117 of file connection.hpp.

Referenced by FIX8::FIXReader::quit(), and FIX8::FIXWriter::quit().

117 { _thread.request_stop(); join(); }
f8_thread< AsyncSocket > _thread
Definition: connection.hpp:66
template<typename T>
virtual void FIX8::AsyncSocket< T >::request_stop ( )
inlinevirtual

Start the processing thread.

Definition at line 114 of file connection.hpp.

Referenced by FIX8::FIXReader::stop(), and FIX8::FIXWriter::stop().

114 { _thread.request_stop(); }
f8_thread< AsyncSocket > _thread
Definition: connection.hpp:66
template<typename T>
Poco::Net::StreamSocket* FIX8::AsyncSocket< T >::socket ( )
inline

Get the underlying socket object.

Returns
the socket

Definition at line 121 of file connection.hpp.

121 { return _sock; }
Poco::Net::StreamSocket * _sock
Definition: connection.hpp:57
template<typename T>
virtual void FIX8::AsyncSocket< T >::start ( )
inlinevirtual

Start the processing thread.

Reimplemented in FIX8::FIXWriter, and FIX8::FIXReader.

Definition at line 96 of file connection.hpp.

Referenced by FIX8::FIXReader::start(), and FIX8::FIXWriter::start().

97  {
98  if (!_started)
99  {
101  if (!_started)
102  {
103  _started = true;
104  _thread.start();
105  }
106  }
107  else
108  {
109  glout_warn << "AsyncSocket already started.";
110  }
111  }
f8_scoped_lock_impl< f8_mutex > f8_scoped_lock
Definition: thread.hpp:451
f8_thread< AsyncSocket > _thread
Definition: connection.hpp:66
#define glout_warn
Definition: logger.hpp:604
f8_mutex _start_mutex
Definition: connection.hpp:63
volatile bool _started
Definition: connection.hpp:62
template<typename T>
bool FIX8::AsyncSocket< T >::started ( ) const
inline

Check if this socket has started

Returns
true if started

Definition at line 85 of file connection.hpp.

85 { return _started; }
volatile bool _started
Definition: connection.hpp:62

Member Data Documentation

template<typename T>
f8_thread_cancellation_token FIX8::AsyncSocket< T >::_cancellation_token
protected

Definition at line 61 of file connection.hpp.

Referenced by FIX8::AsyncSocket< f8String >::cancellation_token().

template<typename T>
coroutine FIX8::AsyncSocket< T >::_coro
protected

Definition at line 56 of file connection.hpp.

template<typename T>
f8_concurrent_queue<T> FIX8::AsyncSocket< T >::_msg_queue
protected

Definition at line 58 of file connection.hpp.

template<typename T>
ProcessModel FIX8::AsyncSocket< T >::_pmodel
protected

Definition at line 60 of file connection.hpp.

template<typename T>
Session& FIX8::AsyncSocket< T >::_session
protected

Definition at line 59 of file connection.hpp.

template<typename T>
Poco::Net::StreamSocket* FIX8::AsyncSocket< T >::_sock
protected

Definition at line 57 of file connection.hpp.

Referenced by FIX8::AsyncSocket< f8String >::socket().

template<typename T>
f8_mutex FIX8::AsyncSocket< T >::_start_mutex
protected

Definition at line 63 of file connection.hpp.

template<typename T>
volatile bool FIX8::AsyncSocket< T >::_started
protected

Definition at line 62 of file connection.hpp.

Referenced by FIX8::AsyncSocket< f8String >::started().

template<typename T>
f8_thread<AsyncSocket> FIX8::AsyncSocket< T >::_thread
private

Definition at line 66 of file connection.hpp.


The documentation for this class was generated from the following file: