FIX::SocketServer Class Reference

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

`#include <SocketServer.h>`

Collaboration diagram for FIX::SocketServer:
[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 ()
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 73 of file SocketServer.h.

## Member Typedef Documentation

## PortToInfo

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

private

Definition at line 96 of file SocketServer.h.

## SocketToInfo

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

private

Definition at line 94 of file SocketServer.h.

## Constructor & Destructor Documentation

## SocketServer()

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

Definition at line 111 of file SocketServer.cpp.

## Member Function Documentation

## accept()

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

Definition at line 138 of file SocketServer.cpp.

{
SocketToInfo::iterator i = m_socketToInfo.begin();
for( ; i != m_socketToInfo.end(); ++i )
{
int s = i->first;
socket_close( s );
socket_invalidate( s );
}
}
bool SocketServer::block( Strategy& strategy, bool poll, double timeout )
{
std::set<int> sockets;
SocketToInfo::iterator i = m_socketToInfo.begin();
for( ; i != m_socketToInfo.end(); ++i )

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 114 of file SocketServer.cpp.

{
SocketInfo info = m_socketToInfo[socket];
int result = socket_accept( socket );
if( info.m_noDelay )
socket_setsockopt( result, TCP_NODELAY );
if( info.m_sendBufSize )
socket_setsockopt( result, SO_SNDBUF, info.m_sendBufSize );
if( info.m_rcvBufSize )
socket_setsockopt( result, SO_RCVBUF, info.m_rcvBufSize );
if ( result >= 0 )
m_monitor.addConnect( result );
return result;
}

## block()

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

Definition at line 165 of file SocketServer.cpp.

{
SocketToInfo::iterator find = m_socketToInfo.find( socket );
if( find == m_socketToInfo.end() ) return 0;
return find->second.m_port;
}
int SocketServer::portToSocket( int port )
{
SocketToInfo::iterator find = m_portToInfo.find( port );
if( find == m_portToInfo.end() ) return 0;
return find->second.m_socket;
}
}

References m_socketToInfo.

## close()

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

Definition at line 154 of file SocketServer.cpp.

## getMonitor()

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

inline

Definition at line 87 of file SocketServer.h.

{

References FIX::SocketServer::Strategy::onConnect(), FIX::SocketServer::Strategy::onData(), FIX::SocketServer::Strategy::onDisconnect(), FIX::SocketServer::Strategy::onWrite(), and FIX::SocketServer::Strategy::~Strategy().

## numConnections()

size_t FIX::SocketServer::numConnections | ( |  | ) |

inline

Definition at line 86 of file SocketServer.h.

{

## portToSocket()

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

Definition at line 188 of file SocketServer.cpp.

## socketToPort()

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

Definition at line 181 of file SocketServer.cpp.

## Member Data Documentation

## m_monitor

SocketMonitor FIX::SocketServer::m_monitor

private

Definition at line 100 of file SocketServer.h.

## m_portToInfo

PortToInfo FIX::SocketServer::m_portToInfo

private

Definition at line 99 of file SocketServer.h.

## m_socketToInfo

SocketToInfo FIX::SocketServer::m_socketToInfo

private

Definition at line 98 of file SocketServer.h.

Referenced by accept(), and block().

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

- SocketServer.h
- SocketServer.cpp

FIX::SocketServer::m_monitor
SocketMonitor m_monitor
Definition: SocketServer.h:100
FIX::socket_setsockopt
int socket_setsockopt(int s, int opt)
Definition: Utility.cpp:225
FIX::SocketServer::block
bool block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketServer.cpp:165
FIX::SocketMonitor::addConnect
bool addConnect(int socket)
Definition: SocketMonitor.cpp:82
FIX::SocketServer::portToSocket
int portToSocket(int port)
Definition: SocketServer.cpp:188
FIX::SocketServer::m_portToInfo
PortToInfo m_portToInfo
Definition: SocketServer.h:99
FIX::socket_accept
int socket_accept(int s)
Definition: Utility.cpp:181
FIX::SocketServer::m_socketToInfo
SocketToInfo m_socketToInfo
Definition: SocketServer.h:98
FIX::socket_invalidate
void socket_invalidate(int &socket)
Definition: Utility.cpp:312
FIX::socket_close
void socket_close(int s)
Definition: Utility.cpp:197