proxygen
fizz::AsyncFizzBase Class Referenceabstract

#include <AsyncFizzBase.h>

Inheritance diagram for fizz::AsyncFizzBase:
folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper > folly::AsyncWriter::WriteCallback folly::AsyncReader::ReadCallback folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper > folly::AsyncTransportWrapper folly::AsyncTransport folly::AsyncReader folly::AsyncWriter folly::DelayedDestruction folly::AsyncSocketBase folly::DelayedDestructionBase 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  HandshakeTimeout
 

Public Types

using UniquePtr = std::unique_ptr< AsyncFizzBase, folly::DelayedDestruction::Destructor >
 
using ReadCallback = folly::AsyncTransportWrapper::ReadCallback
 
- Public Types inherited from folly::AsyncTransportWrapper
using UniquePtr = std::unique_ptr< AsyncTransportWrapper, Destructor >
 
using ReadCallback = AsyncReader::ReadCallback
 
using WriteCallback = AsyncWriter::WriteCallback
 
- Public Types inherited from folly::AsyncTransport
typedef std::unique_ptr< AsyncTransport, DestructorUniquePtr
 

Public Member Functions

 AsyncFizzBase (folly::AsyncTransportWrapper::UniquePtr transport)
 
 ~AsyncFizzBase () override
 
ReadCallbackgetReadCallback () const override
 
void setReadCB (ReadCallback *callback) override
 
void writeChain (folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE) override
 
size_t getAppBytesWritten () const override
 
size_t getAppBytesReceived () const override
 
bool good () const override=0
 
bool readable () const override=0
 
bool connecting () const override=0
 
bool error () const override=0
 
folly::ssl::X509UniquePtr getPeerCert () const override=0
 
const X509 * getSelfCert () const override=0
 
const CertgetPeerCertificate () const override=0
 
const CertgetSelfCertificate () const override=0
 
bool isReplaySafe () const override=0
 
void setReplaySafetyCallback (folly::AsyncTransport::ReplaySafetyCallback *callback) override=0
 
std::string getApplicationProtocol () const noexceptoverride=0
 
virtual folly::Optional< CipherSuitegetCipher () const =0
 
virtual std::vector< SignatureSchemegetSupportedSigSchemes () const =0
 
virtual Buf getEkm (folly::StringPiece label, const Buf &context, uint16_t length) const =0
 
void destroy () override
 
std::string getSecurityProtocol () const override
 
void attachTimeoutManager (folly::TimeoutManager *manager)
 
void detachTimeoutManager ()
 
void attachEventBase (folly::EventBase *eventBase) override
 
void detachEventBase () override
 
bool isDetachable () const override
 
- Public Member Functions inherited from folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper >
void write (folly::AsyncTransportWrapper::WriteCallback *callback, const void *buf, size_t bytes, folly::WriteFlags flags=folly::WriteFlags::NONE) override
 
void writev (folly::AsyncTransportWrapper::WriteCallback *callback, const iovec *vec, size_t count, folly::WriteFlags flags=folly::WriteFlags::NONE) override
 
- Public Member Functions inherited from folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >
 DecoratedAsyncTransportWrapper (typename folly::AsyncTransportWrapper::UniquePtr transport)
 
const AsyncTransportWrappergetWrappedTransport () const override
 
ReadCallbackgetReadCallback () const override
 
void setReadCB (folly::AsyncTransportWrapper::ReadCallback *callback) override
 
folly::EventBasegetEventBase () const override
 
void attachEventBase (folly::EventBase *eventBase) override
 
void close () override
 
void closeNow () override
 
void closeWithReset () override
 
bool connecting () const override
 
void detachEventBase () override
 
bool error () const override
 
size_t getAppBytesReceived () const override
 
size_t getAppBytesWritten () const override
 
void getLocalAddress (folly::SocketAddress *address) const override
 
void getPeerAddress (folly::SocketAddress *address) const override
 
folly::ssl::X509UniquePtr getPeerCert () const override
 
size_t getRawBytesReceived () const override
 
size_t getRawBytesWritten () const override
 
uint32_t getSendTimeout () const override
 
bool good () const override
 
bool isDetachable () const override
 
bool isEorTrackingEnabled () const override
 
bool readable () const override
 
bool writable () const override
 
void setEorTracking (bool track) override
 
void setSendTimeout (uint32_t timeoutInMs) override
 
void shutdownWrite () override
 
void shutdownWriteNow () override
 
std::string getApplicationProtocol () const noexceptoverride
 
std::string getSecurityProtocol () const override
 
bool isReplaySafe () const override
 
void setReplaySafetyCallback (folly::AsyncTransport::ReplaySafetyCallback *callback) override
 
const AsyncTransportCertificategetPeerCertificate () const override
 
const AsyncTransportCertificategetSelfCertificate () const override
 
- Public Member Functions inherited from folly::AsyncTransportWrapper
template<class T >
const TgetUnderlyingTransport () const
 
template<class T >
TgetUnderlyingTransport ()
 
- Public Member Functions inherited from folly::AsyncTransport
virtual bool isPending () const
 
SocketAddress getLocalAddress () const
 
void getAddress (SocketAddress *address) const override
 
SocketAddress getPeerAddress () const
 
- Public Member Functions inherited from folly::DelayedDestruction
bool getDestroyPending () const
 
- Public Member Functions inherited from folly::DelayedDestructionBase
virtual ~DelayedDestructionBase ()=default
 
- Public Member Functions inherited from folly::AsyncSocketBase
virtual ~AsyncSocketBase ()=default
 

Protected Member Functions

virtual void startTransportReads ()
 
virtual void startHandshakeTimeout (std::chrono::milliseconds)
 
virtual void cancelHandshakeTimeout ()
 
virtual void deliverAppData (std::unique_ptr< folly::IOBuf > buf)
 
virtual void deliverError (const folly::AsyncSocketException &ex, bool closeTransport=true)
 
virtual void writeAppData (folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE)=0
 
virtual void transportError (const folly::AsyncSocketException &ex)=0
 
virtual void transportDataAvailable ()=0
 
- Protected Member Functions inherited from folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >
 ~DecoratedAsyncTransportWrapper () override
 
- Protected Member Functions inherited from folly::AsyncTransport
 ~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
 
- Protected Member Functions inherited from folly::AsyncReader
virtual ~AsyncReader ()=default
 
- Protected Member Functions inherited from folly::AsyncWriter
virtual ~AsyncWriter ()=default
 
- Protected Member Functions inherited from folly::AsyncWriter::WriteCallback
virtual ~WriteCallback ()=default
 

Protected Attributes

folly::IOBufQueue transportReadBuf_ {folly::IOBufQueue::cacheChainLength()}
 
- Protected Attributes inherited from folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >
folly::AsyncTransportWrapper::UniquePtr transport_
 

Private Member Functions

void getReadBuffer (void **bufReturn, size_t *lenReturn) override
 
void readDataAvailable (size_t len) noexceptoverride
 
bool isBufferMovable () noexceptoverride
 
void readBufferAvailable (std::unique_ptr< folly::IOBuf > data) noexceptoverride
 
void readEOF () noexceptoverride
 
void readErr (const folly::AsyncSocketException &ex) noexceptoverride
 
void writeSuccess () noexceptoverride
 
void writeErr (size_t bytesWritten, const folly::AsyncSocketException &ex) noexceptoverride
 
void checkBufLen ()
 
void handshakeTimeoutExpired () noexcept
 
- Private Member Functions inherited from folly::AsyncReader::ReadCallback
virtual ~ReadCallback ()=default
 
virtual size_t maxBufferSize () const
 

Private Attributes

ReadCallbackreadCallback_ {nullptr}
 
std::unique_ptr< folly::IOBufappDataBuf_
 
size_t appBytesWritten_ {0}
 
size_t appBytesReceived_ {0}
 
HandshakeTimeout handshakeTimeout_
 

Detailed Description

This class is a wrapper around AsyncTransportWrapper to handle most app level interactions so that the derived client and server classes

Definition at line 24 of file AsyncFizzBase.h.

Member Typedef Documentation

Constructor & Destructor Documentation

fizz::AsyncFizzBase::AsyncFizzBase ( folly::AsyncTransportWrapper::UniquePtr  transport)
explicit
fizz::AsyncFizzBase::~AsyncFizzBase ( )
override

Member Function Documentation

void fizz::AsyncFizzBase::attachEventBase ( folly::EventBase eventBase)
inlineoverridevirtual

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.

Implements folly::AsyncTransport.

Reimplemented in fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.

