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
35namespace FIX
36{
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
49 short m_port;
53};
54
57{
58public:
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
75private:
76 typedef std::map<int, SocketInfo>
78 typedef std::map<int, SocketInfo>
80
84
85public:
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.
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 &)
virtual void onDisconnect(SocketServer &, int socket)=0
virtual void onError(SocketServer &)=0
Listens for and accepts incoming socket connections on a port.
size_t numConnections()
int add(int port, bool reuse=false, bool noDelay=false, int sendBufSize=0, int rcvBufSize=0)
SocketMonitor m_monitor
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
int portToSocket(int port)
int socketToPort(int socket)
int accept(int socket)
SocketMonitor & getMonitor()
SocketToInfo m_socketToInfo
PortToInfo m_portToInfo
std::map< int, SocketInfo > PortToInfo
std::map< int, SocketInfo > SocketToInfo
Socket Error.
Definition Exceptions.h:246
Information about listening socket.
SocketInfo(int socket, short port, bool noDelay, int sendBufSize, int rcvBufSize)

Generated on Mon Oct 14 2024 06:04:44 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001