fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::Connection Class Reference

Complete Fix connection (reader and writer). More...

#include <connection.hpp>

Inheritance diagram for FIX8::Connection:
FIX8::ClientConnection FIX8::ServerConnection

Public Types

enum  Role { cn_acceptor, cn_initiator, cn_unknown }
 Roles: acceptor, initiator or unknown. More...
 

Public Member Functions

 Connection (Poco::Net::StreamSocket *sock, Poco::Net::SocketAddress &addr, Session &session, Role role, const ProcessModel pmodel, unsigned hb_interval, bool secured)
 
virtual ~Connection ()
 Dtor. More...
 
Role get_role () const
 
ProcessModel get_pmodel () const
 
bool is_secure () const
 
F8API void start ()
 Start the reader and writer threads. More...
 
F8API void stop ()
 Stop the reader and writer threads. More...
 
virtual bool connect ()
 
bool is_connected () const
 
virtual bool write (Message *from, bool destroy=true)
 
virtual bool write (Message &from)
 
size_t write_batch (const std::vector< Message * > &msgs, bool destroy)
 
int send (const char *from, size_t sz)
 
int send (const f8String &from)
 
void set_hb_interval (const unsigned hb_interval)
 
unsigned get_hb_interval () const
 
unsigned get_hb_interval20pc () const
 
Poco::Net::SocketAddress get_peer_socket_address () const
 
const Poco::Net::SocketAddress & get_socket_address () const
 
int join ()
 
bool is_socket_error () const
 
void set_recv_buf_sz (const unsigned sz) const
 
void set_send_buf_sz (const unsigned sz) const
 
void set_tcp_cork_flag (bool way) const
 
Sessionget_session ()
 
int reader_execute ()
 
bool reader_poll (const Poco::Timespan &ts=Poco::Timespan()) const
 
int writer_execute ()
 
bool writer_poll (const Poco::Timespan &ts=Poco::Timespan()) const
 

Static Public Member Functions

static void set_recv_buf_sz (const unsigned sz, Poco::Net::Socket *sock)
 
static void set_send_buf_sz (const unsigned sz, Poco::Net::Socket *sock)
 

Protected Attributes

Poco::Net::StreamSocket * _sock
 
Poco::Net::SocketAddress _addr
 
f8_atomic< bool > _connected
 
Session_session
 
Role _role
 
ProcessModel _pmodel
 
unsigned _hb_interval
 
unsigned _hb_interval20pc
 
FIXReader _reader
 
FIXWriter _writer
 
bool _secured
 

Detailed Description

Complete Fix connection (reader and writer).

Definition at line 508 of file connection.hpp.

Member Enumeration Documentation

Roles: acceptor, initiator or unknown.

Enumerator
cn_acceptor 
cn_initiator 
cn_unknown 

Definition at line 512 of file connection.hpp.

Constructor & Destructor Documentation

FIX8::Connection::Connection ( Poco::Net::StreamSocket *  sock,
Poco::Net::SocketAddress &  addr,
Session session,
Role  role,
const ProcessModel  pmodel,
unsigned  hb_interval,
bool  secured 
)
inline

Ctor.

Parameters
sockconnected socket
addrsock address structure
sessionsession
roleconnection role
pmodelprocess model
hb_intervalheartbeat interval
securedtrue for ssl connection

Definition at line 537 of file connection.hpp.

539  : _sock(sock), _addr(addr), _connected(role == cn_acceptor), _session(session), _role(role), _pmodel(pmodel),
541  _reader(sock, session, pmodel), _writer(sock, session, pmodel),
542  _secured(secured) {}
f8_atomic< bool > _connected
Definition: connection.hpp:517
FIXReader _reader
Definition: connection.hpp:523
Poco::Net::StreamSocket * _sock
Definition: connection.hpp:515
FIXWriter _writer
Definition: connection.hpp:524
unsigned _hb_interval20pc
Definition: connection.hpp:521
Poco::Net::SocketAddress _addr
Definition: connection.hpp:516
Session & _session
Definition: connection.hpp:518
unsigned _hb_interval
Definition: connection.hpp:521
ProcessModel _pmodel
Definition: connection.hpp:520
virtual FIX8::Connection::~Connection ( )
inlinevirtual

