Classes | Public Member Functions | Private Types | Private Attributes | List of all members
FIX::SocketServer Class Reference

Listens for and accepts incoming socket connections on a port. More...

#include <SocketServer.h>

Collaboration diagram for FIX::SocketServer:
Collaboration graph
[legend]

Classes

class  Strategy
 

Public Member Functions

 SocketServer (int timeout=0)
 
int add (int port, bool reuse=false, bool noDelay=false, int sendBufSize=0, int rcvBufSize=0) throw ( SocketException& )
 
int accept (int socket)
 
void close ()
 
bool block (Strategy &strategy, bool poll=0, double timeout=0.0)
 
size_t numConnections ()
 
SocketMonitorgetMonitor ()
 
int socketToPort (int socket)
 
int portToSocket (int port)
 

Private Types

typedef std::map< int, SocketInfoSocketToInfo
 
typedef std::map< int, SocketInfoPortToInfo
 

Private Attributes

SocketToInfo m_socketToInfo
 
PortToInfo m_portToInfo
 
SocketMonitor m_monitor
 

Detailed Description

Listens for and accepts incoming socket connections on a port.

Definition at line 56 of file SocketServer.h.

Member Typedef Documentation

◆ PortToInfo

typedef std::map<int, SocketInfo> FIX::SocketServer::PortToInfo
private

Definition at line 79 of file SocketServer.h.

◆ SocketToInfo

typedef std::map<int, SocketInfo> FIX::SocketServer::SocketToInfo
private

Definition at line 77 of file SocketServer.h.

Constructor & Destructor Documentation

◆ SocketServer()

FIX::SocketServer::SocketServer ( int  timeout = 0)

Definition at line 94 of file SocketServer.cpp.

95: m_monitor( timeout ) {}
SocketMonitor m_monitor

Member Function Documentation

◆ accept()

int FIX::SocketServer::accept ( int  socket)

Definition at line 121 of file SocketServer.cpp.

122{
123 SocketInfo info = m_socketToInfo[socket];
124
125 int result = socket_accept( socket );
126 if( info.m_noDelay )
127 socket_setsockopt( result, TCP_NODELAY );
128 if( info.m_sendBufSize )
129 socket_setsockopt( result, SO_SNDBUF, info.m_sendBufSize );
130 if( info.m_rcvBufSize )
131 socket_setsockopt( result, SO_RCVBUF, info.m_rcvBufSize );
132 if ( result >= 0 )
133 m_monitor.addConnect( result );
134 return result;
135}
bool addConnect(int socket)
SocketToInfo m_socketToInfo
int socket_accept(int s)
Definition Utility.cpp:164
int socket_setsockopt(int s, int opt)
Definition Utility.cpp:208

References FIX::SocketMonitor::addConnect(), m_monitor, FIX::SocketInfo::m_noDelay, FIX::SocketInfo::m_rcvBufSize, FIX::SocketInfo::m_sendBufSize, m_socketToInfo, FIX::socket_accept(), and FIX::socket_setsockopt().

Referenced by FIX::ServerWrapper::onEvent().

◆ add()

int FIX::SocketServer::add ( int  port,
bool  reuse = false,
bool  noDelay = false,
int  sendBufSize = 0,
int  rcvBufSize = 0 
)
throw (SocketException &
)

Definition at line 97 of file SocketServer.cpp.

100{
101 if( m_portToInfo.find(port) != m_portToInfo.end() )
102 return m_portToInfo[port].m_socket;
103
104 int socket = socket_createAcceptor( port, reuse );
105 if( socket < 0 )
106 throw SocketException();
107 if( noDelay )
108 socket_setsockopt( socket, TCP_NODELAY );
109 if( sendBufSize )
110 socket_setsockopt( socket, SO_SNDBUF, sendBufSize );
111 if( rcvBufSize )
112 socket_setsockopt( socket, SO_RCVBUF, rcvBufSize );
113 m_monitor.addRead( socket );
114
115 SocketInfo info( socket, port, noDelay, sendBufSize, rcvBufSize );
116 m_socketToInfo[socket] = info;
117 m_portToInfo[port] = info;
118 return socket;
119}
bool addRead(int socket)
PortToInfo m_portToInfo
int socket_createAcceptor(int port, bool reuse)
Definition Utility.cpp:120

