proxygen
folly::ReadCallback Class Reference

#include <AsyncSSLSocketTest.h>

Inheritance diagram for folly::ReadCallback:
folly::ReadCallbackBase folly::AsyncReader::ReadCallback folly::AsyncSSLSocket::DefaultOpenSSLAsyncFinishCallback folly::EmptyReadCallback folly::ReadCallbackTerminator folly::WriteErrorCallback

Classes

class  Buffer
 

Public Member Functions

 ReadCallback (WriteCallbackBase *wcb)
 
 ~ReadCallback () override
 
void getReadBuffer (void **bufReturn, size_t *lenReturn) override
 
void readDataAvailable (size_t len) noexceptoverride
 
- Public Member Functions inherited from folly::ReadCallbackBase
 ReadCallbackBase (WriteCallbackBase *wcb)
 
 ~ReadCallbackBase () override
 
void setSocket (const std::shared_ptr< AsyncSSLSocket > &socket)
 
void setState (StateEnum s)
 
void readErr (const AsyncSocketException &ex) noexceptoverride
 
void readEOF () noexceptoverride
 
- Public Member Functions inherited from folly::AsyncReader::ReadCallback
virtual bool isBufferMovable () noexcept
 
virtual size_t maxBufferSize () const
 
virtual void readBufferAvailable (std::unique_ptr< IOBuf >) noexcept
 

Public Attributes

std::vector< Bufferbuffers
 
Buffer currentBuffer
 
- Public Attributes inherited from folly::ReadCallbackBase
std::shared_ptr< AsyncSSLSocketsocket_
 
WriteCallbackBasewcb_
 
StateEnum state
 

Detailed Description

Definition at line 314 of file AsyncSSLSocketTest.h.

Constructor & Destructor Documentation

folly::ReadCallback::ReadCallback ( WriteCallbackBase wcb)
inlineexplicit

Definition at line 316 of file AsyncSSLSocketTest.h.

317  : ReadCallbackBase(wcb), buffers() {}
ReadCallbackBase(WriteCallbackBase *wcb)
std::vector< Buffer > buffers
folly::ReadCallback::~ReadCallback ( )
inlineoverridevirtual

Reimplemented from folly::AsyncReader::ReadCallback.

Definition at line 319 of file AsyncSSLSocketTest.h.

319  {
320  for (std::vector<Buffer>::iterator it = buffers.begin();
321  it != buffers.end();
322  ++it) {
323  it->free();
324  }
326  }
std::vector< Buffer > buffers

Member Function Documentation

void folly::ReadCallback::getReadBuffer ( void **  bufReturn,
size_t *  lenReturn 
)
inlineoverridevirtual

When data becomes available, getReadBuffer() will be invoked to get the buffer into which data should be read.

This method allows the ReadCallback to delay buffer allocation until data becomes available. This allows applications to manage large numbers of idle connections, without having to maintain a separate read buffer for each idle connection.

It is possible that in some cases, getReadBuffer() may be called multiple times before readDataAvailable() is invoked. In this case, the data will be written to the buffer returned from the most recent call to readDataAvailable(). If the previous calls to readDataAvailable() returned different buffers, the ReadCallback is responsible for ensuring that they are not leaked.

If getReadBuffer() throws an exception, returns a nullptr buffer, or returns a 0 length, the ReadCallback will be uninstalled and its readError() method will be invoked.

getReadBuffer() is not allowed to change the transport state before it returns. (For example, it should never uninstall the read callback, or set a different read callback.)

Parameters
bufReturngetReadBuffer() should update *bufReturn to contain the address of the read buffer. This parameter will never be nullptr.
lenReturngetReadBuffer() should update *lenReturn to contain the maximum number of bytes that may be written to the read buffer. This parameter will never be nullptr.

Implements folly::AsyncReader::ReadCallback.

Definition at line 328 of file AsyncSSLSocketTest.h.

328  {
329  if (!currentBuffer.buffer) {
330  currentBuffer.allocate(4096);
331  }
332  *bufReturn = currentBuffer.buffer;
333  *lenReturn = currentBuffer.length;
334  }
void folly::ReadCallback::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.

Reimplemented in folly::WriteErrorCallback.

Definition at line 336 of file AsyncSSLSocketTest.h.

References folly::SendMsgParamsCallbackBase::socket_, and folly::STATE_SUCCEEDED.

336  {
337  std::cerr << "readDataAvailable, len " << len << std::endl;
338 
339  currentBuffer.length = len;
340 
342 
343  // Write back the same data.
344  socket_->write(wcb_, currentBuffer.buffer, len);
345 
346  buffers.push_back(currentBuffer);
349  }
virtual void setSocket(const std::shared_ptr< AsyncSSLSocket > &socket)
std::vector< Buffer > buffers
WriteCallbackBase * wcb_
std::shared_ptr< AsyncSSLSocket > socket_
state
Definition: http_parser.c:272

Member Data Documentation

std::vector<Buffer> folly::ReadCallback::buffers

Definition at line 374 of file AsyncSSLSocketTest.h.

Referenced by TEST(), folly::TEST(), TEST_P(), and testConnectOptWrite().

Buffer folly::ReadCallback::currentBuffer

Definition at line 375 of file AsyncSSLSocketTest.h.


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