Library: Net
Package: Reactor
Header: Poco/Net/ParallelSocketAcceptor.h
Description
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 Summary
Member Functions: createServiceHandler, init, next, onAccept, operator =, reactor, reactors, registerAcceptor, setReactor, socket, unregisterAcceptor
Types Aliases
Observer
using Observer = Poco::Observer < ParallelSocketAcceptor, ReadableNotification >;
ParallelReactor
using ParallelReactor = Poco::Net::ParallelSocketReactor < SR >;
ReactorVec
using ReactorVec = std::vector < typename ParallelReactor::Ptr >;
Constructors
ParallelSocketAcceptor
ParallelSocketAcceptor() = delete;
ParallelSocketAcceptor
ParallelSocketAcceptor(
const ParallelSocketAcceptor & param443
) = delete;
ParallelSocketAcceptor
explicit ParallelSocketAcceptor(
ServerSocket & socket,
unsigned threads = Poco::Environment::processorCount (),
const std::string & threadName = ""
);
Creates a ParallelSocketAcceptor using the given ServerSocket, sets number of threads and populates the reactors vector.
ParallelSocketAcceptor
ParallelSocketAcceptor(
ServerSocket & socket,
SocketReactor & reactor,
unsigned threads = Poco::Environment::processorCount (),
const std::string & threadName = ""
);
Creates a ParallelSocketAcceptor using the given ServerSocket, sets the number of threads, populates the reactors vector and registers itself with the given SocketReactor.
Destructor
~ParallelSocketAcceptor
virtual ~ParallelSocketAcceptor();
Destroys the ParallelSocketAcceptor.
Member Functions
onAccept
void onAccept(
ReadableNotification * pNotification
);
Accepts connection and creates event handler.
operator =
ParallelSocketAcceptor & operator = (
const ParallelSocketAcceptor & param444
) = delete;
registerAcceptor
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.
setReactor
void setReactor(
SocketReactor & reactor
);
Sets the reactor for this acceptor.
unregisterAcceptor
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.
createServiceHandler
virtual ServiceHandler * createServiceHandler(
StreamSocket & socket
);
Create and initialize a new ServiceHandler instance. If socket is already registered with a reactor, the new ServiceHandler instance is given that reactor; otherwise, the next reactor is used. Reactors are rotated in round-robin fashion.
Subclasses can override this method.
init
void init();
Populates the reactors vector.
next
std::size_t next();
Returns the next reactor index.
reactor
SocketReactor * reactor(
const Socket & socket
);
Returns reactor where this socket is already registered for polling, if found; otherwise returns null pointer.
reactor
SocketReactor * reactor();
Returns a pointer to the SocketReactor where this SocketAcceptor is registered.
The pointer may be null.
reactor
SocketReactor * reactor(
std::size_t idx
);
Returns reference to the reactor at position idx.
reactors
ReactorVec & reactors();
Returns reference to vector of reactors.
socket
Socket & socket();
Returns a reference to the SocketAcceptor's socket.