AsyncServerSocket is a listening socket that asynchronously informs a callback whenever a new connection has been accepted.
Synopsis
Declared in <folly/io/async/AsyncServerSocket.h>
class AsyncServerSocket
: public DelayedDestruction
, public AsyncSocketBase
Description
Unlike most async interfaces that always invoke their callback in the same EventBase thread, AsyncServerSocket is unusual in that it can distribute the callbacks across multiple EventBase threads.
This supports a common use case for network servers to distribute incoming connections across a number of EventBase threads. (Servers typically run with one EventBase thread per CPU.)
Despite being able to invoke callbacks in multiple EventBase threads, AsyncServerSocket still has one "primary" EventBase. Operations that modify the AsyncServerSocket state may only be performed from the primary EventBase thread.
Base Classes
Name |
Description |
DelayedDestruction is a helper class to ensure objects are not deleted while they still have functions executing in a higher stack frame. |
|
Base interface for asynchronous sockets bound to an event base. |
Types
Name |
Description |
Interface notified when connections are accepted or accept errors occur. |
|
A callback interface to get notified of client socket events. |
|
Helper class to allow DelayedDestruction classes to be used with std::shared_ptr. |
|
Classes should create a DestructorGuard object on the stack in any function that may invoke callback functions. |
|
This smart pointer is a convenient way to manage a concrete DelayedDestructorBase child. It can replace the equivalent raw pointer and provide automatic memory management. |
Type Aliases
Name |
Description |
Function that assigns an accepted socket to a callback index. |
|
Bind to the specified port for the specified addresses/if names. |
|
Owning pointer type that routes destruction through Destructor. |
Member Functions
Name |
Description |
|
Constructors |
|
Deleted copy assignment operator. |
|
Add an AcceptCallback. |
Attach this AsyncServerSocket to its primary EventBase. |
|
|
|
|
Destroy the socket. |
Detach the AsyncServerSocket from its primary EventBase. |
|
Do not attempt the transparent TLS handshake |
|
Get the speed of adjusting connection accept rate. |
|
Get whether or not the socket is accepting new connections |
|
|
|
Get all the local addresses to which the socket is bound. |
|
Get whether or not FD_CLOEXEC is enabled on the server socket. |
|
Get the ConnectionEventCallback |
|
Returns whether destruction has been requested but deferred. |
|
|
Get the EventBase used by this socket. |
Get whether or not IP_FREEBIND is enabled on the server socket. |
|
Get whether or not SO_KEEPALIVE is enabled on the server socket. |
|
Get default TOS for listener socket |
|
Index of the callback with the same EVB as the current AsyncServerSocket instance, if any |
|
Get the maximum number of connections that will be accepted each time around the event loop. |
|
Get the maximum number of unprocessed messages which a NotificationQueue can hold. |
|
Backwards compatible getSocket |
|
Return the underlying file descriptor |
|
Get the number of connections dropped by the AsyncServerSocket |
|
Get the current number of unprocessed messages in NotificationQueue. |
|
Get the duration after which new connection messages will be dropped from the NotificationQueue if it has not started processing yet. |
|
Get whether or not SO_REUSEPORT is enabled on the server socket. |
|
Get TOS reflection for server socket |
|
|
Begin listening for connections. |
Pause accepting connections. |
|
Remove an AcceptCallback. |
|
Set the speed of adjusting connection accept rate. |
|
sets the callback assign function |
|
Set whether or not the socket should close during exec() (FD_CLOEXEC). By default, this is enabled |
|
Set the ConnectionEventCallback |
|
Set whether or not SO_REUSEADDR should be enabled on the server socket, allowing multiple sockets binds to the same <address>:<port> It's enabled by default. |
|
Set whether or not IP_FREEBIND is enabled on the server socket. Only supported on Linux. |
|
Set whether or not SO_KEEPALIVE should be enabled on the server socket (and thus on all subsequently‐accepted connections). By default, keepalive is enabled. |
|
Set default TOS for listener socket |
|
Set the maximum number of connections that will be accepted each time around the event loop. |
|
Set the maximum number of unprocessed messages in NotificationQueue. No new message will be sent to that NotificationQueue if there are more than such number of unprocessed messages in that queue. |
|
|
|
Set whether or not SO_REUSEPORT should be enabled on the server socket, allowing multiple binds to the same port |
|
Sets the ShutdownSocketSet that tracks this socket's file descriptors. |
|
Tries to enable TFO if the machine supports it. |
|
Enable/Disable TOS reflection for the server socket |
|
enable zerocopy support for the server sockets ‐ the s = accept sockets inherit it |
|
|
Begin accepting connctions on this socket. |
Shutdown the listen socket and notify all callbacks that accept has stopped |
|
Create a AsyncServerSocket from an existing socket file descriptor. |
|
Create a AsyncServerSocket from existing socket file descriptors. |
Static Member Functions
Name |
Description |
Helper function to create a shared_ptr<AsyncServerSocket>. |
Static Data Members
Name |
Description |
Default maximum connections a single callback accepts at once. |
|
Default maximum connections accepted per event loop iteration. |
|
Default maximum number of unprocessed messages in the queue. |
Protected Member Functions
Name |
Description |
|
Protected destructor. |
Get the number of DestructorGuards currently protecting this object. |
|
|
Implement onDelayedDestroy in subclasses. onDelayedDestroy() is invoked when the object is potentially being destroyed. |
Created with MrDocs