LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends
LogCabin::RPC::OpaqueServer Class Reference

An OpaqueServer listens for incoming RPCs over TCP connections. More...

#include <OpaqueServer.h>

List of all members.

Classes

class  BoundListener
 A socket that listens on a particular address. More...
struct  BoundListenerWithMonitor
 Couples a BoundListener with an Event::File::Monitor and destroys them in the right order (monitor first). More...
class  Handler
 An interface for handling events generated by an OpaqueServer. More...
class  MessageSocketHandler
 Receives events from a MessageSocket. More...
struct  SocketWithHandler
 Couples a MessageSocketHandler with a MessageSocket (monitor) and destroys them in the right order (monitor first). More...

Public Member Functions

 OpaqueServer (Handler &handler, Event::Loop &eventLoop, uint32_t maxMessageLength)
 Constructor.
 ~OpaqueServer ()
 Destructor.
std::string bind (const Address &listenAddress)
 Listen on an address for new client connections.

Private Member Functions

 OpaqueServer (const OpaqueServer &)
OpaqueServeroperator= (const OpaqueServer &)

Private Attributes

HandlerrpcHandler
 Deals with OpaqueServerRPC objects that this class creates when it receives a request.
Event::LoopeventLoop
 The event loop that is used for non-blocking I/O.
const uint32_t maxMessageLength
 The maximum number of bytes to allow per request/response.
std::unordered_set
< std::shared_ptr
< SocketWithHandler > > 
sockets
 Every open socket is referenced here so that it can be cleaned up when this OpaqueServer is destroyed.
Core::Mutex boundListenersMutex
 Lock to prevent concurrent modification of boundListeners.
std::deque
< BoundListenerWithMonitor
boundListeners
 A list of listening sockets that each listen on a particular address.

Friends

class OpaqueServerRPC
 OpaqueServerRPC keeps a std::weak_ptr back to its originating ServerMessageSocket.

Detailed Description

An OpaqueServer listens for incoming RPCs over TCP connections.

OpaqueServers can be created from any thread, but they will always run on the thread running the Event::Loop.

Definition at line 51 of file OpaqueServer.h.


Constructor & Destructor Documentation

LogCabin::RPC::OpaqueServer::OpaqueServer ( Handler handler,
Event::Loop eventLoop,
uint32_t  maxMessageLength 
)

Constructor.

This object won't actually do anything until bind() is called.

Parameters:
handlerHandles inbound RPCs.
eventLoopEvent::Loop that will be used to find out when the underlying socket may be read from or written to without blocking.
maxMessageLengthThe maximum number of bytes to allow per request/response. This exists to limit the amount of buffer space a single RPC can use. Attempting to send longer responses will PANIC; attempting to receive longer requests will disconnect the underlying socket.

Definition at line 167 of file OpaqueServer.cc.

Destructor.

OpaqueServerRPC objects originating from this OpaqueServer may be kept around after this destructor returns; however, they won't actually send replies anymore.

Definition at line 179 of file OpaqueServer.cc.


Member Function Documentation

std::string LogCabin::RPC::OpaqueServer::bind ( const Address listenAddress)

Listen on an address for new client connections.

You can call this multiple times to listen on multiple addresses. (But if you call this twice with the same address, the second time will always throw an error.) This method is thread-safe.

Parameters:
listenAddressThe TCP address on listen for new client connections.
Returns:
An error message if this was not able to listen on the given address; the empty string otherwise.

Definition at line 202 of file OpaqueServer.cc.

OpaqueServer& LogCabin::RPC::OpaqueServer::operator= ( const OpaqueServer ) [private]

Friends And Related Function Documentation

friend class OpaqueServerRPC [friend]

OpaqueServerRPC keeps a std::weak_ptr back to its originating ServerMessageSocket.

Definition at line 267 of file OpaqueServer.h.


Member Data Documentation

Deals with OpaqueServerRPC objects that this class creates when it receives a request.

Definition at line 225 of file OpaqueServer.h.

The event loop that is used for non-blocking I/O.

Definition at line 230 of file OpaqueServer.h.

The maximum number of bytes to allow per request/response.

Definition at line 235 of file OpaqueServer.h.

std::unordered_set<std::shared_ptr<SocketWithHandler> > LogCabin::RPC::OpaqueServer::sockets [private]

Every open socket is referenced here so that it can be cleaned up when this OpaqueServer is destroyed.

These are reference-counted: the lifetime of each socket may slightly exceed the lifetime of the OpaqueServer if it is being actively used to send out a OpaqueServerRPC response when the OpaqueServer is destroyed.

This may only be accessed from the Event::Loop or while holding an Event::Loop::Lock (it's almost entirely accessed from event handlers, so it's convenient to rely on the Event::Loop::Lock for mutual exclusion during OpauqeServer's destructor as well).

Definition at line 249 of file OpaqueServer.h.

Lock to prevent concurrent modification of boundListeners.

Definition at line 254 of file OpaqueServer.h.

A list of listening sockets that each listen on a particular address.

std::deque is used so that the handler objects have a stable memory location (otherwise their monitors would blow up).

Definition at line 261 of file OpaqueServer.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines