AsyncTransport defines an asynchronous API for bidirectional streaming I/O.
Synopsis
Declared in <folly/io/async/AsyncTransport.h>
class AsyncTransport
: public DelayedDestruction
, public AsyncSocketBase
, public AsyncReader
, public AsyncWriter
Description
This class provides an API to for asynchronously waiting for data on a streaming transport, and for asynchronously sending data.
The APIs for reading and writing are intentionally asymmetric. Waiting for data to read is a persistent API: a callback is installed, and is notified whenever new data is available. It continues to be notified of new events until it is uninstalled.
AsyncTransport does not provide read timeout functionality, because it typically cannot determine when the timeout should be active. Generally, a timeout should only be enabled when processing is blocked waiting on data from the remote endpoint. For server‐side applications, the timeout should not be active if the server is currently processing one or more outstanding requests on this transport. For client‐side applications, the timeout should not be active if there are no requests pending on the transport. Additionally, if a client has multiple pending requests, it will ususally want a separate timeout for each request, rather than a single read timeout.
The write API is fairly intuitive: a user can request to send a block of data, and a callback will be informed once the entire block has been transferred to the kernel, or on error. AsyncTransport does provide a send timeout, since most callers want to give up if the remote end stops responding and no further progress can be made sending the data.
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. |
|
Interface for the read side of an asynchronous transport. |
|
Interface for the write side of an asynchronous transport. |
Types
Name |
Description |
Callback class to signal changes in the transport's internal buffers. |
|
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. |
|
Parameters controlling receive‐side zero‐copy. |
|
Callback interface used to receive data read from the transport. |
|
Callback invoked to release ownership of an IOBuf after a write. |
|
Callback class to signal when a transport that did not have replay protection gains replay protection. This is needed for 0‐RTT security protocols. |
|
Callback interface used to report the result of a write. |
Type Aliases
Name |
Description |
Owning pointer that uses the DelayedDestruction Destructor. |
|
Predicate deciding whether a given buffer should use zero‐copy writes. |
Member Functions
Name |
Description |
|
Deleted copy assignment operator. |
|
Attach the transport to a EventBase. |
|
Close the transport. |
|
Close the transport immediately. |
|
Reset the transport immediately. |
|
Determine if transport is connected to the endpoint |
|
destroy() requests destruction of the object. |
|
Detach the transport from its EventBase. |
|
Hints to transport implementations that the associated certificate is no longer required by the application. The transport implementation may choose to free up resources associated with the peer certificate. |
|
Hints to transport implementations that the associated certificate is no longer required by the application. The transport implementation may choose to free up resources associated with the self certificate. |
|
Determine if an error has occurred with this transport. |
|
Store the local address of this transport in the given SocketAddress. |
|
Return the number of allocated bytes buffered to be written later. |
|
Calculates the total number of bytes that are currently buffered in the transport to be written later. |
|
Return the number of application‐level bytes received. |
|
Return the number of application‐level bytes written. |
|
Return the application protocol being used by the underlying transport protocol. This is useful for transports which are used to tunnel other protocols. |
Returns whether destruction has been requested but deferred. |
|
|
Returns the event base this socket is attached to. |
|
Produce exported keying material for this transport. |
|
|
|
Return SO_INCOMING_NAPI_ID for this transport. For socket transports, this is associated with the NAPI instance/receive queue. For other transports, it is not defined. |
Get the address of the remote endpoint to which this transport is connected. |
|
|
Get the peer certificate information if any |
|
Return whether receive‐side zero‐copy is enabled. |
|
Return the number of raw bytes buffered to be written later. |
|
Return the number of raw bytes received from the underlying transport. |
|
Return the number of raw bytes written to the underlying transport. |
|
Return the currently installed read callback. |
|
Returns the name of the security protocol being used. |
|
Get the certificate information of this transport, if any |
|
Get the send timeout. |
|
|
|
AsyncTransports may wrap other AsyncTransport. This returns the transport that is wrapped. It returns nullptr if there is no wrapped transport. |
|
|
|
Return whether zero‐copy writes are enabled. |
|
Determine if transport is open and ready to read or write. |
|
Determine if the transport can be detached. |
|
Return whether end‐of‐record tracking is enabled. |
|
Determine if the there is pending data on the transport. |
|
False if the transport does not have replay protection, but will in the future. |
|
Determine if the transport is readable or not. |
|
Enable or disable end‐of‐record tracking. |
|
Enable or disable receive‐side zero‐copy using the given parameters. |
|
Install the read callback that will receive read events. |
|
Set the ReplaySafeCallback on this transport. |
|
Set the send timeout. |
|
Enable or disable zero‐copy writes. |
|
Set the predicate deciding when zero‐copy writes are used. |
|
Set the minimum write size, in bytes, for using zero‐copy writes. |
|
Perform a half‐shutdown of the write side of the transport. |
|
Perform a half‐shutdown of the write side of the transport. |
|
Take any data received before a read callback was installed. |
Exchange the underlying transport of type T with the given one. |
|
|
Exchange the directly wrapped transport with the given one. |
|
Determine if the transport is writable or not. |
|
If you supply a non‐null WriteCallback, exactly one of writeSuccess() or writeErr() will be invoked when the write completes. If you supply the same WriteCallback object for multiple write() calls, it will be invoked exactly once per call. The only way to cancel outstanding write requests is to close the socket (e.g., with closeNow() or shutdownWriteNow()). When closing the socket this way, writeErr() will still be invoked once for each outstanding write operation. |
|
If you supply a non‐null WriteCallback, exactly one of writeSuccess() or writeErr() will be invoked when the write completes. If you supply the same WriteCallback object for multiple write() calls, it will be invoked exactly once per call. The only way to cancel outstanding write requests is to close the socket (e.g., with closeNow() or shutdownWriteNow()). When closing the socket this way, writeErr() will still be invoked once for each outstanding write operation. |
|
If you supply a non‐null WriteCallback, exactly one of writeSuccess() or writeErr() will be invoked when the write completes. If you supply the same WriteCallback object for multiple write() calls, it will be invoked exactly once per call. The only way to cancel outstanding write requests is to close the socket (e.g., with closeNow() or shutdownWriteNow()). When closing the socket this way, writeErr() will still be invoked once for each outstanding write operation. |
Protected Member Functions
Name |
Description |
|
Destroy the transport. |
Get the number of DestructorGuards currently protecting this object. |
|
|
Implement onDelayedDestroy in subclasses. onDelayedDestroy() is invoked when the object is potentially being destroyed. |
Friends
Name |
Description |
Convenience class so that AsyncTransport can be decorated without having to redefine every single method. |
Derived Classes
Name |
Description |
Abstract asynchronous transport backed by a socket. |
|
Convenience class so that AsyncTransport can be decorated without having to redefine every single method. |
Created with MrDocs