SocketConnector.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (c) 2001-2014
3 **
4 ** This file is part of the QuickFIX FIX Engine
5 **
6 ** This file may be distributed under the terms of the quickfixengine.org
7 ** license as defined by quickfixengine.org and appearing in the file
8 ** LICENSE included in the packaging of this file.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 ** See http://www.quickfixengine.org/LICENSE for licensing information.
14 **
15 ** Contact ask@quickfixengine.org if any conditions of this licensing are
16 ** not clear to you.
17 **
18 ****************************************************************************/
19 
20 #ifdef _MSC_VER
21 #include "stdafx.h"
22 #else
23 #include "config.h"
24 #endif
25 
26 #include "SocketConnector.h"
27 #include "Utility.h"
28 #ifndef _MSC_VER
29 #include <unistd.h>
30 #include <sys/ioctl.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #endif
34 #include <iostream>
35 
36 namespace FIX
37 {
40 {
41 public:
43  SocketConnector::Strategy& strategy )
44 : m_connector( connector ), m_strategy( strategy ) {}
45 
46 private:
47  void onConnect( SocketMonitor&, int socket )
48  {
49  m_strategy.onConnect( m_connector, socket );
50  }
51 
52  void onWrite( SocketMonitor&, int socket )
53  {
54  m_strategy.onWrite( m_connector, socket );
55  }
56 
57  void onEvent( SocketMonitor&, int socket )
58  {
59  if( !m_strategy.onData( m_connector, socket ) )
61  }
62 
63  void onError( SocketMonitor&, int socket )
64  {
66  }
67 
69  {
71  }
72 
74  {
76  };
77 
80 };
81 
83 : m_monitor( timeout ) {}
84 
85 int SocketConnector::connect( const std::string& address, int port, bool noDelay,
86  int sendBufSize, int rcvBufSize )
87 {
88  int socket = socket_createConnector();
89 
90  if ( socket != -1 )
91  {
92  if( noDelay )
93  socket_setsockopt( socket, TCP_NODELAY );
94  if( sendBufSize )
95  socket_setsockopt( socket, SO_SNDBUF, sendBufSize );
96  if( rcvBufSize )
97  socket_setsockopt( socket, SO_RCVBUF, rcvBufSize );
98  m_monitor.addConnect( socket );
99  socket_connect( socket, address.c_str(), port );
100  }
101  return socket;
102 }
103 
104 int SocketConnector::connect( const std::string& address, int port, bool noDelay,
105  int sendBufSize, int rcvBufSize, Strategy& strategy )
106 {
107  int socket = connect( address, port, noDelay, sendBufSize, rcvBufSize );
108  return socket;
109 }
110 
111 void SocketConnector::block( Strategy& strategy, bool poll, double timeout )
112 {
113  ConnectorWrapper wrapper( *this, strategy );
114  m_monitor.block( wrapper, poll, timeout );
115 }
116 }
SocketConnector & m_connector
Handles events from SocketMonitor for client connections.
int socket_connect(int socket, const char *address, int port)
Definition: Utility.cpp:131
void onTimeout(SocketMonitor &)
Connects sockets to remote ports and addresses.
virtual void onError(SocketConnector &)=0
void onConnect(SocketMonitor &, int socket)
int socket_createConnector()
Definition: Utility.cpp:126
virtual bool onData(SocketConnector &, int socket)=0
void onError(SocketMonitor &)
int socket_setsockopt(int s, int opt)
Definition: Utility.cpp:186
virtual void onConnect(SocketConnector &, int socket)=0
void onWrite(SocketMonitor &, int socket)
virtual void onDisconnect(SocketConnector &, int socket)=0
void block(Strategy &strategy, bool poll=0, double timeout=0.0)
Monitors events on a collection of sockets.
Definition: SocketMonitor.h:47
bool addConnect(int socket)
void block(Strategy &strategy, bool poll=0, double timeout=0.0)
virtual void onTimeout(SocketConnector &)
ConnectorWrapper(SocketConnector &connector, SocketConnector::Strategy &strategy)
SocketConnector(int timeout=0)
void onError(SocketMonitor &, int socket)
virtual void onWrite(SocketConnector &, int socket)=0
SocketMonitor m_monitor
int connect(const std::string &address, int port, bool noDelay, int sendBufSize, int rcvBufSize)
SocketConnector::Strategy & m_strategy
void onEvent(SocketMonitor &, int socket)

Generated on Sat Mar 29 2014 15:13:32 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001