SocketMonitor.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_SOCKETMONITOR_H
23#define FIX_SOCKETMONITOR_H
24
25#ifdef _MSC_VER
26#pragma warning( disable : 4503 4355 4786 4290 )
27#endif
28
29#ifdef _MSC_VER
30#include <Winsock2.h>
31typedef int socklen_t;
32#else
33#include <sys/types.h>
34#include <sys/socket.h>
35#include <sys/time.h>
36#include <netinet/in.h>
37#include <arpa/inet.h>
38#endif
39
40#include <set>
41#include <queue>
42#include <time.h>
43
44namespace FIX
45{
48{
49public:
50 class Strategy;
51
52 SocketMonitor( int timeout = 0 );
53 virtual ~SocketMonitor();
54
55 bool addConnect( int socket );
56 bool addRead( int socket );
57 bool addWrite( int socket );
58 bool drop( int socket );
59 void signal( int socket );
60 void unsignal( int socket );
61 void block( Strategy& strategy, bool poll = 0, double timeout = 0.0 );
62
63 size_t numSockets()
64 { return m_readSockets.size() - 1; }
65
66private:
67 typedef std::set < int > Sockets;
68 typedef std::queue < int > Queue;
69
70 void setsockopt();
71 bool bind();
72 bool listen();
73 void buildSet( const Sockets&, fd_set& );
74 inline timeval* getTimeval( bool poll, double timeout );
75 inline bool sleepIfEmpty( bool poll );
76
77 void processReadSet( Strategy&, fd_set& );
78 void processWriteSet( Strategy&, fd_set& );
79 void processExceptSet( Strategy&, fd_set& );
80
82 timeval m_timeval;
83#ifndef SELECT_DECREMENTS_TIME
84 clock_t m_ticks;
85#endif
86
93
94public:
96 {
97 public:
98 virtual ~Strategy()
99 {}
100 virtual void onConnect( SocketMonitor&, int socket ) = 0;
101 virtual void onEvent( SocketMonitor&, int socket ) = 0;
102 virtual void onWrite( SocketMonitor&, int socket ) = 0;
103 virtual void onError( SocketMonitor&, int socket ) = 0;
104 virtual void onError( SocketMonitor& ) = 0;
105 virtual void onTimeout( SocketMonitor& )
106 {}}
107 ;
108};
109}
110
111#endif //FIX_SOCKETMONITOR_H
virtual void onError(SocketMonitor &)=0
virtual void onWrite(SocketMonitor &, int socket)=0
virtual void onError(SocketMonitor &, int socket)=0
virtual void onTimeout(SocketMonitor &)
virtual void onEvent(SocketMonitor &, int socket)=0
virtual void onConnect(SocketMonitor &, int socket)=0
Monitors events on a collection of sockets.
void unsignal(int socket)
bool drop(int socket)
void block(Strategy &strategy, bool poll=0, double timeout=0.0)
void signal(int socket)
void buildSet(const Sockets &, fd_set &)
std::set< int > Sockets
timeval * getTimeval(bool poll, double timeout)
bool addRead(int socket)
bool addConnect(int socket)
bool sleepIfEmpty(bool poll)
std::queue< int > Queue
void processWriteSet(Strategy &, fd_set &)
void processReadSet(Strategy &, fd_set &)
void processExceptSet(Strategy &, fd_set &)
bool addWrite(int socket)

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