Abstract asynchronous transport backed by a socket.

Synopsis

Declared in <folly/io/async/AsyncSocketTransport.h>

class AsyncSocketTransport
    : public AsyncTransport

Base Classes

Name

Description

AsyncTransport

AsyncTransport defines an asynchronous API for bidirectional streaming I/O.

Types

Name

Description

BufferCallback

Callback class to signal changes in the transport's internal buffers.

ConnectCallback

Callback invoked on the outcome of a connection attempt.

Destructor

Helper class to allow DelayedDestruction classes to be used with std::shared_ptr.

DestructorGuard

Classes should create a DestructorGuard object on the stack in any function that may invoke callback functions.

IntrusivePtr

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.

RXZerocopyParams

Parameters controlling receive‐side zero‐copy.

ReadCallback

Callback interface used to receive data read from the transport.

ReleaseIOBufCallback

Callback invoked to release ownership of an IOBuf after a write.

ReplaySafetyCallback

Callback class to signal when a transport that did not have replay protection gains replay protection. This is needed for 0‐RTT security protocols.

WriteCallback

Callback interface used to report the result of a write.

Type Aliases

Name

Description

BindOptions

Options for binding a socket before connecting. The two alternatives are mutually exclusive: ‐ SocketAddress: bind to a local address before connecting. ‐ NetworkSocket: use a pre‐bound (or pre‐created) socket fd. Ownership of the fd is transferred to the AsyncSocketTransport.

UniquePtr

Owning pointer type that respects the transport's deferred destructor.

ZeroCopyEnableFunc

Predicate deciding whether a given buffer should use zero‐copy writes.

Member Functions

Name

Description

operator= [deleted]

Deleted copy assignment operator.

attachEventBase [virtual]

Attach the transport to a EventBase.

cacheAddresses [virtual]

Caches the local and peer addresses of the socket.

cancelConnect [virtual]

If a connect request is in‐flight, cancels it and closes the socket immediately. Otherwise, this is a no‐op.

close [virtual]

Close the transport.

closeNow [virtual]

Close the transport immediately.

closeWithReset [virtual]

Reset the transport immediately.

connect [virtual]

Initiates an asynchronous connection to the given address.

connecting [virtual]

Determine if transport is connected to the endpoint

destroy [virtual]

destroy() requests destruction of the object.

detachEventBase [virtual]

Detach the transport from its EventBase.

disableTransparentTls [virtual]

Disables transparent TLS handling on the socket.

dropPeerCertificate [virtual]

Releases the cached peer certificate.

dropSelfCertificate [virtual]

Releases the cached self certificate.

enableTFO [virtual]

Enables TCP Fast Open on the socket.

error [virtual]

Determine if an error has occurred with this transport.

getAddress [virtual]

Store the local address of this transport in the given SocketAddress.

getAllocatedBytesBuffered [virtual]

Return the number of allocated bytes buffered to be written later.

getAppBytesBuffered [virtual]

Calculates the total number of bytes that are currently buffered in the transport to be written later.

getAppBytesReceived [virtual]

Return the number of application‐level bytes received.

getAppBytesWritten [virtual]

Return the number of application‐level bytes written.

getApplicationProtocol [virtual]

Return the application protocol being used by the underlying transport protocol. This is useful for transports which are used to tunnel other protocols.

getDestroyPending

Returns whether destruction has been requested but deferred.

getEventBase [virtual]

Returns the event base this socket is attached to.

getExportedKeyingMaterial [virtual]

Produce exported keying material for this transport.

getLocalAddress

getLocalAddress overloads

getNapiId [virtual]

Returns the NAPI id associated with the socket.

getNetworkSocket [virtual]

Returns the underlying network socket handle.

getPeerAddress

Get the address of the remote endpoint to which this transport is connected.

getPeerCertificate [virtual]

Returns the peer's certificate, or nullptr if none is set.

getRXZeroCopy [virtual]

