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 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.

: m_monitor( timeout ) {}
FIX::SocketServer::m_monitor
SocketMonitor m_monitor
Definition: SocketServer.h:83

## Member Function Documentation

## accept()

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

Definition at line 121 of file SocketServer.cpp.

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().

{
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;
}
FIX::socket_accept
int socket_accept(int s)
Definition: Utility.cpp:147
FIX::socket_setsockopt
int socket_setsockopt(int s, int opt)
Definition: Utility.cpp:186
FIX::SocketServer::m_monitor
SocketMonitor m_monitor
Definition: SocketServer.h:83
FIX::SocketMonitor::addConnect
bool addConnect(int socket)
Definition: SocketMonitor.cpp:65
FIX::SocketServer::m_socketToInfo
SocketToInfo m_socketToInfo
Definition: SocketServer.h:81

## 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.

References FIX::SocketMonitor::addRead(), m_monitor, m_portToInfo, m_socketToInfo, FIX::socket_createAcceptor(), and FIX::socket_setsockopt().

Referenced by FIX::HttpServer::onInitialize().

{
if( m_portToInfo.find(port) != m_portToInfo.end() )
return m_portToInfo[port].m_socket;
int socket = socket_createAcceptor( port, reuse );
if( socket < 0 )
throw SocketException();
if( noDelay )
socket_setsockopt( socket, TCP_NODELAY );
if( sendBufSize )
socket_setsockopt( socket, SO_SNDBUF, sendBufSize );
if( rcvBufSize )
socket_setsockopt( socket, SO_RCVBUF, rcvBufSize );
m_monitor.addRead( socket );
SocketInfo info( socket, port, noDelay, sendBufSize, rcvBufSize );
m_socketToInfo[socket] = info;
m_portToInfo[port] = info;
return socket;
}
FIX::SocketServer::m_portToInfo
PortToInfo m_portToInfo
Definition: SocketServer.h:82
FIX::SocketMonitor::addRead
bool addRead(int socket)
Definition: SocketMonitor.cpp:75
FIX::socket_setsockopt
int socket_setsockopt(int s, int opt)
Definition: Utility.cpp:186
FIX::SocketServer::m_monitor
SocketMonitor m_monitor
Definition: SocketServer.h:83
FIX::socket_createAcceptor
int socket_createAcceptor(int port, bool reuse)
Definition: Utility.cpp:103
FIX::SocketServer::m_socketToInfo
SocketToInfo m_socketToInfo
Definition: SocketServer.h:81

## block()

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

Definition at line 148 of file SocketServer.cpp.

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().

{
std::set<int> sockets;
SocketToInfo::iterator i = m_socketToInfo.begin();
for( ; i != m_socketToInfo.end(); ++i )
{
if( !socket_isValid(i->first) )
return false;
sockets.insert( i->first );
}
ServerWrapper wrapper( sockets, *this, strategy );
m_monitor.block( wrapper, poll, timeout );
return true;
}
FIX::socket_isValid
bool socket_isValid(int socket)
Definition: Utility.cpp:255
FIX::SocketServer::m_monitor
SocketMonitor m_monitor
Definition: SocketServer.h:83
FIX::SocketMonitor::block
void block(Strategy &strategy, bool poll=0, double timeout=0.0)
Definition: SocketMonitor.cpp:181
FIX::SocketServer::m_socketToInfo
SocketToInfo m_socketToInfo
Definition: SocketServer.h:81

## close()

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

Definition at line 137 of file SocketServer.cpp.

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

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

{
SocketToInfo::iterator i = m_socketToInfo.begin();
for( ; i != m_socketToInfo.end(); ++i )
{
int s = i->first;
socket_close( s );
socket_invalidate( s );
}
}
FIX::socket_invalidate
void socket_invalidate(int &socket)
Definition: Utility.cpp:273
FIX::socket_close
void socket_close(int s)
Definition: Utility.cpp:158
FIX::SocketServer::m_socketToInfo
SocketToInfo m_socketToInfo
Definition: SocketServer.h:81

## getMonitor()

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

inline

Definition at line 70 of file SocketServer.h.

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

{ return m_monitor; }
FIX::SocketServer::m_monitor
SocketMonitor m_monitor
Definition: SocketServer.h:83

## numConnections()

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

inline

Definition at line 69 of file SocketServer.h.

{ return m_monitor.numSockets() - 1; }
FIX::SocketServer::m_monitor
SocketMonitor m_monitor
Definition: SocketServer.h:83
FIX::SocketMonitor::numSockets
size_t numSockets()
Definition: SocketMonitor.h:63

## portToSocket()

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

Definition at line 171 of file SocketServer.cpp.

References m_portToInfo.

{
SocketToInfo::iterator find = m_portToInfo.find( port );
if( find == m_portToInfo.end() ) return 0;
return find->second.m_socket;
}
FIX::SocketServer::m_portToInfo
PortToInfo m_portToInfo
Definition: SocketServer.h:82

## socketToPort()

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

Definition at line 164 of file SocketServer.cpp.

References m_socketToInfo.

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

{
SocketToInfo::iterator find = m_socketToInfo.find( socket );
if( find == m_socketToInfo.end() ) return 0;
return find->second.m_port;
}
FIX::SocketServer::m_socketToInfo
SocketToInfo m_socketToInfo
Definition: SocketServer.h:81

## Member Data Documentation

## m_monitor

SocketMonitor FIX::SocketServer::m_monitor

private

Definition at line 83 of file SocketServer.h.

Referenced by accept(), add(), and block().

## m_portToInfo

PortToInfo FIX::SocketServer::m_portToInfo

private

Definition at line 82 of file SocketServer.h.

Referenced by add(), and portToSocket().

## m_socketToInfo

SocketToInfo FIX::SocketServer::m_socketToInfo

private

Definition at line 81 of file SocketServer.h.

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

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

- SocketServer.h
- SocketServer.cpp