LogCabin
|
An OpaqueServer listens for incoming RPCs over TCP connections. More...
#include <OpaqueServer.h>
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 &) | |
OpaqueServer & | operator= (const OpaqueServer &) |
Private Attributes | |
Handler & | rpcHandler |
Deals with OpaqueServerRPC objects that this class creates when it receives a request. | |
Event::Loop & | eventLoop |
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. |
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.
LogCabin::RPC::OpaqueServer::OpaqueServer | ( | Handler & | handler, |
Event::Loop & | eventLoop, | ||
uint32_t | maxMessageLength | ||
) |
Constructor.
This object won't actually do anything until bind() is called.
handler | Handles inbound RPCs. |
eventLoop | Event::Loop that will be used to find out when the underlying socket may be read from or written to without blocking. |
maxMessageLength | The 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.
LogCabin::RPC::OpaqueServer::OpaqueServer | ( | const OpaqueServer & | ) | [private] |
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.
listenAddress | The TCP address on listen for new client connections. |
Definition at line 202 of file OpaqueServer.cc.
OpaqueServer& LogCabin::RPC::OpaqueServer::operator= | ( | const OpaqueServer & | ) | [private] |
friend class OpaqueServerRPC [friend] |
OpaqueServerRPC keeps a std::weak_ptr back to its originating ServerMessageSocket.
Definition at line 267 of file OpaqueServer.h.
Handler& LogCabin::RPC::OpaqueServer::rpcHandler [private] |
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.
const uint32_t LogCabin::RPC::OpaqueServer::maxMessageLength [private] |
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.
std::deque<BoundListenerWithMonitor> LogCabin::RPC::OpaqueServer::boundListeners [private] |
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.