proxygen
BogoTestClient Class Reference
Inheritance diagram for BogoTestClient:
folly::AsyncSocket::ConnectCallback fizz::client::AsyncFizzClientT< SM >::HandshakeCallback folly::AsyncReader::ReadCallback

Public Member Functions

 BogoTestClient (EventBase *evb, uint16_t port, std::shared_ptr< const FizzClientContext > clientContext)
 
void connectSuccess () noexceptoverride
 
void connectErr (const AsyncSocketException &ex) noexceptoverride
 
void fizzHandshakeSuccess (AsyncFizzClient *) noexceptoverride
 
void fizzHandshakeError (AsyncFizzClient *, folly::exception_wrapper ex) noexceptoverride
 
void getReadBuffer (void **, size_t *) override
 
void readDataAvailable (size_t) noexceptoverride
 
bool isBufferMovable () noexceptoverride
 
void readBufferAvailable (std::unique_ptr< IOBuf > buf) noexceptoverride
 
void readEOF () noexceptoverride
 
void readErr (const AsyncSocketException &) noexceptoverride
 
bool unimplemented () const
 
bool success () const
 
- Public Member Functions inherited from folly::AsyncSocket::ConnectCallback
virtual ~ConnectCallback ()=default
 
- Public Member Functions inherited from fizz::client::AsyncFizzClientT< SM >::HandshakeCallback
virtual ~HandshakeCallback ()=default
 
virtual void fizzHandshakeSuccess (AsyncFizzClientT *transport) noexcept=0
 
virtual void fizzHandshakeError (AsyncFizzClientT *transport, folly::exception_wrapper ex) noexcept=0
 
- Public Member Functions inherited from folly::AsyncReader::ReadCallback
virtual ~ReadCallback ()=default
 
virtual size_t maxBufferSize () const
 

Private Attributes

AsyncSocket::UniquePtr socket_
 
std::shared_ptr< const FizzClientContextclientContext_
 
AsyncFizzClient::UniquePtr transport_
 
bool unimplemented_ {false}
 
Optional< bool > success_
 

Detailed Description

Definition at line 157 of file BogoShim.cpp.

Constructor & Destructor Documentation

BogoTestClient::BogoTestClient ( EventBase evb,
uint16_t  port,
std::shared_ptr< const FizzClientContext clientContext 
)
inline

Definition at line 161 of file BogoShim.cpp.

References socket_.

165  : clientContext_(clientContext) {
167  socket_->connect(this, "::", port, 1000);
168  }
AsyncSocket::UniquePtr socket_
Definition: BogoShim.cpp:241
std::shared_ptr< const FizzClientContext > clientContext_
Definition: BogoShim.cpp:243
std::unique_ptr< AsyncSocket, Destructor > UniquePtr
Definition: AsyncSocket.h:83

Member Function Documentation

void BogoTestClient::connectErr ( const AsyncSocketException ex)
inlineoverridevirtualnoexcept

connectErr() will be invoked if the connection attempt fails.

Parameters
exAn exception describing the error that occurred.

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 177 of file BogoShim.cpp.

References folly::INFO, and socket_.

177  {
178  LOG(INFO) << "TCP connect failed: " << ex.what();
179  socket_.reset();
180  success_ = false;
181  }
Optional< bool > success_
Definition: BogoShim.cpp:247
AsyncSocket::UniquePtr socket_
Definition: BogoShim.cpp:241
void BogoTestClient::connectSuccess ( )
inlineoverridevirtualnoexcept

connectSuccess() will be invoked when the connection has been successfully established.

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 170 of file BogoShim.cpp.

References clientContext_, folly::gen::move, folly::none, socket_, string, and transport_.

