QuickFIX: FIX::SocketServer Class Reference

Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

# FIX::SocketServer Class Reference

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

`#include <SocketServer.h>`

Collaboration diagram for FIX::SocketServer:
[legend]

List of all members.

## 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)
int | numConnections ()
SocketMonitor & | getMonitor ()
int | socketToPort (int socket)
int | portToSocket (int port)
## Private Types
typedef std::map< int, SocketInfo > | SocketToInfo
typedef std::map< int, SocketInfo > | PortToInfo
## 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

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

Definition at line 79 of file SocketServer.h.

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

Definition at line 77 of file SocketServer.h.

## Constructor & Destructor Documentation

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

Definition at line 107 of file SocketServer.cpp.

    00108 : m_monitor( timeout ) {}

## Member Function Documentation

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

Definition at line 134 of file SocketServer.cpp.

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

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

    00135 { QF_STACK_PUSH(SocketServer::accept)
    00136
    00137   SocketInfo info = m_socketToInfo[socket];
    00138
    00139   int result = socket_accept( socket );
    00140   if( info.m_noDelay )
    00141     socket_setsockopt( result, TCP_NODELAY );
    00142   if( info.m_sendBufSize )
    00143     socket_setsockopt( result, SO_SNDBUF, info.m_sendBufSize );
    00144   if( info.m_rcvBufSize )
    00145     socket_setsockopt( result, SO_RCVBUF, info.m_rcvBufSize );
    00146   if ( result >= 0 )
    00147     m_monitor.addConnect( result );
    00148   return result;
    00149
    00150   QF_STACK_POP
    00151 }

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

Definition at line 110 of file SocketServer.cpp.

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

    00113 {
    00114   if( m_portToInfo.find(port) != m_portToInfo.end() )
    00115     return m_portToInfo[port].m_socket;
    00116
    00117   int socket = socket_createAcceptor( port, reuse );
    00118   if( socket < 0 )
    00119     throw SocketException();
    00120   if( noDelay )
    00121     socket_setsockopt( socket, TCP_NODELAY );
    00122   if( sendBufSize )
    00123     socket_setsockopt( socket, SO_SNDBUF, sendBufSize );
    00124   if( rcvBufSize )
    00125     socket_setsockopt( socket, SO_RCVBUF, rcvBufSize );
    00126   m_monitor.addRead( socket );
    00127
    00128   SocketInfo info( socket, port, noDelay, sendBufSize, rcvBufSize );
    00129   m_socketToInfo[socket] = info;
    00130   m_portToInfo[port] = info;
    00131   return socket;
    00132 }

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

Definition at line 167 of file SocketServer.cpp.

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

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

    00168 { QF_STACK_PUSH(SocketServer::block)
    00169
    00170   std::set<int> sockets;
    00171   SocketToInfo::iterator i = m_socketToInfo.begin();
    00172   for( ; i != m_socketToInfo.end(); ++i )
    00173   {
    00174     if( !socket_isValid(i->first) )
    00175       return false;
    00176     sockets.insert( i->first );
    00177   }
    00178
    00179   ServerWrapper wrapper( sockets, *this, strategy );
    00180   m_monitor.block( wrapper, poll, timeout );
    00181   return true;
    00182
    00183   QF_STACK_POP
    00184 }

void FIX::SocketServer::close | ( |  | ) |

Definition at line 153 of file SocketServer.cpp.

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

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

    00154 { QF_STACK_PUSH(SocketServer::close)
    00155
    00156   SocketToInfo::iterator i = m_socketToInfo.begin();
    00157   for( ; i != m_socketToInfo.end(); ++i )
    00158   {
    00159     int s = i->first;
    00160     socket_close( s );
    00161     socket_invalidate( s );
    00162   }
    00163
    00164   QF_STACK_POP
    00165 }

SocketMonitor& FIX::SocketServer::getMonitor | ( |  | ) | `[inline]`

Definition at line 70 of file SocketServer.h.

References m_monitor.

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

    00070 { return m_monitor; }

int FIX::SocketServer::numConnections | ( |  | ) | `[inline]`

Definition at line 69 of file SocketServer.h.

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

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

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

Definition at line 193 of file SocketServer.cpp.

References m_portToInfo.

    00194 {
    00195   SocketToInfo::iterator find = m_portToInfo.find( port );
    00196   if( find == m_portToInfo.end() ) return 0;
    00197   return find->second.m_socket;
    00198 }

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

Definition at line 186 of file SocketServer.cpp.

References m_socketToInfo.

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

    00187 {
    00188   SocketToInfo::iterator find = m_socketToInfo.find( socket );
    00189   if( find == m_socketToInfo.end() ) return 0;
    00190   return find->second.m_port;
    00191 }

## Member Data Documentation

SocketMonitor FIX::SocketServer::m_monitor`[private]`

Definition at line 83 of file SocketServer.h.

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

PortToInfo FIX::SocketServer::m_portToInfo`[private]`

Definition at line 82 of file SocketServer.h.

Referenced by portToSocket().

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:

- /home/omiller/Development/autobuild/quickfix/src/C++/SocketServer.h
- /home/omiller/Development/autobuild/quickfix/src/C++/SocketServer.cpp