fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::ServerManager Class Reference

Multi Server Manager. More...

#include <multisession.hpp>

Public Member Functions

 ServerManager ()=default
 Ctor. More...
 
virtual ~ServerManager ()
 Dtor. More...
 
bool add (ServerSessionBase *what)
 
ServerSessionBaseselect (const Poco::Timespan &timeout=Poco::Timespan(250000)) const
 
size_t select_l (std::vector< ServerSessionBase * > &result, const Poco::Timespan &timeout=Poco::Timespan(250000)) const
 
unsigned size () const
 

Private Attributes

std::map< Poco::Net::ServerSocket, ServerSessionBase * > _servermap
 

Detailed Description

Multi Server Manager.

Definition at line 45 of file multisession.hpp.

Constructor & Destructor Documentation

FIX8::ServerManager::ServerManager ( )
default

Ctor.

virtual FIX8::ServerManager::~ServerManager ( )
inlinevirtual

Dtor.

Definition at line 54 of file multisession.hpp.

55  { std::for_each (_servermap.begin(), _servermap.end(), [](decltype(_servermap)::value_type& pp){ delete pp.second; }); }
std::map< Poco::Net::ServerSocket, ServerSessionBase * > _servermap

Member Function Documentation

bool FIX8::ServerManager::add ( ServerSessionBase what)
inline

Add a ServerSession to the manager; takes ownership of the object

Parameters
whatServerSession to add
Returns
true if successful

Definition at line 60 of file multisession.hpp.

References FIX8::ServerSessionBase::_server_sock.

61  {
62  if (!what || !what->_server_sock)
63  throw f8Exception("bad or missing server socket");
64  _servermap.insert({*what->_server_sock, what});
65  return true;
66  }
std::map< Poco::Net::ServerSocket, ServerSessionBase * > _servermap
ServerSessionBase* FIX8::ServerManager::select ( const Poco::Timespan &  timeout = Poco::Timespan(250000)) const
inline

Check to see if there are any waiting inbound connections on any of the managed servers. Will only return the first ServerSession; select should be called continually to process all waiting sockets.

Parameters
timeouttimespan (us, default 250 ms) to wait before returning (will return immediately if connection available)
Returns
pointer to ServerSession that is ready to accept a connection or nullptr if timeout with none

Definition at line 72 of file multisession.hpp.

73  {
74  Poco::Net::Socket::SocketList readList, writeList, exceptList;
75  for (auto& pp : _servermap)
76  readList.push_back(pp.first);
77  return Poco::Net::Socket::select(readList, writeList, exceptList, timeout) && !readList.empty()
78  ? _servermap.find(readList[0])->second : nullptr;
79  }
std::map< Poco::Net::ServerSocket, ServerSessionBase * > _servermap
size_t FIX8::ServerManager::select_l ( std::vector< ServerSessionBase * > &  result,
const Poco::Timespan &  timeout = Poco::Timespan(250000) 
) const
inline

Check to see if there are any waiting inbound connections on any of the managed servers. Will add all ServerSession pointers to the supplied vector for all waiting sockets found.

Parameters
resultvector to place results in; will empty before polling
timeouttimespan (us, default 250 ms) to wait before returning (will return immediately if connection available)
Returns
number of active ServerSockets returned in vector

Definition at line 86 of file multisession.hpp.

87  {
88  result.clear();
89  Poco::Net::Socket::SocketList readList, writeList, exceptList;
90  for (auto& pp : _servermap)
91  readList.push_back(pp.first);
92  if (Poco::Net::Socket::select(readList, writeList, exceptList, timeout) && !readList.empty())
93  std::for_each(readList.begin(), readList.end(), [&](decltype(readList)::value_type& pp)
94  { result.push_back(_servermap.find(pp)->second); });
95  return result.size();
96  }
std::map< Poco::Net::ServerSocket, ServerSessionBase * > _servermap
unsigned FIX8::ServerManager::size ( ) const
inline

Get the number of server sessions being manager by this object

Returns
count of server sessions

Definition at line 100 of file multisession.hpp.

100 { return static_cast<unsigned>(_servermap.size()); }
std::map< Poco::Net::ServerSocket, ServerSessionBase * > _servermap

Member Data Documentation

std::map<Poco::Net::ServerSocket, ServerSessionBase *> FIX8::ServerManager::_servermap
private

Definition at line 47 of file multisession.hpp.


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