proxygen
fizz::test::LocalTransport Class Reference

#include <LocalTransport.h>

Inheritance diagram for fizz::test::LocalTransport:
folly::AsyncTransportWrapper folly::AsyncTransport folly::AsyncReader folly::AsyncWriter folly::DelayedDestruction folly::AsyncSocketBase folly::DelayedDestructionBase

Public Types

using UniquePtr = std::unique_ptr< LocalTransport, Destructor >
 
- 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

void setTrickle (bool trickle, folly::Function< void()> callback=nullptr)
 
void setPeer (LocalTransport *peer)
 
void receiveData (std::unique_ptr< folly::IOBuf > buf)
 
ReadCallbackgetReadCallback () const override
 
void setReadCB (ReadCallback *callback) override
 
void write (WriteCallback *, const void *, size_t, folly::WriteFlags=folly::WriteFlags::NONE) override
 
void writeChain (WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags=folly::WriteFlags::NONE) override
 
void writev (WriteCallback *, const iovec *, size_t, folly::WriteFlags=folly::WriteFlags::NONE) 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 *) const override
 
void getPeerAddress (folly::SocketAddress *) 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
 
void setEorTracking (bool) override
 
void setSendTimeout (uint32_t) override
 
void shutdownWrite () override
 
void shutdownWriteNow () override
 
- Public Member Functions inherited from folly::AsyncTransportWrapper
virtual const AsyncTransportWrappergetWrappedTransport () const
 
template<class T >
const TgetUnderlyingTransport () const
 
template<class T >
TgetUnderlyingTransport ()
 
- Public Member Functions inherited from folly::AsyncTransport
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 AsyncTransportCertificategetPeerCertificate () const
 
virtual const AsyncTransportCertificategetSelfCertificate () 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 Member Functions

void deliverData ()
 

Private Attributes

LocalTransportpeer_ {nullptr}
 
folly::EventBaseevb_ {nullptr}
 
size_t received_ {0}
 
size_t written_ {0}
 
folly::IOBufQueue readBuf_ {folly::IOBufQueue::cacheChainLength()}
 
ReadCallbackcallback_ {nullptr}
 
bool trickle_ {false}
 
folly::Function< void()> trickleCallback_
 

Additional Inherited Members

- 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
 

Detailed Description

Definition at line 16 of file LocalTransport.h.

Member Typedef Documentation

Definition at line 18 of file LocalTransport.h.

Member Function Documentation

void fizz::test::LocalTransport::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.

Definition at line 85 of file LocalTransport.h.

References evb_.

85  {
86  evb_ = eventBase;
87  }
folly::EventBase * evb_
void fizz::test::LocalTransport::close ( )
inlineoverridevirtual

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 89 of file LocalTransport.h.

89 {}
void fizz::test::LocalTransport::closeNow ( )
inlineoverridevirtual

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 91 of file LocalTransport.h.

91 {}
void fizz::test::LocalTransport::closeWithReset ( )
inlineoverridevirtual

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 from folly::AsyncTransport.

Definition at line 93 of file LocalTransport.h.

93 {}
bool fizz::test::LocalTransport::connecting ( ) const
inlineoverridevirtual

Determine if transport is connected to the endpoint

Returns
false iff the transport is connected, otherwise true

Implements folly::AsyncTransport.

Definition at line 95 of file LocalTransport.h.

95  {
96  return false;
97  }
void fizz::test::LocalTransport::deliverData ( )
inlineprivate

Definition at line 156 of file LocalTransport.h.

References callback_, folly::IOBufQueue::empty(), folly::IOBufQueue::move(), readBuf_, folly::AsyncReader::ReadCallback::readBufferAvailable(), folly::IOBufQueue::split(), trickle_, and trickleCallback_.

Referenced by receiveData(), and setReadCB().

156  {
157  while (callback_ && !readBuf_.empty()) {
158  if (!trickle_) {
160  } else {
161  if (trickleCallback_) {
163  }
165  }
166  }
167  }
virtual void readBufferAvailable(std::unique_ptr< IOBuf >) noexcept
std::unique_ptr< folly::IOBuf > split(size_t n)
Definition: IOBufQueue.h:420
folly::IOBufQueue readBuf_
bool empty() const
Definition: IOBufQueue.h:503
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
folly::Function< void()> trickleCallback_
void fizz::test::LocalTransport::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 99 of file LocalTransport.h.

References evb_.

99  {
100  evb_ = nullptr;
101  }
folly::EventBase * evb_
bool fizz::test::LocalTransport::error ( ) const
inlineoverridevirtual

