Library: Net
Package: Reactor
Header: Poco/Net/ParallelSocketAcceptor.h
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.
Member Functions: createServiceHandler, init, onAccept, reactor, registerAcceptor, socket, unregisterAcceptor
typedef Poco::Net::ParallelSocketReactor < SR > ParallelReactor;
explicit 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.
virtual ~ParallelSocketAcceptor();
Destroys the ParallelSocketAcceptor.
void onAccept(
ReadableNotification * pNotification
);
Accepts connection and creates event handler.
virtual void registerAcceptor(
SocketReactor & reactor
);
Registers the ParallelSocketAcceptor with a SocketReactor.
A subclass can override this and, for example, also register an event handler for a timeout event.
The overriding method must call the baseclass implementation first.
virtual void unregisterAcceptor();
Unregisters the ParallelSocketAcceptor.
A subclass can override this and, for example, also unregister its event handler for a timeout event.
The overriding method must call the baseclass implementation first.
virtual ServiceHandler * createServiceHandler(
StreamSocket & socket
);
Create and initialize a new ServiceHandler instance.
Subclasses can override this method.
void init();
Populates the reactors vector.
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.