Definition at line 135 of file AsyncFizzBase.h.

References folly::AsyncTimeout::attachEventBase(), attachEventBase(), good(), handshakeTimeout_, readCallback_, startTransportReads(), and fizz::AsyncFizzBase::HandshakeTimeout::transport_.

Referenced by fizz::server::AsyncFizzServerT< SM >::attachEventBase(), and attachEventBase().

135  {
137  transport_->attachEventBase(eventBase);
138  // we want to avoid setting a read cb on a bad transport (i.e. closed or
139  // disconnected) unless we have a read callback we can pass the errors to.
140  if (transport_->good() || readCallback_) {
142  }
143  }
HandshakeTimeout handshakeTimeout_
virtual void startTransportReads()
void attachEventBase(EventBase *eventBase, InternalEnum internal=InternalEnum::NORMAL)
ReadCallback * readCallback_
void fizz::AsyncFizzBase::attachTimeoutManager ( folly::TimeoutManager manager)
inline

EventBase operations.

Definition at line 129 of file AsyncFizzBase.h.

References folly::AsyncTimeout::attachTimeoutManager(), and handshakeTimeout_.

129  {
131  }
void attachTimeoutManager(TimeoutManager *timeoutManager, InternalEnum internal=InternalEnum::NORMAL)
HandshakeTimeout handshakeTimeout_
void fizz::AsyncFizzBase::cancelHandshakeTimeout ( )
protectedvirtual
void fizz::AsyncFizzBase::checkBufLen ( )
private

Definition at line 222 of file AsyncFizzBase.cpp.

References appDataBuf_, folly::IOBufQueue::chainLength(), fizz::kMaxBufSize, readCallback_, folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_, and transportReadBuf_.

Referenced by deliverAppData(), readBufferAvailable(), and readDataAvailable().

222  {
223  if (!readCallback_ &&
225  (appDataBuf_ && appDataBuf_->computeChainDataLength() >= kMaxBufSize))) {
226  transport_->setReadCB(nullptr);
227  }
228 }
folly::IOBufQueue transportReadBuf_
size_t chainLength() const
Definition: IOBufQueue.h:492
std::unique_ptr< folly::IOBuf > appDataBuf_
static const uint32_t kMaxBufSize
ReadCallback * readCallback_
bool fizz::AsyncFizzBase::connecting ( ) const
overridepure virtual
void fizz::AsyncFizzBase::deliverAppData ( std::unique_ptr< folly::IOBuf buf)
protectedvirtual

Interfaces for the derived class to interact with the app level read callback.

Definition at line 100 of file AsyncFizzBase.cpp.

References appBytesReceived_, appDataBuf_, folly::AsyncSocketException::BAD_ARGS, checkBufLen(), folly::IOBuf::computeChainDataLength(), deliverError(), folly::AsyncReader::ReadCallback::getReadBuffer(), folly::AsyncReader::ReadCallback::isBufferMovable(), min, folly::gen::move, folly::AsyncReader::ReadCallback::readBufferAvailable(), readCallback_, and folly::AsyncReader::ReadCallback::readDataAvailable().

Referenced by isDetachable(), and setReadCB().

100  {
101  if (data) {
102  appBytesReceived_ += data->computeChainDataLength();
103  }
104 
105  if (appDataBuf_) {
106  if (data) {
107  appDataBuf_->prependChain(std::move(data));
108  }
110  }
111 
112  if (readCallback_ && data) {
115  } else {
116  folly::io::Cursor cursor(data.get());
117  size_t available = 0;
118  while ((available = cursor.totalLength()) != 0 && readCallback_) {
119  void* buf = nullptr;
120  size_t buflen = 0;
121  try {
122  readCallback_->getReadBuffer(&buf, &buflen);
123  } catch (const AsyncSocketException& ase) {
124  return deliverError(ase);
125  } catch (const std::exception& e) {
126  AsyncSocketException ase(
128  folly::to<std::string>("getReadBuffer() threw ", e.what()));
129  return deliverError(ase);
130  } catch (...) {
131  AsyncSocketException ase(
133  "getReadBuffer() threw unknown exception");
134  return deliverError(ase);
135  }
136  if (buflen == 0 || buf == nullptr) {
137  AsyncSocketException ase(
139  "getReadBuffer() returned empty buffer");
140  return deliverError(ase);
141  }
142 
143  size_t bytesToRead = std::min(buflen, available);
144  cursor.pull(buf, bytesToRead);
145  readCallback_->readDataAvailable(bytesToRead);
146  }
147  if (available != 0) {
148  cursor.clone(appDataBuf_, available);
149  }
150  }
151  } else if (data) {
153  }
154 
155  checkBufLen();
156 }
virtual void readBufferAvailable(std::unique_ptr< IOBuf >) noexcept
virtual void readDataAvailable(size_t len) noexcept=0
virtual void deliverError(const folly::AsyncSocketException &ex, bool closeTransport=true)
std::unique_ptr< folly::IOBuf > appDataBuf_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual bool isBufferMovable() noexcept
LogLevel min
Definition: LogLevel.cpp:30
virtual void getReadBuffer(void **bufReturn, size_t *lenReturn)=0
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
ReadCallback * readCallback_
void fizz::AsyncFizzBase::deliverError ( const folly::AsyncSocketException ex,
bool  closeTransport = true 
)
protectedvirtual