Determine if an error has occurred with this transport.

Returns
true iff an error has occurred (not EOF).

Implements folly::AsyncTransport.

Definition at line 103 of file LocalTransport.h.

103  {
104  return false;
105  }
size_t fizz::test::LocalTransport::getAppBytesReceived ( ) const
inlineoverridevirtual

Implements folly::AsyncTransport.

Definition at line 107 of file LocalTransport.h.

References received_.

107  {
108  return received_;
109  }
size_t fizz::test::LocalTransport::getAppBytesWritten ( ) const
inlineoverridevirtual

Implements folly::AsyncTransport.

Definition at line 111 of file LocalTransport.h.

References written_.

111  {
112  return written_;
113  }
folly::EventBase* fizz::test::LocalTransport::getEventBase ( ) const
inlineoverridevirtual

Implements folly::AsyncSocketBase.

Definition at line 81 of file LocalTransport.h.

References evb_.

81  {
82  return evb_;
83  }
folly::EventBase * evb_
void fizz::test::LocalTransport::getLocalAddress ( folly::SocketAddress address) const
inlineoverridevirtual

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.

Implements folly::AsyncTransport.

Definition at line 115 of file LocalTransport.h.

115 {}
void fizz::test::LocalTransport::getPeerAddress ( folly::SocketAddress address) const
inlineoverridevirtual

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.

Implements folly::AsyncTransport.

Definition at line 117 of file LocalTransport.h.

117 {}
size_t fizz::test::LocalTransport::getRawBytesReceived ( ) const
inlineoverridevirtual

Implements folly::AsyncTransport.

Definition at line 119 of file LocalTransport.h.

References received_.

119  {
120  return received_;
121  }
size_t fizz::test::LocalTransport::getRawBytesWritten ( ) const
inlineoverridevirtual

Implements folly::AsyncTransport.

Definition at line 123 of file LocalTransport.h.

References written_.

123  {
124  return written_;
125  }
ReadCallback* fizz::test::LocalTransport::getReadCallback ( ) const
inlineoverridevirtual

Implements folly::AsyncTransportWrapper.

Definition at line 42 of file LocalTransport.h.

References callback_.

42  {
43  return callback_;
44  }
uint32_t fizz::test::LocalTransport::getSendTimeout ( ) const
inlineoverridevirtual

Get the send timeout.

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

Implements folly::AsyncTransport.

Definition at line 127 of file LocalTransport.h.

127  {
128  return 0;
129  }
bool fizz::test::LocalTransport::good ( ) const
inlineoverridevirtual

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.

Returns
true iff the transport is open and ready, false otherwise.

Implements folly::AsyncTransport.

Definition at line 131 of file LocalTransport.h.

131  {
132  return true;
133  }
bool fizz::test::LocalTransport::isDetachable ( ) const
inlineoverridevirtual

Determine if the transport can be detached.

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

Implements folly::AsyncTransport.

Definition at line 135 of file LocalTransport.h.

135  {
136  return true;
137  }
bool fizz::test::LocalTransport::isEorTrackingEnabled ( ) const
inlineoverridevirtual
Returns
True iff end of record tracking is enabled

Implements folly::AsyncTransport.

Definition at line 139 of file LocalTransport.h.

139  {
140  return false;
141  }
bool fizz::test::LocalTransport::readable ( ) const
inlineoverridevirtual

Determine if the transport is readable or not.

Returns
true iff the transport is readable, false otherwise.

Implements folly::AsyncTransport.

Definition at line 143 of file LocalTransport.h.

143  {
144  return true;
145  }
void fizz::test::LocalTransport::receiveData ( std::unique_ptr< folly::IOBuf buf)
inline

Definition at line 36 of file LocalTransport.h.

References folly::IOBufQueue::append(), folly::IOBuf::computeChainDataLength(), deliverData(), folly::gen::move, readBuf_, and received_.

Referenced by writeChain().

36  {
39  deliverData();
40  }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
folly::IOBufQueue readBuf_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
void fizz::test::LocalTransport::setEorTracking ( bool  )
inlineoverridevirtual

Implements folly::AsyncTransport.

Definition at line 147 of file LocalTransport.h.

147 {}
void fizz::test::LocalTransport::setPeer ( LocalTransport peer)
inline

Definition at line 32 of file LocalTransport.h.

References peer_.

32  {
33  peer_ = peer;
34  }
void fizz::test::LocalTransport::setReadCB ( ReadCallback callback)
inlineoverridevirtual

