proxygen
folly::test::MockAsyncSocket Class Reference

#include <MockAsyncSocket.h>

Inheritance diagram for folly::test::MockAsyncSocket:
folly::AsyncSocket folly::AsyncTransportWrapper folly::AsyncTransport folly::AsyncReader folly::AsyncWriter folly::DelayedDestruction folly::AsyncSocketBase folly::DelayedDestructionBase

Public Types

typedef std::unique_ptr< MockAsyncSocket, DestructorUniquePtr
 
- Public Types inherited from folly::AsyncSocket
enum  StateEnum : uint8_t {
  StateEnum::UNINIT, StateEnum::CONNECTING, StateEnum::ESTABLISHED, StateEnum::CLOSED,
  StateEnum::ERROR, StateEnum::FAST_OPEN
}
 
typedef std::unique_ptr< AsyncSocket, DestructorUniquePtr
 
typedef std::map< OptionKey, int > OptionMap
 
- 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

 MockAsyncSocket (EventBase *base)
 
 MOCK_METHOD5 (connect_, void(AsyncSocket::ConnectCallback *, const folly::SocketAddress &, int, const OptionMap &, const folly::SocketAddress &))
 
void connect (AsyncSocket::ConnectCallback *callback, const folly::SocketAddress &address, int timeout, const OptionMap &options, const folly::SocketAddress &bindAddr) noexceptoverride
 
 MOCK_CONST_METHOD1 (getPeerAddress, void(folly::SocketAddress *))
 
 MOCK_METHOD0 (detachFd, int())
 
 MOCK_CONST_METHOD0 (getFd, int())
 
 MOCK_METHOD0 (closeNow, void())
 
 MOCK_CONST_METHOD0 (good, bool())
 
 MOCK_CONST_METHOD0 (readable, bool())
 
 MOCK_CONST_METHOD0 (hangup, bool())
 
 MOCK_CONST_METHOD1 (getLocalAddress, void(SocketAddress *))
 
 MOCK_METHOD1 (setReadCB, void(ReadCallback *))
 
 MOCK_METHOD1 (_setPreReceivedData, void(std::unique_ptr< IOBuf > &))
 
 MOCK_CONST_METHOD0 (getRawBytesWritten, size_t())
 
 MOCK_METHOD4 (setSockOptVirtual, int(int, int, void const *, socklen_t))
 
 MOCK_METHOD1 (setErrMessageCB, void(AsyncSocket::ErrMessageCallback *))
 
 MOCK_METHOD1 (setSendMsgParamCB, void(AsyncSocket::SendMsgParamsCallback *))
 
void setPreReceivedData (std::unique_ptr< IOBuf > data) override
 
- Public Member Functions inherited from folly::AsyncSocket
 AsyncSocket ()
 
 AsyncSocket (EventBase *evb)
 
void setShutdownSocketSet (const std::weak_ptr< ShutdownSocketSet > &wSS)
 
 AsyncSocket (EventBase *evb, const folly::SocketAddress &address, uint32_t connectTimeout=0)
 
 AsyncSocket (EventBase *evb, const std::string &ip, uint16_t port, uint32_t connectTimeout=0)
 
 AsyncSocket (EventBase *evb, int fd, uint32_t zeroCopyBufId=0)
 
 AsyncSocket (AsyncSocket::UniquePtr)
 
void destroy () override
 
EventBasegetEventBase () const override
 
virtual int getFd () const
 
virtual int detachFd ()
 
void connect (ConnectCallback *callback, const std::string &ip, uint16_t port, int timeout=0, const OptionMap &options=emptyOptionMap) noexcept
 
void cancelConnect ()
 
void setSendTimeout (uint32_t milliseconds) override
 
uint32_t getSendTimeout () const override
 
void setMaxReadsPerEvent (uint16_t maxReads)
 
uint16_t getMaxReadsPerEvent () const
 
virtual void setErrMessageCB (ErrMessageCallback *callback)
 
virtual ErrMessageCallbackgetErrMessageCallback () const
 
virtual void setSendMsgParamCB (SendMsgParamsCallback *callback)
 