References FIX::socket_createAcceptor(), and FIX::socket_setsockopt().

◆ block()

bool FIX::SocketServer::block ( Strategy strategy,
bool  poll = 0,
double  timeout = 0.0 
)

Definition at line 148 of file SocketServer.cpp.

149{
150 std::set<int> sockets;
151 SocketToInfo::iterator i = m_socketToInfo.begin();
152 for( ; i != m_socketToInfo.end(); ++i )
153 {
154 if( !socket_isValid(i->first) )
155 return false;
156 sockets.insert( i->first );
157 }
158
159 ServerWrapper wrapper( sockets, *this, strategy );
160 m_monitor.block( wrapper, poll, timeout );
161 return true;
162}
void block(Strategy &strategy, bool poll=0, double timeout=0.0)
bool socket_isValid(int socket)
Definition Utility.cpp:277

References FIX::SocketMonitor::block(), m_monitor, m_socketToInfo, and FIX::socket_isValid().

Referenced by FIX::HttpServer::onPoll(), FIX::SocketAcceptor::onPoll(), FIX::HttpServer::onStart(), and FIX::SocketAcceptor::onStart().

◆ close()

void FIX::SocketServer::close ( )

Definition at line 137 of file SocketServer.cpp.

138{
139 SocketToInfo::iterator i = m_socketToInfo.begin();
140 for( ; i != m_socketToInfo.end(); ++i )
141 {
142 int s = i->first;
143 socket_close( s );
145 }
146}
void socket_invalidate(int &socket)
Definition Utility.cpp:295
void socket_close(int s)
Definition Utility.cpp:180

References m_socketToInfo, FIX::socket_close(), and FIX::socket_invalidate().

Referenced by FIX::HttpServer::onStart(), and FIX::SocketAcceptor::onStart().

◆ getMonitor()

SocketMonitor & FIX::SocketServer::getMonitor ( )
inline

Definition at line 70 of file SocketServer.h.

70{ return m_monitor; }

References m_monitor.

Referenced by FIX::HttpServer::onConnect(), FIX::SocketAcceptor::onConnect(), and FIX::SocketConnection::read().

◆ numConnections()

size_t FIX::SocketServer::numConnections ( )
inline

Definition at line 69 of file SocketServer.h.

69{ return m_monitor.numSockets() - 1; }

References m_monitor, and FIX::SocketMonitor::numSockets().

◆ portToSocket()

int FIX::SocketServer::portToSocket ( int  port)

Definition at line 171 of file SocketServer.cpp.

172{
173 SocketToInfo::iterator find = m_portToInfo.find( port );
174 if( find == m_portToInfo.end() ) return 0;
175 return find->second.m_socket;
176}

References m_portToInfo.

◆ socketToPort()

int FIX::SocketServer::socketToPort ( int  socket)

Definition at line 164 of file SocketServer.cpp.

165{
166 SocketToInfo::iterator find = m_socketToInfo.find( socket );
167 if( find == m_socketToInfo.end() ) return 0;
168 return find->second.m_port;
169}

References m_socketToInfo.

Referenced by FIX::SocketAcceptor::onConnect().

Member Data Documentation

◆ m_monitor

SocketMonitor FIX::SocketServer::m_monitor
private

Definition at line 83 of file SocketServer.h.

Referenced by accept(), block(), getMonitor(), and numConnections().

◆ m_portToInfo

PortToInfo FIX::SocketServer::m_portToInfo
private

Definition at line 82 of file SocketServer.h.

Referenced by portToSocket().

◆ m_socketToInfo

SocketToInfo FIX::SocketServer::m_socketToInfo
private

Definition at line 81 of file SocketServer.h.

Referenced by accept(), block(), close(), and socketToPort().


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

Generated on Sun Mar 31 2024 07:07:24 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001