Dtor.

Definition at line 545 of file connection.hpp.

References FIX8::Session::clear_connection(), and stop().

545 { stop(); _session.clear_connection(this); }
F8API void stop()
Stop the reader and writer threads.
Definition: connection.cpp:322
void clear_connection(const Connection *connection)
Definition: session.hpp:586
Session & _session
Definition: connection.hpp:518

Member Function Documentation

virtual bool FIX8::Connection::connect ( )
inlinevirtual

Get the connection state.

Returns
true if connected

Reimplemented in FIX8::ClientConnection.

Definition at line 567 of file connection.hpp.

References _connected.

Referenced by FIX8::Session::start().

567 { return _connected; }
f8_atomic< bool > _connected
Definition: connection.hpp:517
unsigned FIX8::Connection::get_hb_interval ( ) const
inline

Get the heartbeat interval for this connection.

Returns
the heartbeat interval

Definition at line 608 of file connection.hpp.

References _hb_interval.

Referenced by FIX8::Session::handle_logon(), FIX8::Session::heartbeat_service(), and FIX8::Session::start().

608 { return _hb_interval; }
unsigned _hb_interval
Definition: connection.hpp:521
unsigned FIX8::Connection::get_hb_interval20pc ( ) const
inline

Get the heartbeat interval + %20 for this connection.

Returns
the heartbeat interval + %20

Definition at line 612 of file connection.hpp.

References _hb_interval20pc.

Referenced by FIX8::Session::heartbeat_service().

612 { return _hb_interval20pc; }
unsigned _hb_interval20pc
Definition: connection.hpp:521
Poco::Net::SocketAddress FIX8::Connection::get_peer_socket_address ( ) const
inline

Get the peer socket address

Returns
peer socket address reference

Definition at line 616 of file connection.hpp.

Referenced by FIX8::Session::handle_logon().

616 { return _sock->peerAddress(); }
Poco::Net::StreamSocket * _sock
Definition: connection.hpp:515
ProcessModel FIX8::Connection::get_pmodel ( ) const
inline

Get the process model

Returns
the process model

Definition at line 553 of file connection.hpp.

References _pmodel.

Referenced by FIX8::Session::handle_logon(), FIX8::Session::recover_seqnums(), FIX8::Session::send_process(), FIX8::Session::stop(), and FIX8::Session::update_persist_seqnums().

553 { return _pmodel; }
ProcessModel _pmodel
Definition: connection.hpp:520
Role FIX8::Connection::get_role ( ) const
inline

Get the role for this connection.

Returns
the role

Definition at line 549 of file connection.hpp.

References _role.

Referenced by FIX8::Session::handle_logon(), FIX8::Session::start(), FIX8::Session::stop(), and FIX8::Session::~Session().

549 { return _role; }
Session& FIX8::Connection::get_session ( )
inline

Get the session associated with this connection.

Returns
the session

Definition at line 670 of file connection.hpp.

References _session.

670 { return _session; }
Session & _session
Definition: connection.hpp:518
const Poco::Net::SocketAddress& FIX8::Connection::get_socket_address ( ) const
inline

Get the socket address

Returns
socket address reference

Definition at line 620 of file connection.hpp.

References _addr.

620 { return _addr; }
Poco::Net::SocketAddress _addr
Definition: connection.hpp:516
bool FIX8::Connection::is_connected ( ) const
inline

Determine if this session is actually connected

Returns
true if connected

Definition at line 571 of file connection.hpp.

References _connected.

Referenced by FIX8::Session::activation_service(), and FIX8::Session::heartbeat_service().

571 { return _connected; }
f8_atomic< bool > _connected
Definition: connection.hpp:517
bool FIX8::Connection::is_secure ( ) const
inline