Implements folly::AsyncTransportWrapper.

Definition at line 46 of file LocalTransport.h.

References callback_, deliverData(), and folly::AsyncReader::ReadCallback::isBufferMovable().

46  {
47  callback_ = callback;
48  if (callback_) {
49  CHECK(callback->isBufferMovable());
50  deliverData();
51  }
52  }
void fizz::test::LocalTransport::setSendTimeout ( uint32_t  milliseconds)
inlineoverridevirtual

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.

Implements folly::AsyncTransport.

Definition at line 149 of file LocalTransport.h.

149 {}
void fizz::test::LocalTransport::setTrickle ( bool  trickle,
folly::Function< void()>  callback = nullptr 
)
inline

Deliver the data one byte at a time. Callback will be invoked before delivering each byte.

Note that this does not affect how data within encrypted records is delivered after decryption.

Definition at line 27 of file LocalTransport.h.

References folly::gen::move, trickle_, and trickleCallback_.

27  {
28  trickle_ = trickle;
29  trickleCallback_ = std::move(callback);
30  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Function< void()> trickleCallback_
void fizz::test::LocalTransport::shutdownWrite ( )
inlineoverridevirtual

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 151 of file LocalTransport.h.

151 {}
void fizz::test::LocalTransport::shutdownWriteNow ( )
inlineoverridevirtual

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 153 of file LocalTransport.h.

153 {}
void fizz::test::LocalTransport::write ( WriteCallback callback,
const void *  buf,
size_t  bytes,
folly::WriteFlags  flags = folly::WriteFlags::NONE 
)
inlineoverridevirtual

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.

Implements folly::AsyncTransportWrapper.

Definition at line 54 of file LocalTransport.h.

References folly::FATAL.

58  {
59  LOG(FATAL) << "only writeChain() supported";
60  }
void fizz::test::LocalTransport::writeChain ( WriteCallback callback,
std::unique_ptr< folly::IOBuf > &&  buf,
folly::WriteFlags  flags = folly::WriteFlags::NONE 
)
inlineoverridevirtual

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.

Implements folly::AsyncTransportWrapper.

Definition at line 62 of file LocalTransport.h.

References folly::gen::move, peer_, receiveData(), folly::AsyncWriter::WriteCallback::writeSuccess(), and written_.

65  {
68  if (callback) {
69  callback->writeSuccess();
70  }
71  }
void writeSuccess() noexceptoverride
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void receiveData(std::unique_ptr< folly::IOBuf > buf)
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
void fizz::test::LocalTransport::writev ( WriteCallback callback,
const iovec *  vec,
size_t  count,
folly::WriteFlags  flags = folly::WriteFlags::NONE 
)
inlineoverridevirtual

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.

Implements folly::AsyncTransportWrapper.

Definition at line 73 of file LocalTransport.h.

References folly::FATAL.

77  {
78  LOG(FATAL) << "only writeChain() supported";
79  }

Member Data Documentation

ReadCallback* fizz::test::LocalTransport::callback_ {nullptr}
private

Definition at line 174 of file LocalTransport.h.

Referenced by deliverData(), getReadCallback(), and setReadCB().

folly::EventBase* fizz::test::LocalTransport::evb_ {nullptr}
private

Definition at line 170 of file LocalTransport.h.

Referenced by attachEventBase(), detachEventBase(), and getEventBase().

LocalTransport* fizz::test::LocalTransport::peer_ {nullptr}
private

Definition at line 169 of file LocalTransport.h.

Referenced by setPeer(), and writeChain().

folly::IOBufQueue fizz::test::LocalTransport::readBuf_ {folly::IOBufQueue::cacheChainLength()}
private

Definition at line 173 of file LocalTransport.h.

Referenced by deliverData(), and receiveData().

size_t fizz::test::LocalTransport::received_ {0}
private

Definition at line 171 of file LocalTransport.h.

Referenced by getAppBytesReceived(), getRawBytesReceived(), and receiveData().

bool fizz::test::LocalTransport::trickle_ {false}
private

Definition at line 176 of file LocalTransport.h.

Referenced by deliverData(), and setTrickle().

folly::Function<void()> fizz::test::LocalTransport::trickleCallback_
private

Definition at line 177 of file LocalTransport.h.

Referenced by deliverData(), and setTrickle().

size_t fizz::test::LocalTransport::written_ {0}
private

Definition at line 172 of file LocalTransport.h.

Referenced by getAppBytesWritten(), getRawBytesWritten(), and writeChain().


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