Definition at line 158 of file AsyncFizzBase.cpp.

References folly::AsyncSocketException::END_OF_FILE, folly::AsyncSocketException::getType(), readCallback_, folly::AsyncReader::ReadCallback::readEOF(), and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

Referenced by fizz::server::AsyncFizzServerT< SM >::deliverAllErrors(), fizz::client::AsyncFizzClientT< SM >::deliverAllErrors(), deliverAppData(), isDetachable(), and setReadCB().

160  {
161  DelayedDestruction::DestructorGuard dg(this);
162 
163  if (readCallback_) {
164  auto readCallback = readCallback_;
165  readCallback_ = nullptr;
167  readCallback->readEOF();
168  } else {
169  readCallback->readErr(ex);
170  }
171  }
172  if (closeTransport) {
173  transport_->close();
174  }
175 }
AsyncSocketExceptionType getType() const noexcept
virtual void readEOF() noexcept=0
ReadCallback * readCallback_
void fizz::AsyncFizzBase::destroy ( )
overridevirtual

Clean up transport on destruction

Reimplemented from folly::DelayedDestruction.

Definition at line 39 of file AsyncFizzBase.cpp.

References destroy(), and folly::DecoratedAsyncTransportWrapper< folly::AsyncTransportWrapper >::transport_.

39  {
40  transport_->closeNow();
41  transport_->setReadCB(nullptr);
43 }
static void destroy()
void fizz::AsyncFizzBase::detachEventBase ( )
inlineoverridevirtual

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.

Implements folly::AsyncTransport.

Definition at line 144 of file AsyncFizzBase.h.

References folly::AsyncTimeout::detachEventBase(), detachEventBase(), handshakeTimeout_, setReadCB(), and fizz::AsyncFizzBase::HandshakeTimeout::transport_.

Referenced by detachEventBase().

144  {
146  transport_->setReadCB(nullptr);
147  transport_->detachEventBase();
148  }
HandshakeTimeout handshakeTimeout_
void fizz::AsyncFizzBase::detachTimeoutManager ( )
inline

Definition at line 132 of file AsyncFizzBase.h.

References folly::AsyncTimeout::detachTimeoutManager(), and handshakeTimeout_.

132  {
134  }
HandshakeTimeout handshakeTimeout_
bool fizz::AsyncFizzBase::error ( ) const
overridepure virtual
size_t fizz::AsyncFizzBase::getAppBytesReceived ( ) const
overridevirtual

Implements folly::AsyncTransport.

Definition at line 84 of file AsyncFizzBase.cpp.

References appBytesReceived_.

84  {
85  return appBytesReceived_;
86 }
size_t fizz::AsyncFizzBase::getAppBytesWritten ( ) const
overridevirtual

App data usage accounting.

Implements folly::AsyncTransport.

Definition at line 80 of file AsyncFizzBase.cpp.

References appBytesWritten_.

80  {
81  return appBytesWritten_;
82 }
std::string fizz::AsyncFizzBase::getApplicationProtocol ( ) const
overridepure virtualnoexcept
folly::ssl::X509UniquePtr fizz::AsyncFizzBase::getPeerCert ( ) const
overridepure virtual
void fizz::AsyncFizzBase::getReadBuffer ( void **  bufReturn,
size_t *  lenReturn 
)
overrideprivatevirtual

ReadCallback implementation.