Check if this connection is secure

Returns
true if secure

Definition at line 557 of file connection.hpp.

References _secured.

557 { return _secured; }
bool FIX8::Connection::is_socket_error ( ) const
inline

Check to see if the socket is in error

Returns
true if there was a socket error

Definition at line 628 of file connection.hpp.

References FIX8::FIXReader::is_socket_error().

628 { return _reader.is_socket_error(); }
FIXReader _reader
Definition: connection.hpp:523
bool is_socket_error() const
Definition: connection.hpp:325
int FIX8::Connection::join ( )
inline

Wait till reader thead has finished.

Returns
0 on success

Definition at line 624 of file connection.hpp.

References FIX8::FIXReader::join().

Referenced by FIX8::Session::start().

624 { return _reader.join(); }
FIXReader _reader
Definition: connection.hpp:523
int FIX8::Connection::reader_execute ( )
inline

Call the FIXreader method

Returns
result of call

Definition at line 674 of file connection.hpp.

References FIX8::AsyncSocket< T >::cancellation_token(), and FIX8::FIXReader::execute().

FIXReader _reader
Definition: connection.hpp:523
virtual F8API int execute(f8_thread_cancellation_token &cancellation_token)
Definition: connection.cpp:45
f8_thread_cancellation_token & cancellation_token()
Definition: connection.hpp:129
bool FIX8::Connection::reader_poll ( const Poco::Timespan &  ts = Poco::Timespan()) const
inline

Check if the reader will block

Parameters
tstimeout
Returns
true if won't block

Definition at line 679 of file connection.hpp.

References FIX8::FIXReader::poll().

679 { return _reader.poll(ts); }
FIXReader _reader
Definition: connection.hpp:523
bool poll(const Poco::Timespan &ts=Poco::Timespan()) const
Definition: connection.hpp:330
int FIX8::Connection::send ( const char *  from,
size_t  sz 
)
inline

Write a string message to the underlying socket.

Parameters
fromMessage (string) to write
sznumber bytes to send
Returns
number of bytes written

Definition at line 594 of file connection.hpp.

References FIX8::FIXWriter::send().

Referenced by FIX8::Session::send_process().

594 { return _writer.send(from, sz); }
FIXWriter _writer
Definition: connection.hpp:524
int send(const char *data, size_t remaining, bool nb=false)
Definition: connection.hpp:438
int FIX8::Connection::send ( const f8String from)
inline

Write a string message to the underlying socket.

Parameters
fromMessage (string) to write
Returns
number of bytes written

Definition at line 599 of file connection.hpp.

References FIX8::FIXWriter::send().

599 { return _writer.send(from.data(), from.size()); }
FIXWriter _writer
Definition: connection.hpp:524
int send(const char *data, size_t remaining, bool nb=false)
Definition: connection.hpp:438
void FIX8::Connection::set_hb_interval ( const unsigned  hb_interval)
inline

Set the heartbeat interval for this connection.

Parameters
hb_intervalheartbeat interval

Definition at line 603 of file connection.hpp.

References FIX8::defaults::hb_interval.

Referenced by FIX8::Session::handle_logon().

static void FIX8::Connection::set_recv_buf_sz ( const unsigned  sz,
Poco::Net::Socket *  sock 
)
inlinestatic

Set the socket recv buffer sz

Parameters
socksocket to operate on
sznew size

Definition at line 633 of file connection.hpp.

References glout_info.

Referenced by FIX8::ServerSession< T >::ServerSession().

634  {
635  const unsigned current_sz(sock->getReceiveBufferSize());
636  sock->setReceiveBufferSize(sz);
637  glout_info << "fd(" << sock->impl()->sockfd() << ") ReceiveBufferSize old:" << current_sz
638  << " requested:" << sz << " new:" << sock->getReceiveBufferSize();
639  }
#define glout_info
Definition: logger.hpp:601
void FIX8::Connection::set_recv_buf_sz ( const unsigned  sz) const
inline