virtual SendMsgParamsCallbackgetSendMsgParamsCB () const
 
void setReadCB (ReadCallback *callback) override
 
ReadCallbackgetReadCallback () const override
 
bool setZeroCopy (bool enable)
 
bool getZeroCopy () const
 
uint32_t getZeroCopyBufId () const
 
size_t getZeroCopyReenableThreshold () const
 
void setZeroCopyReenableThreshold (size_t threshold)
 
void write (WriteCallback *callback, const void *buf, size_t bytes, WriteFlags flags=WriteFlags::NONE) override
 
void writev (WriteCallback *callback, const iovec *vec, size_t count, WriteFlags flags=WriteFlags::NONE) override
 
void writeChain (WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags=WriteFlags::NONE) override
 
virtual void writeRequest (WriteRequest *req)
 
void writeRequestReady ()
 
void close () override
 
void closeNow () override
 
void closeWithReset () override
 
void shutdownWrite () override
 
void shutdownWriteNow () override
 
bool readable () const override
 
bool writable () const override
 
bool isPending () const override
 
virtual bool hangup () const
 
bool good () const override
 
bool error () const override
 
void attachEventBase (EventBase *eventBase) override
 
void detachEventBase () override
 
bool isDetachable () const override
 
void getLocalAddress (folly::SocketAddress *address) const override
 
void getPeerAddress (folly::SocketAddress *address) const override
 
bool isEorTrackingEnabled () const override
 
void setEorTracking (bool track) override
 
bool connecting () const override
 
virtual bool isClosedByPeer () const
 
virtual bool isClosedBySelf () const
 
size_t getAppBytesWritten () const override
 
size_t getRawBytesWritten () const override
 
size_t getAppBytesReceived () const override
 
size_t getRawBytesReceived () const override
 
std::chrono::nanoseconds getConnectTime () const
 
std::chrono::milliseconds getConnectTimeout () const
 
std::chrono::steady_clock::time_point getConnectStartTime () const
 
std::chrono::steady_clock::time_point getConnectEndTime () const
 
bool getTFOAttempted () const
 
bool getTFOFinished () const
 
bool getTFOSucceded () const
 
int setNoDelay (bool noDelay)
 
void setCloseOnExec ()
 
int setCongestionFlavor (const std::string &cname)
 
int setQuickAck (bool quickack)
 
int setSendBufSize (size_t bufsize)
 
int setRecvBufSize (size_t bufsize)
 
int setTCPProfile (int profd)
 
template<typename T >
int getSockOpt (int level, int optname, T *optval, socklen_t *optlen)
 
template<typename T >
int setSockOpt (int level, int optname, const T *optval)
 
virtual int getSockOptVirtual (int level, int optname, void *optval, socklen_t *optlen)
 
virtual int setSockOptVirtual (int level, int optname, void const *optval, socklen_t optlen)
 
void enableTFO ()
 
void disableTransparentTls ()
 
void disableTSocks ()
 
void setBufferCallback (BufferCallback *cb)
 
void setEvbChangedCallback (std::unique_ptr< EvbChangeCallback > cb)
 
void cacheAddresses ()
 
bool isZeroCopyWriteInProgress () const noexcept
 
bool processZeroCopyWriteInProgress () noexcept
 
void setPeerCertificate (std::unique_ptr< const AsyncTransportCertificate > cert)
 
const AsyncTransportCertificategetPeerCertificate () const override
 
void setSelfCertificate (std::unique_ptr< const AsyncTransportCertificate > cert)
 
const AsyncTransportCertificategetSelfCertificate () const 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
SocketAddress getLocalAddress () const
 
void getAddress (SocketAddress *address) const override
 
SocketAddress getPeerAddress () const
 
virtual ssl::X509UniquePtr getPeerCert () const
 
virtual const X509 * getSelfCert () 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
bool getDestroyPending () const
 
- Public Member Functions inherited from folly::DelayedDestructionBase
virtual ~DelayedDestructionBase ()=default
 
- Public Member Functions inherited from folly::AsyncSocketBase
virtual ~AsyncSocketBase ()=default
 

Additional Inherited Members

