37 #ifndef FIX8_MULTISESSSION_HPP_
38 #define FIX8_MULTISESSSION_HPP_
47 std::map<Poco::Net::ServerSocket, ServerSessionBase *>
_servermap;
55 { std::for_each (_servermap.begin(), _servermap.end(), [](decltype(_servermap)::value_type& pp){
delete pp.second; }); }
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;
86 size_t select_l(std::vector<ServerSessionBase *>& result,
const Poco::Timespan& timeout=Poco::Timespan(250000))
const
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); });
100 unsigned size()
const {
return static_cast<unsigned>(_servermap.size()); }
105 template <
typename T>
119 std::for_each (_sessionmap.begin(), _sessionmap.end(), [](
typename decltype(_sessionmap)::value_type& pp){
delete pp.second; });
131 return _sessionmap.insert({name, what}).second;
139 for (
auto& pp : _sessionmap)
142 if (!func(pp.second))
154 auto itr(_sessionmap.find(name));
155 if (itr == _sessionmap.end())
158 _sessionmap.erase(itr);
168 const auto itr(_sessionmap.find(name));
169 return itr == _sessionmap.cend() ?
nullptr : itr->second;
179 unsigned size()
const {
return static_cast<unsigned>(_sessionmap.size()); }
190 #endif // FIX8_MULTISESSSION_HPP_
generic pthread_mutex wrapper
virtual ~SessionManager()
Dtor.
bool add(ServerSessionBase *what)
ServerManager()=default
Ctor.
Poco::Net::ServerSocket * _server_sock
std::map< Poco::Net::ServerSocket, ServerSessionBase * > _servermap
ServerSessionBase * select(const Poco::Timespan &timeout=Poco::Timespan(250000)) const
T * operator[](const f8String &name) const
std::map< f8String, T * > _sessionmap
T * for_each_if(std::function< bool(T *)> func)
SessionManager()=default
Ctor.
T * find(const f8String &name)
bool add(const f8String &name, T *what)
virtual ~ServerManager()
Dtor.
size_t select_l(std::vector< ServerSessionBase * > &result, const Poco::Timespan &timeout=Poco::Timespan(250000)) const