proxygen
|
#include <BlockingSocket.h>
Public Member Functions | |
BlockingSocket (int fd) | |
BlockingSocket (folly::SocketAddress address, std::shared_ptr< folly::SSLContext > sslContext) | |
BlockingSocket (folly::AsyncSocket::UniquePtr socket) | |
void | enableTFO () |
void | setAddress (folly::SocketAddress address) |
void | open (std::chrono::milliseconds timeout=std::chrono::milliseconds::zero()) |
void | close () |
void | closeWithReset () |
int32_t | write (uint8_t const *buf, size_t len) |
void | flush () |
int32_t | readAll (uint8_t *buf, size_t len) |
int32_t | read (uint8_t *buf, size_t len) |
int | getSocketFD () const |
folly::AsyncSocket * | getSocket () |
folly::AsyncSSLSocket * | getSSLSocket () |
Public Member Functions inherited from folly::AsyncSocket::ConnectCallback | |
virtual | ~ConnectCallback ()=default |
Public 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 |
Public Member Functions inherited from folly::AsyncWriter::WriteCallback | |
virtual | ~WriteCallback ()=default |
Private Member Functions | |
void | connectSuccess () noexceptoverride |
void | connectErr (const folly::AsyncSocketException &ex) noexceptoverride |
void | getReadBuffer (void **bufReturn, size_t *lenReturn) override |
void | readDataAvailable (size_t len) noexceptoverride |
void | readEOF () noexceptoverride |
void | readErr (const folly::AsyncSocketException &ex) noexceptoverride |
void | writeSuccess () noexceptoverride |
void | writeErr (size_t, const folly::AsyncSocketException &ex) noexceptoverride |
int32_t | readHelper (uint8_t *buf, size_t len, bool all) |
Private Attributes | |
folly::EventBase | eventBase_ |
folly::AsyncSocket::UniquePtr | sock_ |
folly::Optional< folly::AsyncSocketException > | err_ |
uint8_t * | readBuf_ {nullptr} |
size_t | readLen_ {0} |
folly::SocketAddress | address_ |
Definition at line 23 of file BlockingSocket.h.
|
inlineexplicit |
Definition at line 27 of file BlockingSocket.h.
|
inline |
Definition at line 30 of file BlockingSocket.h.
|
inlineexplicit |
|
inline |
Definition at line 60 of file BlockingSocket.h.
References sock_.
Referenced by main(), and folly::TEST().
|
inline |
|
inlineoverrideprivatevirtualnoexcept |
connectErr() will be invoked if the connection attempt fails.
ex | An exception describing the error that occurred. |
Implements folly::AsyncSocket::ConnectCallback.
Definition at line 107 of file BlockingSocket.h.
|
inlineoverrideprivatevirtualnoexcept |
connectSuccess() will be invoked when the connection has been successfully established.
Implements folly::AsyncSocket::ConnectCallback.
Definition at line 106 of file BlockingSocket.h.
|
inline |
|
inline |
Definition at line 76 of file BlockingSocket.h.
|
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.)
bufReturn | getReadBuffer() should update *bufReturn to contain the address of the read buffer. This parameter will never be nullptr. |
lenReturn | getReadBuffer() 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 110 of file BlockingSocket.h.
References readBuf_, and readLen_.
|
inline |
|
inline |
|
inline |
|
inline |
Definition at line 51 of file BlockingSocket.h.
References address_, err_, eventBase_, folly::Optional< Value >::hasValue(), folly::EventBase::loop(), sock_, and folly::Optional< Value >::value().
Referenced by main().
Definition at line 82 of file BlockingSocket.h.
References readHelper().
Referenced by main().
Definition at line 78 of file BlockingSocket.h.
References readHelper().
Referenced by folly::TEST().
|
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().
len | The number of bytes placed in the buffer. |
Implements folly::AsyncReader::ReadCallback.
Definition at line 114 of file BlockingSocket.h.
References readBuf_, and readLen_.
|
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 121 of file BlockingSocket.h.
|
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.
ex | An exception describing the error that occurred. |
Implements folly::AsyncReader::ReadCallback.
Definition at line 122 of file BlockingSocket.h.
Definition at line 132 of file BlockingSocket.h.
References folly::Optional< Value >::hasValue(), folly::EventBase::loopOnce(), readBuf_, readLen_, folly::AsyncSocketException::UNKNOWN, and folly::Optional< Value >::value().
Referenced by read(), and readAll().
|
inline |
Definition at line 67 of file BlockingSocket.h.
References err_, eventBase_, folly::Optional< Value >::hasValue(), folly::EventBase::loop(), sock_, and folly::Optional< Value >::value().
Referenced by main(), and folly::TEST().
|
inlineoverrideprivatevirtualnoexcept |
writeError() will be invoked if an error occurs writing the data.
bytesWritten | The number of bytes that were successfull |
ex | An exception describing the error that occurred. |
Implements folly::AsyncWriter::WriteCallback.
Definition at line 126 of file BlockingSocket.h.
|
inlineoverrideprivatevirtualnoexcept |
writeSuccess() will be invoked when all of the data has been successfully written.
Note that this mainly signals that the buffer containing the data to write is no longer needed and may be freed or re-used. It does not guarantee that the data has been fully transmitted to the remote endpoint. For example, on socket-based transports, writeSuccess() only indicates that the data has been given to the kernel for eventual transmission.
Implements folly::AsyncWriter::WriteCallback.
Definition at line 125 of file BlockingSocket.h.
|
private |
Definition at line 104 of file BlockingSocket.h.
Referenced by open(), and setAddress().
|
private |
Definition at line 101 of file BlockingSocket.h.
|
private |
Definition at line 99 of file BlockingSocket.h.
Referenced by BlockingSocket(), open(), and write().
Definition at line 102 of file BlockingSocket.h.
Referenced by getReadBuffer(), readDataAvailable(), and readHelper().
|
private |
Definition at line 103 of file BlockingSocket.h.
Referenced by getReadBuffer(), readDataAvailable(), and readHelper().
|
private |
Definition at line 100 of file BlockingSocket.h.
Referenced by BlockingSocket(), close(), closeWithReset(), enableTFO(), getSocket(), getSocketFD(), getSSLSocket(), open(), and write().