- Static Public Member Functions inherited from folly::AsyncSocket
static std::shared_ptr< AsyncSocketnewSocket (EventBase *evb)
 
static std::shared_ptr< AsyncSocketnewSocket (EventBase *evb, const folly::SocketAddress &address, uint32_t connectTimeout=0)
 
static std::shared_ptr< AsyncSocketnewSocket (EventBase *evb, const std::string &ip, uint16_t port, uint32_t connectTimeout=0)
 
static std::shared_ptr< AsyncSocketnewSocket (EventBase *evb, int fd)
 
static const folly::SocketAddressanyAddress ()
 
- Static Public Attributes inherited from folly::AsyncSocket
static const OptionMap emptyOptionMap
 
- Protected Types inherited from folly::AsyncSocket
enum  ReadResultEnum { READ_EOF = 0, READ_ERROR = -1, READ_BLOCKING = -2, READ_NO_ERROR = -3 }
 
enum  WriteResultEnum { WRITE_ERROR = -1 }
 
enum  ShutdownFlags { SHUT_WRITE_PENDING = 0x01, SHUT_WRITE = 0x02, SHUT_READ = 0x04 }
 
- Protected Member Functions inherited from folly::AsyncSocket
 ~AsyncSocket () override
 
void init ()
 
void scheduleImmediateRead () noexcept
 
void scheduleInitialReadWrite () noexcept
 
void ioReady (uint16_t events) noexcept
 
virtual void checkForImmediateRead () noexcept
 
virtual void handleInitialReadWrite () noexcept
 
virtual void prepareReadBuffer (void **buf, size_t *buflen)
 
virtual size_t handleErrMessages () noexcept
 
virtual void handleRead () noexcept
 
virtual void handleWrite () noexcept
 
virtual void handleConnect () noexcept
 
void timeoutExpired () noexcept
 
virtual ReadResult performRead (void **buf, size_t *buflen, size_t *offset)
 
void writeChainImpl (WriteCallback *callback, iovec *vec, size_t count, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags)
 
void writeImpl (WriteCallback *callback, const iovec *vec, size_t count, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags=WriteFlags::NONE)
 
virtual WriteResult performWrite (const iovec *vec, uint32_t count, WriteFlags flags, uint32_t *countWritten, uint32_t *partialWritten)
 
AsyncSocket::WriteResult sendSocketMessage (int fd, struct msghdr *msg, int msg_flags)
 
virtual ssize_t tfoSendMsg (int fd, struct msghdr *msg, int msg_flags)
 
int socketConnect (const struct sockaddr *addr, socklen_t len)
 
virtual void scheduleConnectTimeout ()
 
void registerForConnectEvents ()
 
bool updateEventRegistration ()
 
bool updateEventRegistration (uint16_t enable, uint16_t disable)
 
void doClose ()
 
void startFail ()
 
void finishFail ()
 
void finishFail (const AsyncSocketException &ex)
 
void invokeAllErrors (const AsyncSocketException &ex)
 
void fail (const char *fn, const AsyncSocketException &ex)
 
void failConnect (const char *fn, const AsyncSocketException &ex)
 
void failRead (const char *fn, const AsyncSocketException &ex)
 
void failErrMessageRead (const char *fn, const AsyncSocketException &ex)
 
void failWrite (const char *fn, WriteCallback *callback, size_t bytesWritten, const AsyncSocketException &ex)
 
void failWrite (const char *fn, const AsyncSocketException &ex)
 
void failAllWrites (const AsyncSocketException &ex)
 
virtual void invokeConnectErr (const AsyncSocketException &ex)
 
virtual void invokeConnectSuccess ()
 
void invalidState (ConnectCallback *callback)
 
void invalidState (ErrMessageCallback *callback)
 
void invalidState (ReadCallback *callback)
 
void invalidState (WriteCallback *callback)
 
std::string withAddr (const std::string &s)
 
void cacheLocalAddress () const
 
void cachePeerAddress () const
 
bool isZeroCopyRequest (WriteFlags flags)
 
bool isZeroCopyMsg (const cmsghdr &cmsg) const
 
void processZeroCopyMsg (const cmsghdr &cmsg)
 
