template class Poco::Net::ParallelSocketAcceptor
Overview
This class implements the Acceptor part of the Acceptor-Connector design pattern. More…
#include <ParallelSocketAcceptor.h> template < class ServiceHandler, class SR > class ParallelSocketAcceptor { public: // typedefs typedef Poco::Net::ParallelSocketReactor<SR> ParallelReactor; // construction ParallelSocketAcceptor( ServerSocket& socket, unsigned threads = Poco::Environment::processorCount() ); ParallelSocketAcceptor( ServerSocket& socket, SocketReactor& reactor, unsigned threads = Poco::Environment::processorCount() ); // methods void setReactor(SocketReactor& reactor); virtual void registerAcceptor(SocketReactor& reactor); virtual void unregisterAcceptor(); void onAccept(ReadableNotification* pNotification); protected: // typedefs typedef std::vector<typename ParallelReactor::Ptr> ReactorVec; // methods virtual ServiceHandler* createServiceHandler(StreamSocket& socket); SocketReactor* reactor(); Socket& socket(); void init(); ReactorVec& reactors(); SocketReactor* reactor(std::size_t idx); std::size_t& next(); };
Detailed Documentation
This class implements the Acceptor part of the Acceptor-Connector design pattern.
Only the difference from single-threaded version is documented here, For full description see Poco::Net::SocketAcceptor documentation.
This is a multi-threaded version of SocketAcceptor, it differs from the single-threaded version in number of reactors (defaulting to number of processors) that can be specified at construction time and is rotated in a round-robin fashion by event handler. See ParallelSocketAcceptor::onAccept and ParallelSocketAcceptor::createServiceHandler documentation and implementation for details.
Construction
ParallelSocketAcceptor( ServerSocket& socket, unsigned threads = Poco::Environment::processorCount() )
Creates a ParallelSocketAcceptor using the given ServerSocket, sets number of threads and populates the reactors vector.
ParallelSocketAcceptor( ServerSocket& socket, SocketReactor& reactor, unsigned threads = Poco::Environment::processorCount() )
Creates a ParallelSocketAcceptor using the given ServerSocket, sets the number of threads, populates the reactors vector and registers itself with the given SocketReactor.
Methods
void setReactor(SocketReactor& reactor)
Sets the reactor for this acceptor.
virtual void registerAcceptor(SocketReactor& reactor)
Registers the ParallelSocketAcceptor with a SocketReactor.
A subclass can override this function to e.g. register an event handler for timeout event.
The overriding method must either call the base class implementation or register the accept handler on its own.
virtual void unregisterAcceptor()
Unregisters the ParallelSocketAcceptor.
A subclass can override this function to e.g. unregister its event handler for a timeout event.
The overriding method must either call the base class implementation or unregister the accept handler on its own.
void onAccept(ReadableNotification* pNotification)
Accepts connection and creates event handler.
virtual ServiceHandler* createServiceHandler(StreamSocket& socket)
Create and initialize a new ServiceHandler instance.
Subclasses can override this method.
SocketReactor* reactor()
Returns a pointer to the SocketReactor where this SocketAcceptor is registered.
The pointer may be null.
Socket& socket()
Returns a reference to the SocketAcceptor ‘s socket.
void init()
Populates the reactors vector.
ReactorVec& reactors()
Returns reference to vector of reactors.
SocketReactor* reactor(std::size_t idx)
Returns reference to the reactor at position idx.
std::size_t& next()
Returns reference to the next reactor index.