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 71 of file SocketServer.h.

Member Typedef Documentation

◆ PortToInfo

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

Definition at line 94 of file SocketServer.h.

◆ SocketToInfo

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

Definition at line 92 of file SocketServer.h.

Constructor & Destructor Documentation

◆ SocketServer()

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

Definition at line 109 of file SocketServer.cpp.

Member Function Documentation

◆ accept()

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

Definition at line 136 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 );
144  socket_invalidate( s );
145  }
146 }
147 
148 bool SocketServer::block( Strategy& strategy, bool poll, double timeout )
149 {
150  std::set<int> sockets;

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

◆ add()

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

Definition at line 112 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;

◆ block()

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

Definition at line 163 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 }
170 
171 int SocketServer::portToSocket( int port )
172 {
173  SocketToInfo::iterator find = m_portToInfo.find( port );
174  if( find == m_portToInfo.end() ) return 0;
175  return find->second.m_socket;
176 }
177 }

References m_socketToInfo.

◆ close()

void FIX::SocketServer::close ( )

Definition at line 152 of file SocketServer.cpp.

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;

References FIX::socket_isValid().

◆ getMonitor()

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

◆ numConnections()

size_t FIX::SocketServer::numConnections ( )
inline

Definition at line 84 of file SocketServer.h.

85 :
86  class Strategy

◆ portToSocket()

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

Definition at line 186 of file SocketServer.cpp.

◆ socketToPort()

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

Definition at line 179 of file SocketServer.cpp.

Member Data Documentation

◆ m_monitor

SocketMonitor FIX::SocketServer::m_monitor
private

Definition at line 98 of file SocketServer.h.

◆ m_portToInfo

PortToInfo FIX::SocketServer::m_portToInfo
private

Definition at line 97 of file SocketServer.h.

◆ m_socketToInfo

SocketToInfo FIX::SocketServer::m_socketToInfo
private

Definition at line 96 of file SocketServer.h.

Referenced by accept(), and block().


The documentation for this class was generated from the following files:
FIX::SocketServer::m_monitor
SocketMonitor m_monitor
Definition: SocketServer.h:98
FIX::SocketMonitor::block
void block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketMonitor.cpp:196
FIX::socket_setsockopt
int socket_setsockopt(int s, int opt)
Definition: Utility.cpp:223
FIX::SocketServer::block
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketServer.cpp:163
FIX::SocketMonitor::addConnect
bool addConnect(int socket)
Definition: SocketMonitor.cpp:80
FIX::socket_isValid
bool socket_isValid(int socket)
Definition: Utility.cpp:292
FIX::SocketServer::portToSocket
int portToSocket(int port)
Definition: SocketServer.cpp:186
FIX::SocketServer::m_portToInfo
PortToInfo m_portToInfo
Definition: SocketServer.h:97
FIX::socket_accept
int socket_accept(int s)
Definition: Utility.cpp:179
FIX::SocketServer::m_socketToInfo
SocketToInfo m_socketToInfo
Definition: SocketServer.h:96
FIX::socket_invalidate
void socket_invalidate(int &socket)
Definition: Utility.cpp:310
FIX::socket_close
void socket_close(int s)
Definition: Utility.cpp:195

Generated on Thu Apr 23 2020 04:32:03 for QuickFIX by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2001