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

Client (initiator) specialisation of Connection. More...

#include <connection.hpp>

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

Public Member Functions

 ClientConnection (Poco::Net::StreamSocket *sock, Poco::Net::SocketAddress &addr, Session &session, unsigned hb_interval, ProcessModel pmodel=pm_pipeline, bool no_delay=true, bool secured=false)
 
virtual ~ClientConnection ()
 Dtor. More...
 
F8API bool connect ()
 
- Public Member Functions inherited from FIX8::Connection
 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...
 
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
 

Private Attributes

const bool _no_delay
 

Additional Inherited Members

- Public Types inherited from FIX8::Connection
enum  Role { cn_acceptor, cn_initiator, cn_unknown }
 Roles: acceptor, initiator or unknown. More...
 
- Static Public Member Functions inherited from FIX8::Connection
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 inherited from FIX8::Connection
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

Client (initiator) specialisation of Connection.

Definition at line 693 of file connection.hpp.

Constructor & Destructor Documentation

FIX8::ClientConnection::ClientConnection ( Poco::Net::StreamSocket *  sock,
Poco::Net::SocketAddress &  addr,
Session session,
unsigned  hb_interval,
ProcessModel  pmodel = pm_pipeline,
bool  no_delay = true,
bool  secured = false 
)
inline

Ctor. Initiator.

Parameters
sockconnected socket
addrsock address structure
sessionsession
hb_intervalheartbeat interval
pmodelprocess model
no_delayset or clear the tcp no delay flag on the socket
securedtrue for ssl connection

Definition at line 707 of file connection.hpp.

710  : Connection(sock, addr, session, cn_initiator, pmodel, hb_interval, secured), _no_delay(no_delay) {}
Connection(Poco::Net::StreamSocket *sock, Poco::Net::SocketAddress &addr, Session &session, Role role, const ProcessModel pmodel, unsigned hb_interval, bool secured)
Definition: connection.hpp:537
virtual FIX8::ClientConnection::~ClientConnection ( )
inlinevirtual

Dtor.

Definition at line 713 of file connection.hpp.

713 {}

Member Function Documentation

bool ClientConnection::connect ( )
virtual

Establish connection.

Returns
true on success

Reimplemented from FIX8::Connection.

Definition at line 337 of file connection.cpp.

References FIX8::hypersleep< h_milliseconds >(), scout_debug, scout_error, and scout_info.

338 {
339  unsigned attempts(0);
341  const Poco::Timespan timeout(lparam._connect_timeout, 0);
342 
343  while (attempts < (lparam._reliable ? 1 : lparam._login_retries))
344  {
345  try
346  {
347  if (_addr == Poco::Net::SocketAddress())
348  throw Poco::Net::InvalidAddressException("empty address");
349 
350  scout_info << "Trying to connect to: " << _addr.toString() << " (" << ++attempts << ')' << ( _secured ? " secured" : " not-secured");
351  _sock->connect(_addr, timeout);
352  if (lparam._recv_buf_sz)
353  set_recv_buf_sz(lparam._recv_buf_sz);
354  if (lparam._send_buf_sz)
355  set_send_buf_sz(lparam._send_buf_sz);
356  _sock->setLinger(false, 0);
357  _sock->setNoDelay(_no_delay);
358  scout_info << "Connection successful";
359  return _connected = true;
360  }
361  catch (Poco::Exception& e)
362  {
363  if (lparam._reliable)
364  {
365  scout_debug << "rethrowing Poco::Exception: " << e.displayText();
366  throw;
367  }
368  scout_error << "exception: " << e.displayText();
369  hypersleep<h_milliseconds>(lparam._login_retry_interval);
370  }
371  catch (exception& e)
372  {
373  if (lparam._reliable)
374  {
375  scout_debug << "rethrowing exception: " << e.what();
376  throw;
377  }
378  scout_error << "exception: " << e.what();
379  hypersleep<h_milliseconds>(lparam._login_retry_interval);
380  }
381  }
382 
383  scout_error << "Connection failed";
384  return false;
385 }
f8_atomic< bool > _connected
Definition: connection.hpp:517
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 set_send_buf_sz(const unsigned sz, Poco::Net::Socket *sock)
Definition: connection.hpp:644
int hypersleep< h_milliseconds >(unsigned amt)
Definition: hypersleep.hpp:105
Poco::Net::SocketAddress _addr
Definition: connection.hpp:516
Session & _session
Definition: connection.hpp:518
#define scout_info
Definition: connection.hpp:755
#define scout_error
Definition: connection.hpp:757
#define scout_debug
Definition: connection.hpp:759
void get_login_parameters(LoginParameters &loginParamaters) const
Definition: session.hpp:758

Member Data Documentation

const bool FIX8::ClientConnection::_no_delay
private

Definition at line 695 of file connection.hpp.


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