Implements folly::AsyncReader::ReadCallback.

Definition at line 177 of file AsyncFizzBase.cpp.

References folly::IOBufQueue::preallocate(), and transportReadBuf_.

177  {
178  std::pair<void*, uint32_t> readSpace =
180  *bufReturn = readSpace.first;
181  *lenReturn = readSpace.second;
182 }
folly::IOBufQueue transportReadBuf_
static const uint32_t kMaxReadSize
static const uint32_t kMinReadSize
std::pair< void *, std::size_t > preallocate(std::size_t min, std::size_t newAllocationSize, std::size_t max=std::numeric_limits< std::size_t >::max())
Definition: IOBufQueue.h:356
AsyncFizzBase::ReadCallback * fizz::AsyncFizzBase::getReadCallback ( ) const
overridevirtual

App level information for reading/writing app data.

Implements folly::AsyncTransportWrapper.

Definition at line 45 of file AsyncFizzBase.cpp.

References readCallback_.

Referenced by isDetachable().

45  {
46  return readCallback_;
47 }
ReadCallback * readCallback_
std::string fizz::AsyncFizzBase::getSecurityProtocol ( ) const
inlineoverridevirtual

Identify the transport as Fizz.

Reimplemented from folly::AsyncTransport.

Definition at line 122 of file AsyncFizzBase.h.

122  {
123  return "Fizz";
124  }
const X509* fizz::AsyncFizzBase::getSelfCert ( ) const
overridepure virtual
const Cert* fizz::AsyncFizzBase::getSelfCertificate ( ) const
overridepure virtual
bool fizz::AsyncFizzBase::good ( ) const
overridepure virtual
void fizz::AsyncFizzBase::handshakeTimeoutExpired ( )
privatenoexcept

Definition at line 230 of file AsyncFizzBase.cpp.

References folly::AsyncSocketException::TIMED_OUT, and transportError().

Referenced by fizz::AsyncFizzBase::HandshakeTimeout::timeoutExpired().

230  {
231  AsyncSocketException eof(
232  AsyncSocketException::TIMED_OUT, "handshake timeout expired");
233  transportError(eof);
234 }
virtual void transportError(const folly::AsyncSocketException &ex)=0
bool fizz::AsyncFizzBase::isBufferMovable ( )
overrideprivatevirtualnoexcept

When data becomes available, isBufferMovable() will be invoked to figure out which API will be used, readBufferAvailable() or readDataAvailable(). If isBufferMovable() returns true, that means ReadCallback supports the IOBuf ownership transfer and readBufferAvailable() will be used. Otherwise, not.

By default, isBufferMovable() always return false. If readBufferAvailable() is implemented and to be invoked, You should overwrite isBufferMovable() and return true in the inherited class.

This method allows the AsyncSocket/AsyncSSLSocket do buffer allocation by itself until data becomes available. Compared with the pre/post buffer allocation in getReadBuffer()/readDataAvailabe(), readBufferAvailable() has two advantages. First, this can avoid memcpy. E.g., in AsyncSSLSocket, the decrypted data was copied from the openssl internal buffer to the readbuf buffer. With the buffer ownership transfer, the internal buffer can be directly "moved" to ReadCallback. Second, the memory allocation can be more precise. The reason is AsyncSocket/AsyncSSLSocket can allocate the memory of precise size because they have more context about the available data than ReadCallback. Think about the getReadBuffer() pre-allocate 4072 bytes buffer, but the available data is always 16KB (max OpenSSL record size).

Reimplemented from folly::AsyncReader::ReadCallback.

Definition at line 192 of file AsyncFizzBase.cpp.

192  {
193  return true;
194 }
bool fizz::AsyncFizzBase::isDetachable ( ) const
inlineoverridevirtual

Determine if the transport can be detached.

This method must be called from the current EventBase's thread.

Implements folly::AsyncTransport.

Reimplemented in fizz::server::AsyncFizzServerT< SM >, and fizz::server::AsyncFizzServerT< fizz::server::test::MockServerStateMachineInstance >.

Definition at line 149 of file AsyncFizzBase.h.

References cancelHandshakeTimeout(), deliverAppData(), deliverError(), getReadCallback(), handshakeTimeout_, isDetachable(), folly::AsyncTimeout::isScheduled(), folly::NONE, setReadCB(), startHandshakeTimeout(), startTransportReads(), fizz::AsyncFizzBase::HandshakeTimeout::transport_, transportDataAvailable(), transportError(), and writeAppData().

