proxygen
folly::BlockingWriteServer Class Reference

#include <AsyncSSLSocketTest.h>

Inheritance diagram for folly::BlockingWriteServer:
folly::AsyncSSLSocket::HandshakeCB folly::AsyncReader::ReadCallback

Public Member Functions

 BlockingWriteServer (AsyncSSLSocket::UniquePtr socket)
 
void checkBuffer (struct iovec *iov, uint32_t count) const
 

Private Member Functions

void handshakeSuc (AsyncSSLSocket *) noexceptoverride
 
void handshakeErr (AsyncSSLSocket *, const AsyncSocketException &ex) noexceptoverride
 
void getReadBuffer (void **bufReturn, size_t *lenReturn) override
 
void readDataAvailable (size_t len) noexceptoverride
 
void readEOF () noexceptoverride
 
void readErr (const AsyncSocketException &ex) noexceptoverride
 
- Private Member Functions inherited from folly::AsyncSSLSocket::HandshakeCB
virtual ~HandshakeCB ()=default
 
virtual bool handshakeVer (AsyncSSLSocket *, bool preverifyOk, X509_STORE_CTX *) noexcept
 
- Private Member Functions inherited from folly::AsyncReader::ReadCallback
virtual ~ReadCallback ()=default
 
virtual bool isBufferMovable () noexcept
 
virtual size_t maxBufferSize () const
 
virtual void readBufferAvailable (std::unique_ptr< IOBuf >) noexcept
 

Private Attributes

AsyncSSLSocket::UniquePtr socket_
 
uint32_t bufSize_
 
uint32_t bytesRead_
 
std::unique_ptr< uint8_t[]> buf_
 

Detailed Description

Definition at line 848 of file AsyncSSLSocketTest.h.

Constructor & Destructor Documentation

folly::BlockingWriteServer::BlockingWriteServer ( AsyncSSLSocket::UniquePtr  socket)
inlineexplicit

Definition at line 851 of file AsyncSSLSocketTest.h.

References folly::SendMsgParamsCallbackBase::socket_.

852  : socket_(std::move(socket)), bufSize_(2500 * 2000), bytesRead_(0) {
853  buf_ = std::make_unique<uint8_t[]>(bufSize_);
854  socket_->sslAccept(this, std::chrono::milliseconds(100));
855  }
AsyncSSLSocket::UniquePtr socket_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< uint8_t[]> buf_
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412

Member Function Documentation

void folly::BlockingWriteServer::checkBuffer ( struct iovec *  iov,
uint32_t  count 
) const
inline

Definition at line 857 of file AsyncSSLSocketTest.h.

References ADD_FAILURE, count, FAIL, min, and uint32_t.

857  {
858  uint32_t idx = 0;
859  for (uint32_t n = 0; n < count; ++n) {
860  size_t bytesLeft = bytesRead_ - idx;
861  int rc = memcmp(
862  buf_.get() + idx,
863  iov[n].iov_base,
864  std::min(iov[n].iov_len, bytesLeft));
865  if (rc != 0) {
866  FAIL() << "buffer mismatch at iovec " << n << "/" << count
867  << ": rc=" << rc;
868  }
869  if (iov[n].iov_len > bytesLeft) {
870  FAIL() << "server did not read enough data: "
871  << "ended at byte " << bytesLeft << "/" << iov[n].iov_len
872  << " in iovec " << n << "/" << count;
873  }
874 
875  idx += iov[n].iov_len;
876  }
877  if (idx != bytesRead_) {
878  ADD_FAILURE() << "server read extra data: " << bytesRead_
879  << " bytes read; expected " << idx;
880  }
881  }
#define FAIL()
Definition: gtest.h:1822
std::unique_ptr< uint8_t[]> buf_
LogLevel min
Definition: LogLevel.cpp:30
int * count
#define ADD_FAILURE()
Definition: gtest.h:1808
void folly::BlockingWriteServer::getReadBuffer ( void **  bufReturn,
size_t *  lenReturn 
)
inlineoverrideprivatevirtual

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 894 of file AsyncSSLSocketTest.h.

894  {
895  *bufReturn = buf_.get() + bytesRead_;
896  *lenReturn = bufSize_ - bytesRead_;
897  }
std::unique_ptr< uint8_t[]> buf_
void folly::BlockingWriteServer::handshakeErr ( AsyncSSLSocket sock,
const AsyncSocketException ex 
)
inlineoverrideprivatevirtualnoexcept

handshakeErr() is called if an error occurs while establishing the SSL connection.

The HandshakeCB will be uninstalled before handshakeErr() is called.

Parameters
sockSSL socket on which the handshake was initiated
exAn exception representing the error.

Implements folly::AsyncSSLSocket::HandshakeCB.

Definition at line 889 of file AsyncSSLSocketTest.h.

References ADD_FAILURE.

891  {
892  ADD_FAILURE() << "server handshake error: " << ex.what();
893  }
#define ADD_FAILURE()
Definition: gtest.h:1808
void folly::BlockingWriteServer::handshakeSuc ( AsyncSSLSocket sock)
inlineoverrideprivatevirtualnoexcept

handshakeSuc() is called when a new SSL connection is established, i.e., after SSL_accept/connect() returns successfully.

The HandshakeCB will be uninstalled before handshakeSuc() is called.

Parameters
sockSSL socket on which the handshake was initiated

Implements folly::AsyncSSLSocket::HandshakeCB.

Definition at line 884 of file AsyncSSLSocketTest.h.

References folly::SendMsgParamsCallbackBase::socket_.

884  {
885  // Wait 10ms before reading, so the client's writes will initially block.
886  socket_->getEventBase()->tryRunAfterDelay(
887  [this] { socket_->setReadCB(this); }, 10);
888  }
AsyncSSLSocket::UniquePtr socket_
void folly::BlockingWriteServer::readDataAvailable ( size_t  len)
inlineoverrideprivatevirtualnoexcept

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 898 of file AsyncSSLSocketTest.h.

References folly::SendMsgParamsCallbackBase::socket_.

898  {
899  bytesRead_ += len;
900  socket_->setReadCB(nullptr);
901  socket_->getEventBase()->tryRunAfterDelay(
902  [this] { socket_->setReadCB(this); }, 2);
903  }
AsyncSSLSocket::UniquePtr socket_
void folly::BlockingWriteServer::readEOF ( )
inlineoverrideprivatevirtualnoexcept

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 904 of file AsyncSSLSocketTest.h.

References folly::SendMsgParamsCallbackBase::socket_.

904  {
905  socket_->close();
906  }
AsyncSSLSocket::UniquePtr socket_
void folly::BlockingWriteServer::readErr ( const AsyncSocketException ex)
inlineoverrideprivatevirtualnoexcept

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 907 of file AsyncSSLSocketTest.h.

References ADD_FAILURE.

907  {
908  ADD_FAILURE() << "server read error: " << ex.what();
909  }
#define ADD_FAILURE()
Definition: gtest.h:1808

Member Data Documentation

std::unique_ptr<uint8_t[]> folly::BlockingWriteServer::buf_
private

Definition at line 914 of file AsyncSSLSocketTest.h.

uint32_t folly::BlockingWriteServer::bufSize_
private

Definition at line 912 of file AsyncSSLSocketTest.h.

uint32_t folly::BlockingWriteServer::bytesRead_
private

Definition at line 913 of file AsyncSSLSocketTest.h.

AsyncSSLSocket::UniquePtr folly::BlockingWriteServer::socket_
private

Definition at line 911 of file AsyncSSLSocketTest.h.


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