proxygen
folly::AsyncTransport Class Referenceabstract

#include <AsyncTransport.h>

Inheritance diagram for folly::AsyncTransport:
folly::DelayedDestruction folly::AsyncSocketBase folly::DelayedDestructionBase folly::AsyncTransportWrapper folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper > fizz::test::LocalTransport folly::AsyncSocket folly::DecoratedAsyncTransportWrapper< T > folly::test::MockAsyncTransport TestAsyncTransport folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper > AsyncSocketImmediateRead folly::AsyncSSLSocket folly::test::MockAsyncSocket folly::WriteChainAsyncTransportWrapper< T > fizz::AsyncFizzBase folly::test::TestWriteChainAsyncTransportWrapper folly::MockAsyncSSLSocket folly::test::MockAsyncSSLSocket fizz::client::AsyncFizzClientT< fizz::client::test::MockClientStateMachineInstance > fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance > fizz::client::AsyncFizzClientT< SM > fizz::server::AsyncFizzServerT< SM > fizz::test::AsyncFizzBaseTest fizz::test::MockAsyncFizzBase fizz::client::test::MockAsyncFizzClient fizz::server::test::MockAsyncFizzServerT< SM >

Classes

class  BufferCallback
 
class  ReplaySafetyCallback
 

Public Types

typedef std::unique_ptr< AsyncTransport, DestructorUniquePtr
 

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 AsyncTransportCertificategetPeerCertificate () const
 
virtual const AsyncTransportCertificategetSelfCertificate () 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 EventBasegetEventBase () 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
 

Detailed Description

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.

Member Typedef Documentation

Definition at line 152 of file AsyncTransport.h.

Constructor & Destructor Documentation

folly::AsyncTransport::~AsyncTransport ( )
overrideprotecteddefault

Member Function Documentation

virtual void folly::AsyncTransport::attachEventBase ( EventBase eventBase)
pure virtual
virtual void folly::AsyncTransport::close ( )
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().

virtual void folly::AsyncTransport::closeNow ( )
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().

virtual void folly::AsyncTransport::closeWithReset ( )
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().

190  {
191  closeNow();
192  }
virtual void closeNow()=0
virtual void folly::AsyncTransport::detachEventBase ( )
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().

void folly::AsyncTransport::getAddress ( SocketAddress address) const
inlineoverridevirtual

Implements folly::AsyncSocketBase.

Definition at line 352 of file AsyncTransport.h.

352  {
353  getLocalAddress(address);
354  }
SocketAddress getLocalAddress() const
virtual std::string folly::AsyncTransport::getApplicationProtocol ( ) const
inlinevirtualnoexcept
virtual void folly::AsyncTransport::getLocalAddress ( SocketAddress address) const
pure virtual

Get the address of the local endpoint of this transport.

This function may throw AsyncSocketException on error.

Parameters
addressThe 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.

SocketAddress folly::AsyncTransport::getLocalAddress ( ) const
inline

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

This function may throw AsyncSocketException on error.

Returns
Return the local address

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().

346  {
347  SocketAddress addr;
348  getLocalAddress(&addr);
349  return addr;
350  }
SocketAddress getLocalAddress() const
ThreadPoolListHook * addr
virtual void folly::AsyncTransport::getPeerAddress ( SocketAddress address) const
pure virtual

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

This function may throw AsyncSocketException on error.

Parameters
addressThe 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.

SocketAddress folly::AsyncTransport::getPeerAddress ( ) const
inline

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

This function may throw AsyncSocketException on error.

Returns
Return the remote endpoint's address

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().

375  {
376  SocketAddress addr;
377  getPeerAddress(&addr);
378  return addr;
379  }
SocketAddress getPeerAddress() const
ThreadPoolListHook * addr
virtual std::string folly::AsyncTransport::getSecurityProtocol ( ) const
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().

421  {
422  return "";
423  }
virtual const X509* folly::AsyncTransport::getSelfCert ( ) const
inlinevirtual
virtual uint32_t folly::AsyncTransport::getSendTimeout ( ) const
pure virtual

Get the send timeout.

Returns
Returns the current send timeout, in milliseconds. A return value of 0 indicates that no timeout is set.

Implemented in folly::AsyncSocket, folly::DecoratedAsyncTransportWrapper< T >, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >, fizz::test::LocalTransport, and TestAsyncTransport.

Referenced by folly::test::MockAsyncTransport::writeChain().

virtual bool folly::AsyncTransport::good ( ) const
pure virtual
virtual bool folly::AsyncTransport::isEorTrackingEnabled ( ) const
pure virtual
virtual bool folly::AsyncTransport::isPending ( ) const
inlinevirtual

Determine if the there is pending data on the transport.

Returns
true iff the if the there is pending data, false otherwise.

Reimplemented in folly::AsyncSocket.

Definition at line 260 of file AsyncTransport.h.

References folly::pushmi::operators::error(), and uint32_t.

260  {
261  return readable();
262  }
virtual bool readable() const =0
virtual void folly::AsyncTransport::setReplaySafetyCallback ( ReplaySafetyCallback callback)
inlinevirtual
virtual void folly::AsyncTransport::setSendTimeout ( uint32_t  milliseconds)
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.

Parameters
millisecondsThe 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().

virtual void folly::AsyncTransport::shutdownWrite ( )
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().

virtual void folly::AsyncTransport::shutdownWriteNow ( )
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().

virtual bool folly::AsyncTransport::writable ( ) const
inlinevirtual

Determine if the transport is writable or not.

Returns
true iff the transport is writable, false otherwise.

Reimplemented in folly::AsyncSocket, folly::DecoratedAsyncTransportWrapper< T >, and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >.

Definition at line 250 of file AsyncTransport.h.

250  {
251  // By default return good() - leave it to implementers to override.
252  return good();
253  }
virtual bool good() const =0

The documentation for this class was generated from the following file: