proxygen
|
#include <AsyncTransport.h>
Classes | |
class | BufferCallback |
class | ReplaySafetyCallback |
Public Types | |
typedef std::unique_ptr< AsyncTransport, Destructor > | UniquePtr |
Public Member Functions | |
virtual void | close ()=0 |
virtual void | closeNow ()=0 |
virtual void | closeWithReset () |
virtual void | shutdownWrite ()=0 |
virtual void | shutdownWriteNow ()=0 |
virtual bool | good () const =0 |
virtual bool | readable () const =0 |
virtual bool | writable () const |
virtual bool | isPending () const |
virtual bool | connecting () const =0 |
virtual bool | error () const =0 |
virtual void | attachEventBase (EventBase *eventBase)=0 |
virtual void | detachEventBase ()=0 |
virtual bool | isDetachable () const =0 |
virtual void | setSendTimeout (uint32_t milliseconds)=0 |
virtual uint32_t | getSendTimeout () const =0 |
virtual void | getLocalAddress (SocketAddress *address) const =0 |
SocketAddress | getLocalAddress () const |
void | getAddress (SocketAddress *address) const override |
virtual void | getPeerAddress (SocketAddress *address) const =0 |
SocketAddress | getPeerAddress () const |
virtual ssl::X509UniquePtr | getPeerCert () const |
virtual const X509 * | getSelfCert () const |
virtual const AsyncTransportCertificate * | getPeerCertificate () const |
virtual const AsyncTransportCertificate * | getSelfCertificate () const |
virtual std::string | getApplicationProtocol () const noexcept |
virtual std::string | getSecurityProtocol () const |
virtual bool | isEorTrackingEnabled () const =0 |
virtual void | setEorTracking (bool track)=0 |
virtual size_t | getAppBytesWritten () const =0 |
virtual size_t | getRawBytesWritten () const =0 |
virtual size_t | getAppBytesReceived () const =0 |
virtual size_t | getRawBytesReceived () const =0 |
virtual bool | isReplaySafe () const |
virtual void | setReplaySafetyCallback (ReplaySafetyCallback *callback) |
Public Member Functions inherited from folly::DelayedDestruction | |
virtual void | destroy () |
bool | getDestroyPending () const |
Public Member Functions inherited from folly::DelayedDestructionBase | |
virtual | ~DelayedDestructionBase ()=default |
Public Member Functions inherited from folly::AsyncSocketBase | |
virtual EventBase * | getEventBase () const =0 |
virtual | ~AsyncSocketBase ()=default |
Protected Member Functions | |
~AsyncTransport () override=default | |
Protected Member Functions inherited from folly::DelayedDestruction | |
~DelayedDestruction () override=default | |
DelayedDestruction () | |
Protected Member Functions inherited from folly::DelayedDestructionBase | |
DelayedDestructionBase () | |
uint32_t | getDestructorGuardCount () const |
AsyncTransport defines an asynchronous API for streaming I/O.
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.
Definition at line 150 of file AsyncTransport.h.
typedef std::unique_ptr<AsyncTransport, Destructor> folly::AsyncTransport::UniquePtr |
Definition at line 152 of file AsyncTransport.h.
|
overrideprotecteddefault |
|
pure virtual |
Attach the transport to a EventBase.
This may only be called if the transport is not currently attached to a EventBase (by an earlier call to detachEventBase()).
This method must be invoked in the EventBase's thread.
Implemented in folly::AsyncSSLSocket, folly::AsyncSocket, fizz::AsyncFizzBase, fizz::test::LocalTransport, TestAsyncTransport, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Close the transport.
This gracefully closes the transport, waiting for all pending write requests to complete before actually closing the underlying transport.
If a read callback is set, readEOF() will be called immediately. If there are outstanding write requests, the close will be delayed until all remaining writes have completed. No new writes may be started after close() has been called.
Implemented in folly::AsyncSocket, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::test::LocalTransport, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, TestAsyncTransport, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Close the transport immediately.
This closes the transport immediately, dropping any outstanding data waiting to be written.
If a read callback is set, readEOF() will be called immediately. If there are outstanding write requests, these requests will be aborted and writeError() will be invoked immediately on all outstanding write callbacks.
Implemented in folly::AsyncSocket, folly::AsyncSSLSocket, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::test::LocalTransport, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, TestAsyncTransport, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
inlinevirtual |
Reset the transport immediately.
This closes the transport immediately, sending a reset to the remote peer if possible to indicate abnormal shutdown.
Note that not all subclasses implement this reset functionality: some subclasses may treat reset() the same as closeNow(). Subclasses that use TCP transports should terminate the connection with a TCP reset.
Reimplemented in folly::AsyncSocket, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::test::LocalTransport, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 190 of file AsyncTransport.h.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Determine if transport is connected to the endpoint
Implemented in folly::AsyncSocket, folly::AsyncSSLSocket, fizz::client::AsyncFizzClientT< SM >, fizz::test::LocalTransport, folly::DecoratedAsyncTransportWrapper< T >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, TestAsyncTransport, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Detach the transport from its EventBase.
This may only be called when the transport is idle and has no reads or writes pending. Once detached, the transport may not be used again until it is re-attached to a EventBase by calling attachEventBase().
This method must be called from the current EventBase's thread.
Implemented in folly::AsyncSSLSocket, folly::AsyncSocket, fizz::AsyncFizzBase, fizz::test::LocalTransport, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, and TestAsyncTransport.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Determine if an error has occurred with this transport.
Implemented in folly::AsyncSocket, fizz::test::LocalTransport, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, TestAsyncTransport, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
inlineoverridevirtual |
Implements folly::AsyncSocketBase.
Definition at line 352 of file AsyncTransport.h.
|
pure virtual |
|
pure virtual |
|
inlinevirtualnoexcept |
Return the application protocol being used by the underlying transport protocol. This is useful for transports which are used to tunnel other protocols.
Reimplemented in folly::AsyncSSLSocket, fizz::test::MockAsyncFizzBase, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >, and fizz::test::AsyncFizzBaseTest.
Definition at line 414 of file AsyncTransport.h.
|
pure virtual |
Get the address of the local endpoint of this transport.
This function may throw AsyncSocketException on error.
address | The local address will be stored in the specified SocketAddress. |
Implemented in folly::AsyncSocket, fizz::test::LocalTransport, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, and TestAsyncTransport.
|
inline |
Get the address of the remote endpoint to which this transport is connected.
This function may throw AsyncSocketException on error.
Definition at line 346 of file AsyncTransport.h.
References addr.
Referenced by folly::test::MockAsyncSocket::connect(), folly::test::MockAsyncSSLSocket::connect(), folly::AsyncSocket::withAddr(), folly::test::MockAsyncTransport::writeChain(), and folly::AsyncSocket::writeRequestReady().
|
pure virtual |
Get the address of the remote endpoint to which this transport is connected.
This function may throw AsyncSocketException on error.
address | The remote endpoint's address will be stored in the specified SocketAddress. |
Implemented in folly::AsyncSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, and TestAsyncTransport.
|
inline |
Get the address of the remote endpoint to which this transport is connected.
This function may throw AsyncSocketException on error.
Definition at line 375 of file AsyncTransport.h.
References addr.
Referenced by folly::test::MockAsyncSocket::connect(), folly::test::MockAsyncSSLSocket::connect(), folly::AsyncSocket::withAddr(), folly::test::MockAsyncTransport::writeChain(), and folly::AsyncSocket::writeRequestReady().
|
inlinevirtual |
Get the certificate used to authenticate the peer.
Reimplemented in folly::AsyncSSLSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 384 of file AsyncTransport.h.
Referenced by ConnectionFilterTest::createDefaultOpts().
|
inlinevirtual |
Get the peer certificate information if any
Reimplemented in folly::AsyncSocket, folly::AsyncSSLSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 398 of file AsyncTransport.h.
|
pure virtual |
|
pure virtual |
|
inlinevirtual |
Returns the name of the security protocol being used.
Reimplemented in folly::AsyncSSLSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, and fizz::AsyncFizzBase.
Definition at line 421 of file AsyncTransport.h.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
inlinevirtual |
The local certificate used for this connection. May be null
Reimplemented in folly::AsyncSSLSocket, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 391 of file AsyncTransport.h.
|
inlinevirtual |
Get the certificate information of this transport, if any
Reimplemented in folly::AsyncSocket, folly::AsyncSSLSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 405 of file AsyncTransport.h.
|
pure virtual |
Get the send timeout.
Implemented in folly::AsyncSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, and TestAsyncTransport.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Determine if transport is open and ready to read or write.
Note that this function returns false on EOF; you must also call error() to distinguish between an EOF and an error.
Implemented in folly::AsyncSocket, folly::AsyncSSLSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, TestAsyncTransport, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Determine if the transport can be detached.
This method must be called from the current EventBase's thread.
Implemented in folly::AsyncSSLSocket, folly::AsyncSocket, fizz::AsyncFizzBase, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, TestAsyncTransport, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Implemented in folly::AsyncSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, and TestAsyncTransport.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
inlinevirtual |
Determine if the there is pending data on the transport.
Reimplemented in folly::AsyncSocket.
Definition at line 260 of file AsyncTransport.h.
References folly::pushmi::operators::error(), and uint32_t.
|
inlinevirtual |
False if the transport does not have replay protection, but will in the future.
Reimplemented in folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 463 of file AsyncTransport.h.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Determine if the transport is readable or not.
Implemented in folly::AsyncSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, TestAsyncTransport, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
|
inlinevirtual |
Set the ReplaySafeCallback on this transport.
This should only be called if isReplaySafe() returns false.
Reimplemented in folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::client::AsyncFizzClientT< SM >, fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance >, fizz::AsyncFizzBase, fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.
Definition at line 472 of file AsyncTransport.h.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Set the send timeout.
If write requests do not make any progress for more than the specified number of milliseconds, fail all pending writes and close the transport.
If write requests are currently pending when setSendTimeout() is called, the timeout interval is immediately restarted using the new value.
milliseconds | The timeout duration, in milliseconds. If 0, no timeout will be used. |
Implemented in folly::AsyncSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, and TestAsyncTransport.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Perform a half-shutdown of the write side of the transport.
The caller should not make any more calls to write() or writev() after shutdownWrite() is called. Any future write attempts will fail immediately.
Not all transport types support half-shutdown. If the underlying transport does not support half-shutdown, it will fully shutdown both the read and write sides of the transport. (Fully shutting down the socket is better than doing nothing at all, since the caller may rely on the shutdownWrite() call to notify the other end of the connection that no more data can be read.)
If there is pending data still waiting to be written on the transport, the actual shutdown will be delayed until the pending data has been written.
Note: There is no corresponding shutdownRead() equivalent. Simply uninstall the read callback if you wish to stop reading. (On TCP sockets at least, shutting down the read side of the socket is a no-op anyway.)
Implemented in folly::AsyncSocket, folly::AsyncSSLSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, and TestAsyncTransport.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
pure virtual |
Perform a half-shutdown of the write side of the transport.
shutdownWriteNow() is identical to shutdownWrite(), except that it immediately performs the shutdown, rather than waiting for pending writes to complete. Any pending write requests will be immediately failed when shutdownWriteNow() is called.
Implemented in folly::AsyncSocket, folly::AsyncSSLSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, and TestAsyncTransport.
Referenced by folly::test::MockAsyncTransport::writeChain().
|
inlinevirtual |
Determine if the transport is writable or not.
Reimplemented in folly::AsyncSocket, folly::DecoratedAsyncTransportWrapper< T >, and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >.
Definition at line 250 of file AsyncTransport.h.