proxygen
folly::test::MockReadCallback Class Reference

#include <MockAsyncTransport.h>

Inheritance diagram for folly::test::MockReadCallback:
folly::AsyncReader::ReadCallback

Public Member Functions

 MOCK_METHOD2 (getReadBuffer, void(void **, size_t *))
 
 MOCK_METHOD1 (readDataAvailable_, void(size_t))
 
void readDataAvailable (size_t size) noexceptoverride
 
 MOCK_METHOD0 (isBufferMovable_, bool())
 
bool isBufferMovable () noexceptoverride
 
 MOCK_METHOD1 (readBufferAvailable_, void(std::unique_ptr< folly::IOBuf > &))
 
void readBufferAvailable (std::unique_ptr< folly::IOBuf > readBuf) noexceptoverride
 
 MOCK_METHOD0 (readEOF_, void())
 
void readEOF () noexceptoverride
 
 MOCK_METHOD1 (readErr_, void(const AsyncSocketException &))
 
void readErr (const AsyncSocketException &ex) noexceptoverride
 
- Public Member Functions inherited from folly::AsyncReader::ReadCallback
virtual ~ReadCallback ()=default
 
virtual void getReadBuffer (void **bufReturn, size_t *lenReturn)=0
 
virtual size_t maxBufferSize () const
 

Detailed Description

Definition at line 82 of file MockAsyncTransport.h.

Member Function Documentation

bool folly::test::MockReadCallback::isBufferMovable ( )
inlineoverridevirtualnoexcept

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 92 of file MockAsyncTransport.h.

References folly::test::MockAsyncTransport::MOCK_METHOD1().

92  {
93  return isBufferMovable_();
94  }
folly::test::MockReadCallback::MOCK_METHOD0 ( isBufferMovable_  ,
bool()   
)
folly::test::MockReadCallback::MOCK_METHOD0 ( readEOF_  ,
void()   
)
folly::test::MockReadCallback::MOCK_METHOD1 ( readDataAvailable_  ,
void(size_t)   
)
folly::test::MockReadCallback::MOCK_METHOD1 ( readBufferAvailable_  ,
void(std::unique_ptr< folly::IOBuf > &)   
)
folly::test::MockReadCallback::MOCK_METHOD1 ( readErr_  ,
void(const AsyncSocketException &)   
)
folly::test::MockReadCallback::MOCK_METHOD2 ( getReadBuffer  ,
void(void **, size_t *)   
)
void folly::test::MockReadCallback::readBufferAvailable ( std::unique_ptr< folly::IOBuf )
inlineoverridevirtualnoexcept

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 97 of file MockAsyncTransport.h.

References folly::test::MockAsyncTransport::MOCK_METHOD0(), and fizz::detail::readBuf().

98  {
99  readBufferAvailable_(readBuf);
100  }
size_t readBuf(Buf &buf, folly::io::Cursor &cursor)
Definition: Types-inl.h:220
void folly::test::MockReadCallback::readDataAvailable ( size_t  len)
inlineoverridevirtualnoexcept

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 87 of file MockAsyncTransport.h.

References folly::test::MockAsyncTransport::MOCK_METHOD0(), and folly::size().

87  {
88  readDataAvailable_(size);
89  }
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
void folly::test::MockReadCallback::readEOF ( )
inlineoverridevirtualnoexcept

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 103 of file MockAsyncTransport.h.

References folly::test::MockAsyncTransport::MOCK_METHOD1().

103  {
104  readEOF_();
105  }
void folly::test::MockReadCallback::readErr ( const AsyncSocketException ex)
inlineoverridevirtualnoexcept

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 108 of file MockAsyncTransport.h.

108  {
109  readErr_(ex);
110  }

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