170  {
173  transport_->connect(
174  this, nullptr, folly::none, std::string("resumption-id"));
175  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AsyncSocket::UniquePtr socket_
Definition: BogoShim.cpp:241
std::unique_ptr< AsyncFizzClientT, folly::DelayedDestruction::Destructor > UniquePtr
std::shared_ptr< const FizzClientContext > clientContext_
Definition: BogoShim.cpp:243
AsyncFizzClientT< ClientStateMachine > AsyncFizzClient
AsyncFizzClient::UniquePtr transport_
Definition: BogoShim.cpp:244
const char * string
Definition: Conv.cpp:212
constexpr None none
Definition: Optional.h:87
void BogoTestClient::fizzHandshakeError ( AsyncFizzClient ,
folly::exception_wrapper  ex 
)
inlineoverridenoexcept

Definition at line 188 of file BogoShim.cpp.

References folly::INFO, and transport_.

190  {
191  LOG(INFO) << "Handshake error: " << ex.what();
192  transport_.reset();
193 
194  // If the server sent us a protocol_version alert assume that
195  if (ex.what().find(
196  "received alert: protocol_version, in state ExpectingServerHello") !=
197  std::string::npos) {
198  unimplemented_ = true;
199  }
200  success_ = false;
201  }
folly::fbstring what() const
bool unimplemented_
Definition: BogoShim.cpp:246
Optional< bool > success_
Definition: BogoShim.cpp:247
size_type find(const basic_fbstring &str, size_type pos=0) const
Definition: FBString.h:1724
AsyncFizzClient::UniquePtr transport_
Definition: BogoShim.cpp:244
void BogoTestClient::fizzHandshakeSuccess ( AsyncFizzClient )
inlineoverridenoexcept

Definition at line 183 of file BogoShim.cpp.

References transport_.

183  {
184  success_ = true;
185  transport_->setReadCB(this);
186  }
Optional< bool > success_
Definition: BogoShim.cpp:247
AsyncFizzClient::UniquePtr transport_
Definition: BogoShim.cpp:244
void BogoTestClient::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 203 of file BogoShim.cpp.

203  {
204  throw std::runtime_error("getReadBuffer not implemented");
205  }
bool BogoTestClient::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 211 of file BogoShim.cpp.

211  {
212  return true;
213  }
void BogoTestClient::readBufferAvailable ( std::unique_ptr< 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 215 of file BogoShim.cpp.

References folly::gen::move, transport_, uint8_t, and fizz::detail::write().

215  {
216  io::Cursor cursor(buf.get());
217  std::unique_ptr<IOBuf> write = IOBuf::create(0);
218  io::Appender appender(write.get(), 50);
219  while (!cursor.isAtEnd()) {
220  uint8_t byte;
221  cursor.pull(&byte, 1);
222  byte ^= 0xff;
223  appender.push(&byte, 1);
224  }
225  transport_->writeChain(nullptr, std::move(write));
226  }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
AsyncFizzClient::UniquePtr transport_
Definition: BogoShim.cpp:244
void BogoTestClient::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 207 of file BogoShim.cpp.

207  {
208  CHECK(false) << "readDataAvailable not implemented";
209  }
void BogoTestClient::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 228 of file BogoShim.cpp.

228 {}
void BogoTestClient::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 230 of file BogoShim.cpp.

230 {}
bool BogoTestClient::success ( ) const
inline

Definition at line 236 of file BogoShim.cpp.

236  {
237  return *success_;
238  }
Optional< bool > success_
Definition: BogoShim.cpp:247
bool BogoTestClient::unimplemented ( ) const
inline

Definition at line 232 of file BogoShim.cpp.

232  {
233  return unimplemented_;
234  }
bool unimplemented_
Definition: BogoShim.cpp:246

Member Data Documentation

std::shared_ptr<const FizzClientContext> BogoTestClient::clientContext_
private

Definition at line 243 of file BogoShim.cpp.

AsyncSocket::UniquePtr BogoTestClient::socket_
private

Definition at line 241 of file BogoShim.cpp.

Optional<bool> BogoTestClient::success_
private

Definition at line 247 of file BogoShim.cpp.

AsyncFizzClient::UniquePtr BogoTestClient::transport_
private

Definition at line 244 of file BogoShim.cpp.

bool BogoTestClient::unimplemented_ {false}
private

Definition at line 246 of file BogoShim.cpp.


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