Referenced by fizz::server::AsyncFizzServerT< SM >::isDetachable(), and isDetachable().

149  {
151  return false;
152  }
153  // Since we always have a read callback on the underlying transport,
154  // transport_->isDetachable() would always return false. We need to see if
155  // the transport is detachable independent of our callback.
156  auto readCb = transport_->getReadCallback();
157  transport_->setReadCB(nullptr);
158  auto result = transport_->isDetachable();
159  transport_->setReadCB(readCb);
160  return result;
161  }
HandshakeTimeout handshakeTimeout_
bool isScheduled() const
bool fizz::AsyncFizzBase::isReplaySafe ( ) const
overridepure virtual
bool fizz::AsyncFizzBase::readable ( ) const
overridepure virtual
void fizz::AsyncFizzBase::readBufferAvailable ( std::unique_ptr< folly::IOBuf )
overrideprivatevirtualnoexcept

readBufferAvailable() will be invoked when data has been successfully read.

Note that only either readBufferAvailable() or readDataAvailable() will be invoked according to the return value of isBufferMovable(). The timing and aftereffect of readBufferAvailable() are the same as readDataAvailable()

Parameters
readBufThe unique pointer of read buffer.

Reimplemented from folly::AsyncReader::ReadCallback.

Definition at line 196 of file AsyncFizzBase.cpp.

References folly::IOBufQueue::append(), checkBufLen(), data, folly::gen::move, transportDataAvailable(), and transportReadBuf_.

