Poco::Net

template < class ServiceHandler, class SR >

class ParallelSocketAcceptor

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, onAccept, reactor, registerAcceptor, socket, unregisterAcceptor

Types

ParallelReactor

typedef Poco::Net::ParallelSocketReactor < SR > ParallelReactor;

Constructors

ParallelSocketAcceptor inline

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 inline

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.

Destructor

~ParallelSocketAcceptor inline

~ParallelSocketAcceptor();

Destroys the ParallelSocketAcceptor.

Member Functions

onAccept inline

void onAccept(
    ReadableNotification * pNotification
);

Accepts connection and creates event handler.

registerAcceptor inline

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.

unregisterAcceptor inline

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.

createServiceHandler protected inline

ServiceHandler * createServiceHandler(
    StreamSocket & socket
);

Create and initialize a new ServiceHandler instance.

Subclasses can override this method.

init protected inline

void init();

Populates the reactors vector.

reactor protected inline

SocketReactor * reactor();

Returns a pointer to the SocketReactor where this SocketAcceptor is registered.

The pointer may be null.

socket protected inline

Socket & socket();

Returns a reference to the SocketAcceptor's socket.