proxygen
|
#include <TestAsyncTransport.h>
Classes | |
class | ReadEvent |
class | WriteEvent |
Public Member Functions | |
TestAsyncTransport (folly::EventBase *eventBase) | |
void | setReadCB (AsyncTransportWrapper::ReadCallback *callback) override |
ReadCallback * | getReadCallback () const override |
void | write (AsyncTransportWrapper::WriteCallback *callback, const void *buf, size_t bytes, folly::WriteFlags flags=folly::WriteFlags::NONE) override |
void | writev (AsyncTransportWrapper::WriteCallback *callback, const struct iovec *vec, size_t count, folly::WriteFlags flags=folly::WriteFlags::NONE) override |
void | writeChain (AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&iob, folly::WriteFlags flags=folly::WriteFlags::NONE) override |
void | close () override |
void | closeNow () override |
void | shutdownWrite () override |
void | shutdownWriteNow () override |
void | getPeerAddress (folly::SocketAddress *addr) const override |
void | getLocalAddress (folly::SocketAddress *addr) const override |
bool | good () const override |
bool | readable () const override |
bool | connecting () const override |
bool | error () const override |
void | attachEventBase (folly::EventBase *eventBase) override |
void | detachEventBase () override |
bool | isDetachable () const override |
folly::EventBase * | getEventBase () const override |
void | setSendTimeout (uint32_t milliseconds) override |
uint32_t | getSendTimeout () const override |
void | addReadEvent (const void *buf, size_t buflen, std::chrono::milliseconds delayFromPrevious) |
void | addReadEvent (folly::IOBufQueue &chain, std::chrono::milliseconds delayFromPrevious) |
void | addReadEvent (const char *buf, std::chrono::milliseconds delayFromPrevious=std::chrono::milliseconds(0)) |
void | addReadEOF (std::chrono::milliseconds delayFromPrevious) |
void | addReadError (const folly::AsyncSocketException &ex, std::chrono::milliseconds delayFromPrevious) |
void | startReadEvents () |
void | pauseWrites () |
void | resumeWrites () |
std::deque< std::shared_ptr< WriteEvent > > * | getWriteEvents () |
uint32_t | getEORCount () |
uint32_t | getCorkCount () |
size_t | getAppBytesWritten () const override |
size_t | getRawBytesWritten () const override |
size_t | getAppBytesReceived () const override |
size_t | getRawBytesReceived () const override |
bool | isEorTrackingEnabled () const override |
void | setEorTracking (bool) override |
Public Member Functions inherited from folly::AsyncTransportWrapper | |
void | setReadCB (ReadCallback *callback) override=0 |
void | write (WriteCallback *callback, const void *buf, size_t bytes, WriteFlags flags=WriteFlags::NONE) override=0 |
void | writev (WriteCallback *callback, const iovec *vec, size_t count, WriteFlags flags=WriteFlags::NONE) override=0 |
void | writeChain (WriteCallback *callback, std::unique_ptr< IOBuf > &&buf, WriteFlags flags=WriteFlags::NONE) override=0 |
virtual const AsyncTransportWrapper * | getWrappedTransport () const |
template<class T > | |
const T * | getUnderlyingTransport () const |
template<class T > | |
T * | getUnderlyingTransport () |
Public Member Functions inherited from folly::AsyncTransport | |
virtual void | closeWithReset () |
virtual bool | writable () const |
virtual bool | isPending () const |
SocketAddress | getLocalAddress () const |
void | getAddress (SocketAddress *address) const override |
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 | 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 | ~AsyncSocketBase ()=default |
Private Types | |
enum | StateEnum { kStateOpen, kStatePaused, kStateClosed, kStateError } |
Private Types inherited from folly::AsyncTimeout | |
typedef TimeoutManager::InternalEnum | InternalEnum |
Private Attributes | |
folly::EventBase * | eventBase_ |
folly::AsyncTransportWrapper::ReadCallback * | readCallback_ |
uint32_t | sendTimeout_ |
proxygen::TimePoint | prevReadEventTime_ {} |
proxygen::TimePoint | nextReadEventTime_ {} |
StateEnum | readState_ |
StateEnum | writeState_ |
std::deque< std::shared_ptr< ReadEvent > > | readEvents_ |
std::deque< std::shared_ptr< WriteEvent > > | writeEvents_ |
std::deque< std::pair< std::shared_ptr< WriteEvent >, AsyncTransportWrapper::WriteCallback * > > | pendingWriteEvents_ |
uint32_t | eorCount_ {0} |
uint32_t | corkCount_ {0} |
Additional Inherited Members | |
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, Destructor > | UniquePtr |
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 |
Static Private Member Functions inherited from folly::AsyncTimeout | |
template<typename TCallback > | |
static std::unique_ptr< AsyncTimeout > | make (TimeoutManager &manager, TCallback &&callback) |
template<typename TCallback > | |
static std::unique_ptr< AsyncTimeout > | schedule (TimeoutManager::timeout_type timeout, TimeoutManager &manager, TCallback &&callback) |
Definition at line 19 of file TestAsyncTransport.h.
|
private |
Enumerator | |
---|---|
kStateOpen | |
kStatePaused | |
kStateClosed | |
kStateError |
Definition at line 121 of file TestAsyncTransport.h.
|
explicit |
Definition at line 168 of file TestAsyncTransport.cpp.
Referenced by writesAllowed().
|
private |
void TestAsyncTransport::addReadEOF | ( | std::chrono::milliseconds | delayFromPrevious | ) |
Definition at line 455 of file TestAsyncTransport.cpp.
References addReadEvent().
void TestAsyncTransport::addReadError | ( | const folly::AsyncSocketException & | ex, |
std::chrono::milliseconds | delayFromPrevious | ||
) |
Definition at line 460 of file TestAsyncTransport.cpp.
References addReadEvent(), and readEvents_.
void TestAsyncTransport::addReadEvent | ( | const void * | buf, |
size_t | buflen, | ||
std::chrono::milliseconds | delayFromPrevious | ||
) |
Definition at line 438 of file TestAsyncTransport.cpp.
References readEvents_.
Referenced by addReadEOF(), addReadError(), addReadEvent(), and writesAllowed().
void TestAsyncTransport::addReadEvent | ( | folly::IOBufQueue & | chain, |
std::chrono::milliseconds | delayFromPrevious | ||
) |
Definition at line 426 of file TestAsyncTransport.cpp.
References addReadEvent(), folly::IOBuf::data(), folly::IOBuf::length(), and folly::IOBufQueue::pop_front().
void TestAsyncTransport::addReadEvent | ( | const char * | buf, |
std::chrono::milliseconds | delayFromPrevious = std::chrono::milliseconds(0) |
||
) |
Definition at line 449 of file TestAsyncTransport.cpp.
References addReadEvent().
|
private |
Definition at line 471 of file TestAsyncTransport.cpp.
References proxygen::getCurrentTime(), nextReadEventTime_, prevReadEventTime_, readCallback_, readEvents_, scheduleNextReadEvent(), and proxygen::timePointInitialized().
|
overridevirtual |
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.
Definition at line 351 of file TestAsyncTransport.cpp.
References eventBase_, and readCallback_.
|
overridevirtual |
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.
Implements folly::AsyncTransport.
Definition at line 285 of file TestAsyncTransport.cpp.
References closeNow().
|
overridevirtual |
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.
Implements folly::AsyncTransport.
Definition at line 290 of file TestAsyncTransport.cpp.
References kStateClosed, kStateOpen, readCallback_, folly::AsyncReader::ReadCallback::readEOF(), readState_, and shutdownWriteNow().
Referenced by close().
|
overridevirtual |
Determine if transport is connected to the endpoint
Implements folly::AsyncTransport.
Definition at line 341 of file TestAsyncTransport.cpp.
|
overridevirtual |
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 358 of file TestAsyncTransport.cpp.
References eventBase_, and readCallback_.
|
overridevirtual |
Determine if an error has occurred with this transport.
Implements folly::AsyncTransport.
Definition at line 346 of file TestAsyncTransport.cpp.
References kStateError, readState_, and writeState_.
|
private |
Definition at line 410 of file TestAsyncTransport.cpp.
References g(), pendingWriteEvents_, and folly::AsyncWriter::WriteCallback::writeErr().
Referenced by shutdownWriteNow(), and writesAllowed().
|
private |
Definition at line 518 of file TestAsyncTransport.cpp.
References folly::netops::bind(), eventBase_, fireOneReadEvent(), proxygen::getCurrentTime(), nextReadEventTime_, now(), readCallback_, readEvents_, folly::EventBase::runInLoop(), folly::AsyncTimeout::scheduleTimeout(), and proxygen::timePointInitialized().
Referenced by scheduleNextReadEvent(), timeoutExpired(), and writesAllowed().
|
private |
Definition at line 547 of file TestAsyncTransport.cpp.
References folly::AsyncReader::ReadCallback::getReadBuffer(), kStateClosed, kStateError, nextReadEventTime_, prevReadEventTime_, readCallback_, folly::AsyncReader::ReadCallback::readDataAvailable(), folly::AsyncReader::ReadCallback::readEOF(), folly::AsyncReader::ReadCallback::readErr(), readEvents_, readState_, and writeState_.
Referenced by fireNextReadEvent(), and writesAllowed().
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 115 of file TestAsyncTransport.h.
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 113 of file TestAsyncTransport.h.
|
inline |
|
inline |
|
overridevirtual |
Implements folly::AsyncSocketBase.
Definition at line 370 of file TestAsyncTransport.cpp.
References eventBase_.
|
overridevirtual |
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. |
Implements folly::AsyncTransport.
Definition at line 325 of file TestAsyncTransport.cpp.
References folly::SocketAddress::setFromIpPort().
|
overridevirtual |
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. |
Implements folly::AsyncTransport.
Definition at line 319 of file TestAsyncTransport.cpp.
References folly::SocketAddress::setFromIpPort().
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 116 of file TestAsyncTransport.h.
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 114 of file TestAsyncTransport.h.
|
overridevirtual |
Implements folly::AsyncTransportWrapper.
Definition at line 225 of file TestAsyncTransport.cpp.
References readCallback_.
|
overridevirtual |
Get the send timeout.
Implements folly::AsyncTransport.
Definition at line 380 of file TestAsyncTransport.cpp.
References sendTimeout_.
|
inline |
Definition at line 101 of file TestAsyncTransport.h.
References writeEvents_.
|
overridevirtual |
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.
Implements folly::AsyncTransport.
Definition at line 331 of file TestAsyncTransport.cpp.
References kStateOpen, readState_, and writesAllowed().
|
overridevirtual |
Determine if the transport can be detached.
This method must be called from the current EventBase's thread.
Implements folly::AsyncTransport.
Definition at line 365 of file TestAsyncTransport.cpp.
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 117 of file TestAsyncTransport.h.
|
private |
Referenced by writesAllowed().
void TestAsyncTransport::pauseWrites | ( | ) |
Definition at line 385 of file TestAsyncTransport.cpp.
References kStateOpen, kStatePaused, and writeState_.
|
overridevirtual |
Determine if the transport is readable or not.
Implements folly::AsyncTransport.
Definition at line 336 of file TestAsyncTransport.cpp.
void TestAsyncTransport::resumeWrites | ( | ) |
Definition at line 394 of file TestAsyncTransport.cpp.
References kStateOpen, kStatePaused, pendingWriteEvents_, writeEvents_, and writeState_.
|
private |
Definition at line 508 of file TestAsyncTransport.cpp.
References fireNextReadEvent(), nextReadEventTime_, and folly::AsyncTimeout::scheduleTimeout().
Referenced by addReadEvent(), setReadCB(), startReadEvents(), and writesAllowed().
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 118 of file TestAsyncTransport.h.
|
override |
Definition at line 180 of file TestAsyncTransport.cpp.
References folly::AsyncTimeout::cancelTimeout(), proxygen::getCurrentTime(), kStateClosed, kStateError, kStateOpen, nextReadEventTime_, folly::AsyncSocketException::NOT_OPEN, readCallback_, folly::AsyncReader::ReadCallback::readEOF(), readEvents_, readState_, scheduleNextReadEvent(), and proxygen::timePointInitialized().
|
overridevirtual |
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. |
Implements folly::AsyncTransport.
Definition at line 375 of file TestAsyncTransport.cpp.
References sendTimeout_, and uint32_t.
|
overridevirtual |
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.)
Implements folly::AsyncTransport.
Definition at line 304 of file TestAsyncTransport.cpp.
References shutdownWriteNow().
|
overridevirtual |
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.
Implements folly::AsyncTransport.
Definition at line 309 of file TestAsyncTransport.cpp.
References failPendingWrites(), g(), kStateClosed, kStateOpen, kStatePaused, and writeState_.
Referenced by closeNow(), and shutdownWrite().
void TestAsyncTransport::startReadEvents | ( | ) |
Definition at line 491 of file TestAsyncTransport.cpp.
References proxygen::getCurrentTime(), nextReadEventTime_, now(), prevReadEventTime_, readCallback_, readEvents_, and scheduleNextReadEvent().
|
overrideprivatevirtualnoexcept |
timeoutExpired() is invoked when the timeout period has expired.
Implements folly::AsyncTimeout.
Definition at line 636 of file TestAsyncTransport.cpp.
References fireNextReadEvent(), readCallback_, and readEvents_.
Referenced by writesAllowed().
|
override |
Definition at line 230 of file TestAsyncTransport.cpp.
References writev().
|
override |
Definition at line 268 of file TestAsyncTransport.cpp.
References count, folly::IOBuf::data(), i, folly::IOBuf::length(), cpp.ast::next(), folly::IOBuf::next(), uint8_t, and writev().
|
inlineprivate |
Definition at line 130 of file TestAsyncTransport.h.
References addReadEvent(), failPendingWrites(), fireNextReadEvent(), fireOneReadEvent(), kStateOpen, kStatePaused, folly::pushmi::__adl::noexcept(), now(), operator=(), scheduleNextReadEvent(), TestAsyncTransport(), timeoutExpired(), and writeState_.
Referenced by good(), and writev().
|
override |
Definition at line 240 of file TestAsyncTransport.cpp.
References corkCount_, eorCount_, folly::isSet(), kStateOpen, kStatePaused, TestAsyncTransport::WriteEvent::newEvent(), pendingWriteEvents_, writeEvents_, writesAllowed(), and writeState_.
Referenced by write(), and writeChain().
|
private |
Definition at line 160 of file TestAsyncTransport.h.
Referenced by getCorkCount(), and writev().
|
private |
Definition at line 159 of file TestAsyncTransport.h.
Referenced by getEORCount(), and writev().
|
private |
Definition at line 146 of file TestAsyncTransport.h.
Referenced by attachEventBase(), detachEventBase(), fireNextReadEvent(), and getEventBase().
|
private |
Definition at line 151 of file TestAsyncTransport.h.
Referenced by addReadEvent(), fireNextReadEvent(), fireOneReadEvent(), scheduleNextReadEvent(), setReadCB(), and startReadEvents().
|
private |
Definition at line 157 of file TestAsyncTransport.h.
Referenced by failPendingWrites(), resumeWrites(), and writev().
|
private |
Definition at line 150 of file TestAsyncTransport.h.
Referenced by addReadEvent(), fireOneReadEvent(), and startReadEvents().
|
private |
Definition at line 147 of file TestAsyncTransport.h.
Referenced by addReadEvent(), attachEventBase(), closeNow(), detachEventBase(), fireNextReadEvent(), fireOneReadEvent(), getReadCallback(), setReadCB(), startReadEvents(), and timeoutExpired().
|
private |
Definition at line 154 of file TestAsyncTransport.h.
Referenced by addReadError(), addReadEvent(), fireNextReadEvent(), fireOneReadEvent(), setReadCB(), startReadEvents(), and timeoutExpired().
|
private |
Definition at line 152 of file TestAsyncTransport.h.
Referenced by closeNow(), error(), fireOneReadEvent(), good(), and setReadCB().
|
private |
Definition at line 148 of file TestAsyncTransport.h.
Referenced by getSendTimeout(), and setSendTimeout().
|
private |
Definition at line 155 of file TestAsyncTransport.h.
Referenced by getWriteEvents(), resumeWrites(), and writev().
|
private |
Definition at line 153 of file TestAsyncTransport.h.
Referenced by error(), fireOneReadEvent(), pauseWrites(), resumeWrites(), shutdownWriteNow(), writesAllowed(), and writev().