uint32_t getNextZeroCopyBufId ()
 
void adjustZeroCopyFlags (folly::WriteFlags &flags)
 
void addZeroCopyBuf (std::unique_ptr< folly::IOBuf > &&buf)
 
void addZeroCopyBuf (folly::IOBuf *ptr)
 
void setZeroCopyBuf (std::unique_ptr< folly::IOBuf > &&buf)
 
bool containsZeroCopyBuf (folly::IOBuf *ptr)
 
void releaseZeroCopyBuf (uint32_t id)
 
- 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 Attributes inherited from folly::AsyncSocket
uint32_t zeroCopyBufId_ {0}
 
std::unordered_map< uint32_t, folly::IOBuf * > idZeroCopyBufPtrMap_
 
std::unordered_map< folly::IOBuf *, IOBufInfoidZeroCopyBufInfoMap_
 
StateEnum state_
 StateEnum describing current state. More...
 
uint8_t shutdownFlags_
 Shutdown state (ShutdownFlags) More...
 
uint16_t eventFlags_
 EventBase::HandlerFlags settings. More...
 
int fd_
 The socket file descriptor. More...
 
folly::SocketAddress addr_
 The address we tried to connect to. More...
 
folly::SocketAddress localAddr_
 The address we are connecting from. More...
 
uint32_t sendTimeout_
 The send timeout, in milliseconds. More...
 
uint16_t maxReadsPerEvent_
 Max reads per event loop iteration. More...
 
bool isBufferMovable_ {false}
 
int8_t readErr_ {READ_NO_ERROR}
 The read error encountered, if any. More...
 
EventBaseeventBase_
 The EventBase. More...
 
WriteTimeout writeTimeout_
 A timeout for connect and write. More...
 
IoHandler ioHandler_
 A EventHandler to monitor the fd. More...
 
ImmediateReadCB immediateReadHandler_
 LoopCallback for checking read. More...
 
ConnectCallbackconnectCallback_
 ConnectCallback. More...
 
ErrMessageCallbackerrMessageCallback_
 TimestampCallback. More...
 
SendMsgParamsCallbacksendMsgParamCallback_
 < Callback for retrieving More...
 
ReadCallbackreadCallback_
 ReadCallback. More...
 
WriteRequestwriteReqHead_
 Chain of WriteRequests. More...
 
WriteRequestwriteReqTail_
 End of WriteRequest chain. More...
 
std::weak_ptr< ShutdownSocketSetwShutdownSocketSet_
 
size_t appBytesReceived_
 Num of bytes received from socket. More...
 
size_t appBytesWritten_
 Num of bytes written to socket. More...
 
std::unique_ptr< IOBufpreReceivedData_
 
std::chrono::steady_clock::time_point connectStartTime_
 
std::chrono::steady_clock::time_point connectEndTime_
 
std::chrono::milliseconds connectTimeout_ {0}
 
std::unique_ptr< EvbChangeCallbackevbChangeCb_ {nullptr}
 
BufferCallbackbufferCallback_ {nullptr}
 
bool tfoEnabled_ {false}
 
bool tfoAttempted_ {false}
 
bool tfoFinished_ {false}
 
bool noTransparentTls_ {false}
 
bool noTSocks_ {false}
 
bool trackEor_ {false}
 
bool zeroCopyEnabled_ {false}
 
bool zeroCopyVal_ {false}
 
size_t zeroCopyReenableThreshold_ {0}
 
size_t zeroCopyReenableCounter_ {0}
 
std::unique_ptr< const AsyncTransportCertificatepeerCertData_
 
std::unique_ptr< const AsyncTransportCertificateselfCertData_
 

Detailed Description

Definition at line 26 of file MockAsyncSocket.h.

Member Typedef Documentation

Definition at line 28 of file MockAsyncSocket.h.

Constructor & Destructor Documentation

folly::test::MockAsyncSocket::MockAsyncSocket ( EventBase base)
inlineexplicit

Definition at line 30 of file MockAsyncSocket.h.

References MOCK_METHOD5().

30 : AsyncSocket(base) {}

Member Function Documentation