197  {
198  DelayedDestruction::DestructorGuard dg(this);
199 
202  checkBufLen();
203 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
folly::IOBufQueue transportReadBuf_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void transportDataAvailable()=0
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
void fizz::AsyncFizzBase::readDataAvailable ( size_t  len)
overrideprivatevirtualnoexcept

readDataAvailable() will be invoked when data has been successfully read into the buffer returned by the last call to getReadBuffer().

The read callback remains installed after readDataAvailable() returns. It must be explicitly uninstalled to stop receiving read events. getReadBuffer() will be called at least once before each call to readDataAvailable(). getReadBuffer() will also be called before any call to readEOF().

Parameters
lenThe number of bytes placed in the buffer.

Implements folly::AsyncReader::ReadCallback.

Definition at line 184 of file AsyncFizzBase.cpp.

References checkBufLen(), folly::IOBufQueue::postallocate(), transportDataAvailable(), and transportReadBuf_.

184  {
185  DelayedDestruction::DestructorGuard dg(this);
186 
189  checkBufLen();
190 }
folly::IOBufQueue transportReadBuf_
void postallocate(std::size_t n)
Definition: IOBufQueue.h:380
virtual void transportDataAvailable()=0
void fizz::AsyncFizzBase::readEOF ( )
overrideprivatevirtualnoexcept

readEOF() will be invoked when the transport is closed.

The read callback will be automatically uninstalled immediately before readEOF() is invoked.

Implements folly::AsyncReader::ReadCallback.

Definition at line 205 of file AsyncFizzBase.cpp.

References folly::AsyncSocketException::END_OF_FILE, and transportError().

205  {
206  AsyncSocketException eof(AsyncSocketException::END_OF_FILE, "readEOF()");
207  transportError(eof);
208 }
virtual void transportError(const folly::AsyncSocketException &ex)=0
void fizz::AsyncFizzBase::readErr ( const folly::AsyncSocketException ex)
overrideprivatevirtualnoexcept

readError() will be invoked if an error occurs reading from the transport.

The read callback will be automatically uninstalled immediately before readError() is invoked.

Parameters
exAn exception describing the error that occurred.

Implements folly::AsyncReader::ReadCallback.

Definition at line 210 of file AsyncFizzBase.cpp.

References transportError().

210  {
211  transportError(ex);
212 }
virtual void transportError(const folly::AsyncSocketException &ex)=0
void fizz::AsyncFizzBase::setReadCB ( AsyncFizzBase::ReadCallback callback)
overridevirtual

Implements folly::AsyncTransportWrapper.

Definition at line 49 of file AsyncFizzBase.cpp.

References appDataBuf_, deliverAppData(), deliverError(), good(), folly::AsyncSocketException::NOT_OPEN, readCallback_, and startTransportReads().

Referenced by detachEventBase(), and isDetachable().

49  {
50  readCallback_ = callback;
51 
52  if (readCallback_) {
53  if (appDataBuf_) {
54  deliverAppData(nullptr);
55  }
56 
57  if (!good()) {
58  AsyncSocketException ex(
60  "setReadCB() called with transport in bad state");
61  deliverError(ex);
62  } else {
63  // The read callback may have been unset earlier if our buffer was full.
65  }
66  }
67 }
virtual void deliverError(const folly::AsyncSocketException &ex, bool closeTransport=true)
std::unique_ptr< folly::IOBuf > appDataBuf_
bool good() const override=0
virtual void startTransportReads()
ReadCallback * readCallback_
virtual void deliverAppData(std::unique_ptr< folly::IOBuf > buf)
void fizz::AsyncFizzBase::setReplaySafetyCallback ( folly::AsyncTransport::ReplaySafetyCallback callback)
overridepure virtual
void fizz::AsyncFizzBase::startHandshakeTimeout ( std::chrono::milliseconds  timeout)
protectedvirtual

Interface for the derived class to schedule a handshake timeout.

transportError() will be called if the timeout fires before it is cancelled.

Definition at line 92 of file AsyncFizzBase.cpp.

References handshakeTimeout_, and folly::AsyncTimeout::scheduleTimeout().

Referenced by fizz::client::AsyncFizzClientT< SM >::connect(), and isDetachable().

92  {
94 }
HandshakeTimeout handshakeTimeout_
bool scheduleTimeout(uint32_t milliseconds)
void fizz::AsyncFizzBase::startTransportReads ( )
protectedvirtual
virtual void fizz::AsyncFizzBase::transportDataAvailable ( )
protectedpure virtual
void fizz::AsyncFizzBase::writeChain ( folly::AsyncTransportWrapper::WriteCallback callback,
std::unique_ptr< folly::IOBuf > &&  buf,
folly::WriteFlags  flags = folly::WriteFlags::NONE 
)
overridevirtual

It only makes sense to use this class if you override writeChain, so force derived classes to do that.

Implements folly::WriteChainAsyncTransportWrapper< folly::AsyncTransportWrapper >.

Definition at line 69 of file AsyncFizzBase.cpp.

References appBytesWritten_, folly::gen::move, and writeAppData().

72  {
74 
75  // TODO: break up buf into multiple records
76 
77  writeAppData(callback, std::move(buf), flags);
78 }
flags
Definition: http_parser.h:127
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
virtual void writeAppData(folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE)=0
void fizz::AsyncFizzBase::writeErr ( size_t  bytesWritten,
const folly::AsyncSocketException ex 
)
overrideprivatevirtualnoexcept

writeError() will be invoked if an error occurs writing the data.

Parameters
bytesWrittenThe number of bytes that were successfull
exAn exception describing the error that occurred.

Implements folly::AsyncWriter::WriteCallback.

Definition at line 216 of file AsyncFizzBase.cpp.

References transportError().

218  {
219  transportError(ex);
220 }
virtual void transportError(const folly::AsyncSocketException &ex)=0
void fizz::AsyncFizzBase::writeSuccess ( )
overrideprivatevirtualnoexcept

WriteCallback implementation, for use with handshake messages.

Implements folly::AsyncWriter::WriteCallback.

Definition at line 214 of file AsyncFizzBase.cpp.

214 {}

Member Data Documentation

size_t fizz::AsyncFizzBase::appBytesReceived_ {0}
private

Definition at line 236 of file AsyncFizzBase.h.

Referenced by deliverAppData(), and getAppBytesReceived().

size_t fizz::AsyncFizzBase::appBytesWritten_ {0}
private

Definition at line 235 of file AsyncFizzBase.h.

Referenced by getAppBytesWritten(), and writeChain().

std::unique_ptr<folly::IOBuf> fizz::AsyncFizzBase::appDataBuf_
private

Definition at line 233 of file AsyncFizzBase.h.

Referenced by checkBufLen(), deliverAppData(), and setReadCB().

ReadCallback* fizz::AsyncFizzBase::readCallback_ {nullptr}
private
folly::IOBufQueue fizz::AsyncFizzBase::transportReadBuf_ {folly::IOBufQueue::cacheChainLength()}
protected

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