Return whether receive‐side zero‐copy is enabled.

getRawBytesBuffered [virtual]

Return the number of raw bytes buffered to be written later.

getRawBytesReceived [virtual]

Return the number of raw bytes received from the underlying transport.

getRawBytesWritten [virtual]

Return the number of raw bytes written to the underlying transport.

getReadCallback [virtual]

Return the currently installed read callback.

getSecurityProtocol [virtual]

Returns the name of the security protocol being used.

getSelfCertificate [virtual]

Returns this endpoint's certificate, or nullptr if none is set.

getSendTimeout [virtual]

Get the send timeout.

getTFOSucceeded [virtual]

Returns whether TCP Fast Open succeeded for this connection.

getUnderlyingTransport

getUnderlyingTransport overloads

getWrappedTransport [virtual]

AsyncTransports may wrap other AsyncTransport. This returns the transport that is wrapped. It returns nullptr if there is no wrapped transport.

getWrappingTransport

getWrappingTransport overloads

getZeroCopy [virtual]

Return whether zero‐copy writes are enabled.

good [virtual]

Determine if transport is open and ready to read or write.

hangup [virtual]

Returns whether the peer has hung up the connection.

isDetachable [virtual]

Determine if the transport can be detached.

isEorTrackingEnabled [virtual]

Return whether end‐of‐record tracking is enabled.

isPending [virtual]

Determine if the there is pending data on the transport.

isReplaySafe [virtual]

False if the transport does not have replay protection, but will in the future.

readable [virtual]

Determine if the transport is readable or not.

setEorTracking [virtual]

Enable or disable end‐of‐record tracking.

setNoDelay [virtual]

Enables or disables Nagle's algorithm on the socket.

setPeerCertificate

Stores the peer's certificate for later retrieval.

setPreReceivedData [virtual]

Provides data to be treated as if it had already been received.

setRXZeroCopy [virtual]

Enable or disable receive‐side zero‐copy using the given parameters.

setReadCB [virtual]

Install the read callback that will receive read events.

setReplaySafetyCallback [virtual]

Set the ReplaySafeCallback on this transport.

setSelfCertificate

Stores this endpoint's certificate for later retrieval.

setSendTimeout [virtual]

Set the send timeout.

setSockOpt [virtual]

Sets a socket option on the underlying socket.

setZeroCopy [virtual]

Enable or disable zero‐copy writes.

setZeroCopyEnableFunc [virtual]

Set the predicate deciding when zero‐copy writes are used.

setZeroCopyEnableThreshold [virtual]

Set the minimum write size, in bytes, for using zero‐copy writes.

shutdownWrite [virtual]

Perform a half‐shutdown of the write side of the transport.

shutdownWriteNow [virtual]

Perform a half‐shutdown of the write side of the transport.

takePreReceivedData [virtual]

Take any data received before a read callback was installed.

tryExchangeUnderlyingTransport

Exchange the underlying transport of type T with the given one.

tryExchangeWrappedTransport [virtual]

Exchange the directly wrapped transport with the given one.

writable [virtual]

Determine if the transport is writable or not.

write [virtual]

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.

writeChain [virtual]

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.

writev [virtual]

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.

Static Member Functions

Name

Description

anyAddress

Returns a wildcard address usable as a default bind target.

Protected Member Functions

Name

Description

~AsyncSocketTransport [destructor] [virtual]

Destroys the transport.

getDestructorGuardCount

Get the number of DestructorGuards currently protecting this object.

onDelayedDestroy [virtual]

Implement onDelayedDestroy in subclasses. onDelayedDestroy() is invoked when the object is potentially being destroyed.

Protected Data Members

Name

Description

peerCertData_

Cached peer certificate; subclasses may populate it on first access.

selfCertData_

Cached self certificate; subclasses may populate it on first access.

Derived Classes

Name

Description

AsyncIoUringSocket

AsyncSocket

An asynchronous socket.

Created with MrDocs