void folly::test::MockAsyncSocket::connect ( AsyncSocket::ConnectCallback callback,
const folly::SocketAddress address,
int  timeout,
const OptionMap options,
const folly::SocketAddress bindAddr 
)
inlineoverridevirtualnoexcept

Initiate a connection.

Parameters
callbackThe callback to inform when the connection attempt completes.
addressThe address to connect to.
timeoutA timeout value, in milliseconds. If the connection does not succeed within this period, callback->connectError() will be invoked.

Reimplemented from folly::AsyncSocket.

Definition at line 40 of file MockAsyncSocket.h.

References folly::AsyncSocket::closeNow(), folly::AsyncSocket::detachFd(), folly::AsyncSocket::getFd(), folly::AsyncTransport::getLocalAddress(), folly::AsyncTransport::getPeerAddress(), folly::AsyncSocket::getRawBytesWritten(), folly::AsyncSocket::good(), folly::AsyncSocket::hangup(), MOCK_CONST_METHOD0(), MOCK_CONST_METHOD1(), MOCK_METHOD0(), MOCK_METHOD1(), MOCK_METHOD4(), folly::AsyncSocket::readable(), folly::AsyncSocket::setErrMessageCB(), folly::AsyncSocket::setReadCB(), folly::AsyncSocket::setSendMsgParamCB(), folly::AsyncSocket::setSockOptVirtual(), and folly::detail::timeout.

45  {
46  connect_(callback, address, timeout, options, bindAddr);
47  }
folly::test::MockAsyncSocket::MOCK_CONST_METHOD0 ( getFd  ,
int()   
)

Referenced by connect().

folly::test::MockAsyncSocket::MOCK_CONST_METHOD0 ( good  ,
bool()   
)
folly::test::MockAsyncSocket::MOCK_CONST_METHOD0 ( readable  ,
bool()   
)
folly::test::MockAsyncSocket::MOCK_CONST_METHOD0 ( hangup  ,
bool()   
)
folly::test::MockAsyncSocket::MOCK_CONST_METHOD0 ( getRawBytesWritten  ,
size_t()   
)
folly::test::MockAsyncSocket::MOCK_CONST_METHOD1 ( getPeerAddress  ,
void(folly::SocketAddress *)   
)

Referenced by connect().

folly::test::MockAsyncSocket::MOCK_CONST_METHOD1 ( getLocalAddress  ,
void(SocketAddress *)   
)
folly::test::MockAsyncSocket::MOCK_METHOD0 ( detachFd  ,
int()   
)

Referenced by connect().

folly::test::MockAsyncSocket::MOCK_METHOD0 ( closeNow  ,
void()   
)
folly::test::MockAsyncSocket::MOCK_METHOD1 ( setReadCB  ,
void(ReadCallback *)   
)

Referenced by connect().

folly::test::MockAsyncSocket::MOCK_METHOD1 ( _setPreReceivedData  ,
void(std::unique_ptr< IOBuf > &)   
)
folly::test::MockAsyncSocket::MOCK_METHOD1 ( setErrMessageCB  ,
void(AsyncSocket::ErrMessageCallback *)   
)
folly::test::MockAsyncSocket::MOCK_METHOD1 ( setSendMsgParamCB  ,
void(AsyncSocket::SendMsgParamsCallback *)   
)
folly::test::MockAsyncSocket::MOCK_METHOD4 ( setSockOptVirtual  ,
int(int, int, void const *, socklen_t)   
)

Referenced by connect().

folly::test::MockAsyncSocket::MOCK_METHOD5 ( connect_  ,
void(AsyncSocket::ConnectCallback *, const folly::SocketAddress &, int, const OptionMap &, const folly::SocketAddress &)   
)

Referenced by MockAsyncSocket().

void folly::test::MockAsyncSocket::setPreReceivedData ( std::unique_ptr< IOBuf data)
inlineoverridevirtual

Set pre-received data, to be returned to read callback before any data from the socket.

Reimplemented from folly::AsyncSocket.

Definition at line 63 of file MockAsyncSocket.h.

63  {
64  return _setPreReceivedData(data);
65  }

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