Set the socket recv buffer sz

Parameters
sznew size

Definition at line 653 of file connection.hpp.

References set_recv_buf_sz().

Referenced by set_recv_buf_sz().

653 { set_recv_buf_sz(sz, _sock); }
static void set_recv_buf_sz(const unsigned sz, Poco::Net::Socket *sock)
Definition: connection.hpp:633
Poco::Net::StreamSocket * _sock
Definition: connection.hpp:515
static void FIX8::Connection::set_send_buf_sz ( const unsigned  sz,
Poco::Net::Socket *  sock 
)
inlinestatic

Set the socket send buffer sz

Parameters
socksocket to operate on
sznew size

Definition at line 644 of file connection.hpp.

References glout_info.

Referenced by FIX8::ServerSession< T >::ServerSession().

645  {
646  const unsigned current_sz(sock->getSendBufferSize());
647  sock->setSendBufferSize(sz);
648  glout_info << "fd(" << sock->impl()->sockfd() << ") SendBufferSize old:" << current_sz
649  << " requested:" << sz << " new:" << sock->getSendBufferSize();
650  }
#define glout_info
Definition: logger.hpp:601
void FIX8::Connection::set_send_buf_sz ( const unsigned  sz) const
inline

Set the socket send buffer sz

Parameters
sznew size

Definition at line 657 of file connection.hpp.

References set_send_buf_sz().

Referenced by set_send_buf_sz().

657 { set_send_buf_sz(sz, _sock); }
Poco::Net::StreamSocket * _sock
Definition: connection.hpp:515
static void set_send_buf_sz(const unsigned sz, Poco::Net::Socket *sock)
Definition: connection.hpp:644
void FIX8::Connection::set_tcp_cork_flag ( bool  way) const
inline

Set the tcp_cork flag

Parameters
wayboolean true (on) or false(clear)

Definition at line 661 of file connection.hpp.

Referenced by MyMenu::send_all_preloaded().

662  {
663 #if defined FIX8_HAVE_DECL_TCP_CORK && TCP_CORK != 0
664  _sock->setOption(IPPROTO_TCP, TCP_CORK, way ? 1 : 0);
665 #endif
666  }
Poco::Net::StreamSocket * _sock
Definition: connection.hpp:515
void Connection::start ( )

Start the reader and writer threads.

Definition at line 315 of file connection.cpp.

Referenced by FIX8::ReliableClientSession< T >::operator()(), and FIX8::Session::start().

316 {
317  _writer.start();
318  _reader.start();
319 }
virtual void start()
Start the processing threads.
Definition: connection.hpp:468
FIXReader _reader
Definition: connection.hpp:523
FIXWriter _writer
Definition: connection.hpp:524
virtual void start()
Start the processing threads.
Definition: connection.hpp:263
void Connection::stop ( )

Stop the reader and writer threads.

Definition at line 322 of file connection.cpp.

References scout_debug.

Referenced by FIX8::Session::stop(), ~Connection(), and FIX8::SessionInstance< T >::~SessionInstance().

323 {
324  scout_debug << "Connection::stop()";
325  _writer.stop();
326  _writer.join();
327 
328  scout_debug << "Connection::stop() => _reader.stop()";
329  _reader.stop();
330  if (_reader.started())
331  _reader.socket()->shutdown();
332  _reader.join();
333 }
FIXReader _reader
Definition: connection.hpp:523
FIXWriter _writer
Definition: connection.hpp:524
Poco::Net::StreamSocket * socket()
Definition: connection.hpp:121
bool started() const
Definition: connection.hpp:85
virtual void stop()
Send a message to the processing method instructing it to quit.
Definition: connection.hpp:288
virtual void stop()
Send a message to the processing method instructing it to quit.
Definition: connection.hpp:475
#define scout_debug
Definition: connection.hpp:759
virtual bool FIX8::Connection::write ( Message from,
bool  destroy = true 
)
inlinevirtual

