SocketServer.h
Go to the documentation of this file.
1 /* -*- C++ -*- */
2 
3 /****************************************************************************
4 ** Copyright (c) 2001-2014
5 **
6 ** This file is part of the QuickFIX FIX Engine
7 **
8 ** This file may be distributed under the terms of the quickfixengine.org
9 ** license as defined by quickfixengine.org and appearing in the file
10 ** LICENSE included in the packaging of this file.
11 **
12 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14 **
15 ** See http://www.quickfixengine.org/LICENSE for licensing information.
16 **
17 ** Contact ask@quickfixengine.org if any conditions of this licensing are
18 ** not clear to you.
19 **
20 ****************************************************************************/
21 
22 #ifndef FIX_SOCKETSERVER_H
23 #define FIX_SOCKETSERVER_H
24 
25 #ifdef _MSC_VER
26 #pragma warning( disable : 4503 4355 4786 4290 )
27 #endif
28 
29 #include "SocketMonitor.h"
30 #include "Exceptions.h"
31 #include <map>
32 #include <set>
33 #include <queue>
34 
35 namespace FIX
36 {
38 struct SocketInfo
39 {
41  : m_socket( -1 ), m_port( 0 ), m_noDelay( false ),
42  m_sendBufSize( 0 ), m_rcvBufSize( 0 ) {}
43 
44  SocketInfo( int socket, short port, bool noDelay, int sendBufSize, int rcvBufSize )
45  : m_socket( socket ), m_port( port ), m_noDelay( noDelay ),
46  m_sendBufSize( sendBufSize ), m_rcvBufSize( rcvBufSize ) {}
47 
48  int m_socket;
49  short m_port;
50  bool m_noDelay;
53 };
54 
57 {
58 public:
59  class Strategy;
60 
61  SocketServer( int timeout = 0 );
62 
63  int add( int port, bool reuse = false, bool noDelay = false,
64  int sendBufSize = 0, int rcvBufSize = 0 ) throw( SocketException& );
65  int accept( int socket );
66  void close();
67  bool block( Strategy& strategy, bool poll = 0, double timeout = 0.0 );
68 
69  size_t numConnections() { return m_monitor.numSockets() - 1; }
71 
72  int socketToPort( int socket );
73  int portToSocket( int port );
74 
75 private:
76  typedef std::map<int, SocketInfo>
78  typedef std::map<int, SocketInfo>
80 
84 
85 public:
86  class Strategy
87  {
88  public:
89  virtual ~Strategy() {}
90  virtual void onConnect( SocketServer&, int acceptSocket, int socket ) = 0;
91  virtual void onWrite( SocketServer&, int socket ) = 0;
92  virtual bool onData( SocketServer&, int socket ) = 0;
93  virtual void onDisconnect( SocketServer&, int socket ) = 0;
94  virtual void onError( SocketServer& ) = 0;
95  virtual void onTimeout( SocketServer& ) {};
96  };
97 };
98 }
99 
100 #endif //FIX_SOCKETSERVER_H
Monitors events on a collection of sockets.
Definition: SocketMonitor.h:48
virtual void onConnect(SocketServer &, int acceptSocket, int socket)=0
virtual void onWrite(SocketServer &, int socket)=0
virtual bool onData(SocketServer &, int socket)=0
virtual void onTimeout(SocketServer &)
Definition: SocketServer.h:95
virtual void onDisconnect(SocketServer &, int socket)=0
virtual void onError(SocketServer &)=0
Listens for and accepts incoming socket connections on a port.
Definition: SocketServer.h:57
SocketServer(int timeout=0)
size_t numConnections()
Definition: SocketServer.h:69
int add(int port, bool reuse=false, bool noDelay=false, int sendBufSize=0, int rcvBufSize=0)
SocketMonitor m_monitor
Definition: SocketServer.h:83
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
int portToSocket(int port)
int socketToPort(int socket)
int accept(int socket)
SocketToInfo m_socketToInfo
Definition: SocketServer.h:81
PortToInfo m_portToInfo
Definition: SocketServer.h:82
SocketMonitor & getMonitor()
Definition: SocketServer.h:70
std::map< int, SocketInfo > PortToInfo
Definition: SocketServer.h:79
std::map< int, SocketInfo > SocketToInfo
Definition: SocketServer.h:77
Definition: Acceptor.cpp:35
Socket Error.
Definition: Exceptions.h:246
Information about listening socket.
Definition: SocketServer.h:39
SocketInfo(int socket, short port, bool noDelay, int sendBufSize, int rcvBufSize)
Definition: SocketServer.h:44

Generated on Wed Nov 24 2021 09:55:53 for QuickFIX by doxygen 1.9.1 written by Dimitri van Heesch, © 1997-2001