Write a message to the underlying socket.

Parameters
fromMessage to write
destroyif true delete after send
Returns
true on success

Definition at line 577 of file connection.hpp.

References FIX8::FIXWriter::write().

Referenced by FIX8::Session::send().

577 { return _writer.write(from, destroy); }
bool write(Message *from, bool destroy)
Definition: connection.hpp:362
FIXWriter _writer
Definition: connection.hpp:524
virtual bool FIX8::Connection::write ( Message from)
inlinevirtual

Write a message to the underlying socket. Non-pipelined version.

Parameters
fromMessage to write
Returns
true on success

Definition at line 582 of file connection.hpp.

References FIX8::FIXWriter::write().

582 { return _writer.write(from); }
bool write(Message *from, bool destroy)
Definition: connection.hpp:362
FIXWriter _writer
Definition: connection.hpp:524
size_t FIX8::Connection::write_batch ( const std::vector< Message * > &  msgs,
bool  destroy 
)
inline

Write messages to the underlying socket as a single batch.

Parameters
msgsvector of Message to write
destroyif true delete after send
Returns
true on success

Definition at line 588 of file connection.hpp.

References FIX8::FIXWriter::write_batch().

Referenced by FIX8::Session::send_batch().

588 { return _writer.write_batch(msgs, destroy); }
FIXWriter _writer
Definition: connection.hpp:524
size_t write_batch(const std::vector< Message * > &msgs, bool destroy)
Definition: connection.hpp:379
int FIX8::Connection::writer_execute ( )
inline

Call the FIXreader method

Returns
result of call

Definition at line 683 of file connection.hpp.

References FIX8::AsyncSocket< T >::cancellation_token(), and FIX8::FIXWriter::execute().

FIXWriter _writer
Definition: connection.hpp:524
f8_thread_cancellation_token & cancellation_token()
Definition: connection.hpp:129
virtual F8API int execute(f8_thread_cancellation_token &cancellation_token)
Definition: connection.cpp:269
bool FIX8::Connection::writer_poll ( const Poco::Timespan &  ts = Poco::Timespan()) const
inline

Check if the writer will block

Parameters
tstimeout
Returns
true if won't block

Definition at line 688 of file connection.hpp.

References FIX8::FIXWriter::poll().

Referenced by MyMenu::send_all_preloaded().

688 { return _writer.poll(ts); }
FIXWriter _writer
Definition: connection.hpp:524
bool poll(const Poco::Timespan &ts=Poco::Timespan()) const
Definition: connection.hpp:428

Member Data Documentation

Poco::Net::SocketAddress FIX8::Connection::_addr
protected

Definition at line 516 of file connection.hpp.

Referenced by get_socket_address().

f8_atomic<bool> FIX8::Connection::_connected
protected

Definition at line 517 of file connection.hpp.

Referenced by connect(), and is_connected().

unsigned FIX8::Connection::_hb_interval
protected

Definition at line 521 of file connection.hpp.

Referenced by get_hb_interval().

unsigned FIX8::Connection::_hb_interval20pc
protected

Definition at line 521 of file connection.hpp.

Referenced by get_hb_interval20pc().

ProcessModel FIX8::Connection::_pmodel
protected

Definition at line 520 of file connection.hpp.

Referenced by get_pmodel().

FIXReader FIX8::Connection::_reader
protected

Definition at line 523 of file connection.hpp.

Role FIX8::Connection::_role
protected

Definition at line 519 of file connection.hpp.

Referenced by get_role().

bool FIX8::Connection::_secured
protected

Definition at line 525 of file connection.hpp.

Referenced by is_secure().

Session& FIX8::Connection::_session
protected

Definition at line 518 of file connection.hpp.

Referenced by get_session().

Poco::Net::StreamSocket* FIX8::Connection::_sock
protected

Definition at line 515 of file connection.hpp.

FIXWriter FIX8::Connection::_writer
protected

Definition at line 524 of file connection.hpp.


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