proxygen
|
#include <AsyncSocket.h>
Classes | |
class | BytesWriteRequest |
class | ConnectCallback |
class | ErrMessageCallback |
class | EvbChangeCallback |
class | ImmediateReadCB |
struct | IOBufInfo |
class | IoHandler |
class | OptionKey |
struct | ReadResult |
class | SendMsgParamsCallback |
class | WriteRequest |
struct | WriteResult |
class | WriteTimeout |
Public Types | |
enum | StateEnum : uint8_t { StateEnum::UNINIT, StateEnum::CONNECTING, StateEnum::ESTABLISHED, StateEnum::CLOSED, StateEnum::ERROR, StateEnum::FAST_OPEN } |
typedef std::unique_ptr< AsyncSocket, Destructor > | UniquePtr |
typedef std::map< OptionKey, int > | OptionMap |
Public Types inherited from folly::AsyncTransportWrapper | |
using | UniquePtr = std::unique_ptr< AsyncTransportWrapper, Destructor > |
using | ReadCallback = AsyncReader::ReadCallback |
using | WriteCallback = AsyncWriter::WriteCallback |
Public Types inherited from folly::AsyncTransport | |
typedef std::unique_ptr< AsyncTransport, Destructor > | UniquePtr |
Public Member Functions | |
AsyncSocket () | |
AsyncSocket (EventBase *evb) | |
void | setShutdownSocketSet (const std::weak_ptr< ShutdownSocketSet > &wSS) |
AsyncSocket (EventBase *evb, const folly::SocketAddress &address, uint32_t connectTimeout=0) | |
AsyncSocket (EventBase *evb, const std::string &ip, uint16_t port, uint32_t connectTimeout=0) | |
AsyncSocket (EventBase *evb, int fd, uint32_t zeroCopyBufId=0) | |
AsyncSocket (AsyncSocket::UniquePtr) | |
void | destroy () override |
EventBase * | getEventBase () const override |
virtual int | getFd () const |
virtual int | detachFd () |
virtual void | connect (ConnectCallback *callback, const folly::SocketAddress &address, int timeout=0, const OptionMap &options=emptyOptionMap, const folly::SocketAddress &bindAddr=anyAddress()) noexcept |
void | connect (ConnectCallback *callback, const std::string &ip, uint16_t port, int timeout=0, const OptionMap &options=emptyOptionMap) noexcept |
void | cancelConnect () |
void | setSendTimeout (uint32_t milliseconds) override |
uint32_t | getSendTimeout () const override |
void | setMaxReadsPerEvent (uint16_t maxReads) |
uint16_t | getMaxReadsPerEvent () const |
virtual void | setErrMessageCB (ErrMessageCallback *callback) |
virtual ErrMessageCallback * | getErrMessageCallback () const |
virtual void | setSendMsgParamCB (SendMsgParamsCallback *callback) |
virtual SendMsgParamsCallback * | getSendMsgParamsCB () const |
void | setReadCB (ReadCallback *callback) override |
ReadCallback * | getReadCallback () const override |
bool | setZeroCopy (bool enable) |
bool | getZeroCopy () const |
uint32_t | getZeroCopyBufId () const |
size_t | getZeroCopyReenableThreshold () const |
void | setZeroCopyReenableThreshold (size_t threshold) |
void | write (WriteCallback *callback, const void *buf, size_t bytes, WriteFlags flags=WriteFlags::NONE) override |
void | writev (WriteCallback *callback, const iovec *vec, size_t count, WriteFlags flags=WriteFlags::NONE) override |
void | writeChain (WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags=WriteFlags::NONE) override |
virtual void | writeRequest (WriteRequest *req) |
void | writeRequestReady () |
void | close () override |
void | closeNow () override |
void | closeWithReset () override |
void | shutdownWrite () override |
void | shutdownWriteNow () override |
bool | readable () const override |
bool | writable () const override |
bool | isPending () const override |
virtual bool | hangup () const |
bool | good () const override |
bool | error () const override |
void | attachEventBase (EventBase *eventBase) override |
void | detachEventBase () override |
bool | isDetachable () const override |
void | getLocalAddress (folly::SocketAddress *address) const override |
void | getPeerAddress (folly::SocketAddress *address) const override |
bool | isEorTrackingEnabled () const override |
void | setEorTracking (bool track) override |
bool | connecting () const override |
virtual bool | isClosedByPeer () const |
virtual bool | isClosedBySelf () const |
size_t | getAppBytesWritten () const override |
size_t | getRawBytesWritten () const override |
size_t | getAppBytesReceived () const override |
size_t | getRawBytesReceived () const override |
std::chrono::nanoseconds | getConnectTime () const |
std::chrono::milliseconds | getConnectTimeout () const |
std::chrono::steady_clock::time_point | getConnectStartTime () const |
std::chrono::steady_clock::time_point | getConnectEndTime () const |
bool | getTFOAttempted () const |
bool | getTFOFinished () const |
bool | getTFOSucceded () const |
int | setNoDelay (bool noDelay) |
void | setCloseOnExec () |
int | setCongestionFlavor (const std::string &cname) |
int | setQuickAck (bool quickack) |
int | setSendBufSize (size_t bufsize) |
int | setRecvBufSize (size_t bufsize) |
int | setTCPProfile (int profd) |
template<typename T > | |
int | getSockOpt (int level, int optname, T *optval, socklen_t *optlen) |
template<typename T > | |
int | setSockOpt (int level, int optname, const T *optval) |
virtual int | getSockOptVirtual (int level, int optname, void *optval, socklen_t *optlen) |
virtual int | setSockOptVirtual (int level, int optname, void const *optval, socklen_t optlen) |
virtual void | setPreReceivedData (std::unique_ptr< IOBuf > data) |
void | enableTFO () |
void | disableTransparentTls () |
void | disableTSocks () |
void | setBufferCallback (BufferCallback *cb) |
void | setEvbChangedCallback (std::unique_ptr< EvbChangeCallback > cb) |
void | cacheAddresses () |
bool | isZeroCopyWriteInProgress () const noexcept |
bool | processZeroCopyWriteInProgress () noexcept |
void | setPeerCertificate (std::unique_ptr< const AsyncTransportCertificate > cert) |
const AsyncTransportCertificate * | getPeerCertificate () const override |
void | setSelfCertificate (std::unique_ptr< const AsyncTransportCertificate > cert) |
const AsyncTransportCertificate * | getSelfCertificate () const override |
Public Member Functions inherited from folly::AsyncTransportWrapper | |
virtual const AsyncTransportWrapper * | getWrappedTransport () const |
template<class T > | |
const T * | getUnderlyingTransport () const |
template<class T > | |
T * | getUnderlyingTransport () |
Public Member Functions inherited from folly::AsyncTransport | |
SocketAddress | getLocalAddress () const |
void | getAddress (SocketAddress *address) const override |
SocketAddress | getPeerAddress () const |
virtual ssl::X509UniquePtr | getPeerCert () const |
virtual const X509 * | getSelfCert () const |
virtual std::string | getApplicationProtocol () const noexcept |
virtual std::string | getSecurityProtocol () const |
virtual bool | isReplaySafe () const |
virtual void | setReplaySafetyCallback (ReplaySafetyCallback *callback) |
Public Member Functions inherited from folly::DelayedDestruction | |
bool | getDestroyPending () const |
Public Member Functions inherited from folly::DelayedDestructionBase | |
virtual | ~DelayedDestructionBase ()=default |
Public Member Functions inherited from folly::AsyncSocketBase | |
virtual | ~AsyncSocketBase ()=default |
Static Public Member Functions | |
static std::shared_ptr< AsyncSocket > | newSocket (EventBase *evb) |
static std::shared_ptr< AsyncSocket > | newSocket (EventBase *evb, const folly::SocketAddress &address, uint32_t connectTimeout=0) |
static std::shared_ptr< AsyncSocket > | newSocket (EventBase *evb, const std::string &ip, uint16_t port, uint32_t connectTimeout=0) |
static std::shared_ptr< AsyncSocket > | newSocket (EventBase *evb, int fd) |
static const folly::SocketAddress & | anyAddress () |
Static Public Attributes | |
static const OptionMap | emptyOptionMap |
Protected Types | |
enum | ReadResultEnum { READ_EOF = 0, READ_ERROR = -1, READ_BLOCKING = -2, READ_NO_ERROR = -3 } |
enum | WriteResultEnum { WRITE_ERROR = -1 } |
enum | ShutdownFlags { SHUT_WRITE_PENDING = 0x01, SHUT_WRITE = 0x02, SHUT_READ = 0x04 } |
Protected Member Functions | |
~AsyncSocket () override | |
void | init () |
void | scheduleImmediateRead () noexcept |
void | scheduleInitialReadWrite () noexcept |
void | ioReady (uint16_t events) noexcept |
virtual void | checkForImmediateRead () noexcept |
virtual void | handleInitialReadWrite () noexcept |
virtual void | prepareReadBuffer (void **buf, size_t *buflen) |
virtual size_t | handleErrMessages () noexcept |
virtual void | handleRead () noexcept |
virtual void | handleWrite () noexcept |
virtual void | handleConnect () noexcept |
void | timeoutExpired () noexcept |
virtual ReadResult | performRead (void **buf, size_t *buflen, size_t *offset) |
void | writeChainImpl (WriteCallback *callback, iovec *vec, size_t count, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags) |
void | writeImpl (WriteCallback *callback, const iovec *vec, size_t count, std::unique_ptr< folly::IOBuf > &&buf, WriteFlags flags=WriteFlags::NONE) |
virtual WriteResult | performWrite (const iovec *vec, uint32_t count, WriteFlags flags, uint32_t *countWritten, uint32_t *partialWritten) |
AsyncSocket::WriteResult | sendSocketMessage (int fd, struct msghdr *msg, int msg_flags) |
virtual ssize_t | tfoSendMsg (int fd, struct msghdr *msg, int msg_flags) |
int | socketConnect (const struct sockaddr *addr, socklen_t len) |
virtual void | scheduleConnectTimeout () |
void | registerForConnectEvents () |
bool | updateEventRegistration () |
bool | updateEventRegistration (uint16_t enable, uint16_t disable) |
void | doClose () |
void | startFail () |
void | finishFail () |
void | finishFail (const AsyncSocketException &ex) |
void | invokeAllErrors (const AsyncSocketException &ex) |
void | fail (const char *fn, const AsyncSocketException &ex) |
void | failConnect (const char *fn, const AsyncSocketException &ex) |
void | failRead (const char *fn, const AsyncSocketException &ex) |
void | failErrMessageRead (const char *fn, const AsyncSocketException &ex) |
void | failWrite (const char *fn, WriteCallback *callback, size_t bytesWritten, const AsyncSocketException &ex) |
void | failWrite (const char *fn, const AsyncSocketException &ex) |
void | failAllWrites (const AsyncSocketException &ex) |
virtual void | invokeConnectErr (const AsyncSocketException &ex) |
virtual void | invokeConnectSuccess () |
void | invalidState (ConnectCallback *callback) |
void | invalidState (ErrMessageCallback *callback) |
void | invalidState (ReadCallback *callback) |
void | invalidState (WriteCallback *callback) |
std::string | withAddr (const std::string &s) |
void | cacheLocalAddress () const |
void | cachePeerAddress () const |
bool | isZeroCopyRequest (WriteFlags flags) |
bool | isZeroCopyMsg (const cmsghdr &cmsg) const |
void | processZeroCopyMsg (const cmsghdr &cmsg) |
uint32_t | getNextZeroCopyBufId () |
void | adjustZeroCopyFlags (folly::WriteFlags &flags) |
void | addZeroCopyBuf (std::unique_ptr< folly::IOBuf > &&buf) |
void | addZeroCopyBuf (folly::IOBuf *ptr) |
void | setZeroCopyBuf (std::unique_ptr< folly::IOBuf > &&buf) |
bool | containsZeroCopyBuf (folly::IOBuf *ptr) |
void | releaseZeroCopyBuf (uint32_t id) |
Protected Member Functions inherited from folly::AsyncTransport | |
~AsyncTransport () override=default | |
Protected Member Functions inherited from folly::DelayedDestruction | |
~DelayedDestruction () override=default | |
DelayedDestruction () | |
Protected Member Functions inherited from folly::DelayedDestructionBase | |
DelayedDestructionBase () | |
uint32_t | getDestructorGuardCount () const |
Protected Member Functions inherited from folly::AsyncReader | |
virtual | ~AsyncReader ()=default |
Protected Member Functions inherited from folly::AsyncWriter | |
virtual | ~AsyncWriter ()=default |
Friends | |
std::ostream & | operator<< (std::ostream &os, const StateEnum &state) |
A class for performing asynchronous I/O on a socket.
AsyncSocket allows users to asynchronously wait for data on a socket, and to asynchronously send data.
The APIs for reading and writing are intentionally asymmetric. Waiting for data to read is a persistent API: a callback is installed, and is notified whenever new data is available. It continues to be notified of new events until it is uninstalled.
AsyncSocket does not provide read timeout functionality, because it typically cannot determine when the timeout should be active. Generally, a timeout should only be enabled when processing is blocked waiting on data from the remote endpoint. For server sockets, the timeout should not be active if the server is currently processing one or more outstanding requests for this socket. For client sockets, the timeout should not be active if there are no requests pending on the socket. Additionally, if a client has multiple pending requests, it will ususally want a separate timeout for each request, rather than a single read timeout.
The write API is fairly intuitive: a user can request to send a block of data, and a callback will be informed once the entire block has been transferred to the kernel, or on error. AsyncSocket does provide a send timeout, since most callers want to give up if the remote end stops responding and no further progress can be made sending the data.
Definition at line 81 of file AsyncSocket.h.
typedef std::map<OptionKey, int> folly::AsyncSocket::OptionMap |
Definition at line 376 of file AsyncSocket.h.
typedef std::unique_ptr<AsyncSocket, Destructor> folly::AsyncSocket::UniquePtr |
Definition at line 83 of file AsyncSocket.h.
|
protected |
Enumerator | |
---|---|
READ_EOF | |
READ_ERROR | |
READ_BLOCKING | |
READ_NO_ERROR |
Definition at line 940 of file AsyncSocket.h.
|
protected |
Enumerator | |
---|---|
SHUT_WRITE_PENDING |
shutdownWrite() called, but we are still waiting on writes to drain |
SHUT_WRITE |
writes have been completely shut down |
SHUT_READ |
Reads have been shutdown. At the moment we don't distinguish between remote read shutdown (received EOF from the remote end) and local read shutdown. We can only receive EOF when a read callback is set, and we immediately inform it of the EOF. Therefore there doesn't seem to be any reason to have a separate state of "received EOF but the local side may still want to read". We also don't currently provide any API for only shutting down the read side of a socket. (This is a no-op as far as TCP is concerned, anyway.) |
Definition at line 962 of file AsyncSocket.h.
|
strong |
Enumerator | |
---|---|
UNINIT | |
CONNECTING | |
ESTABLISHED | |
CLOSED | |
ERROR | |
FAST_OPEN |
Definition at line 797 of file AsyncSocket.h.
|
protected |
Enumerator | |
---|---|
WRITE_ERROR |
Definition at line 947 of file AsyncSocket.h.
|
explicit |
Definition at line 277 of file AsyncSocket.cpp.
References init().
Referenced by folly::AsyncSocket::SendMsgParamsCallback::getFlagsImpl(), and newSocket().
|
explicit |
Create a new unconnected AsyncSocket.
connect() must later be called on this socket to establish a connection.
Definition at line 286 of file AsyncSocket.cpp.
References init().
folly::AsyncSocket::AsyncSocket | ( | EventBase * | evb, |
const folly::SocketAddress & | address, | ||
uint32_t | connectTimeout = 0 |
||
) |
Create a new AsyncSocket and begin the connection process.
evb | EventBase that will manage this socket. |
address | The address to connect to. |
connectTimeout | Optional timeout in milliseconds for the connection attempt. |
Definition at line 295 of file AsyncSocket.cpp.
References connect().
folly::AsyncSocket::AsyncSocket | ( | EventBase * | evb, |
const std::string & | ip, | ||
uint16_t | port, | ||
uint32_t | connectTimeout = 0 |
||
) |
Create a new AsyncSocket and begin the connection process.
evb | EventBase that will manage this socket. |
ip | IP address to connect to (dotted-quad). |
port | Destination port in host byte order. |
connectTimeout | Optional timeout in milliseconds for the connection attempt. |
Definition at line 303 of file AsyncSocket.cpp.
References connect().
Create a AsyncSocket from an already connected socket file descriptor.
Note that while AsyncSocket enables TCP_NODELAY for sockets it creates when connecting, it does not change the socket options when given an existing file descriptor. If callers want TCP_NODELAY enabled when using this version of the constructor, they need to explicitly call setNoDelay(true) after the constructor returns.
evb | EventBase that will manage this socket. |
fd | File descriptor to take over (should be a connected socket). |
zeroCopyBufId | Zerocopy buf id to start with. |
Definition at line 312 of file AsyncSocket.cpp.
References ESTABLISHED, fd_, init(), noTransparentTls_, noTSocks_, setCloseOnExec(), and state_.
|
explicit |
Create an AsyncSocket from a different, already connected AsyncSocket.
Similar to AsyncSocket(evb, fd) when fd was previously owned by an AsyncSocket.
Definition at line 327 of file AsyncSocket.cpp.
References folly::gen::move, and preReceivedData_.
|
overrideprotected |
Protected destructor.
Users of AsyncSocket must never delete it directly. Instead, invoke destroy() instead. (See the documentation in DelayedDestruction.h for more details.)
Definition at line 358 of file AsyncSocket.cpp.
References eventBase_, fd_, and state_.
|
protected |
Definition at line 924 of file AsyncSocket.cpp.
References getNextZeroCopyBufId(), idZeroCopyBufInfoMap_, idZeroCopyBufPtrMap_, folly::gen::move, ptr, and uint32_t.
Referenced by getNextZeroCopyBufId(), folly::AsyncSocket::BytesWriteRequest::performWrite(), and writeImpl().
|
protected |
Definition at line 935 of file AsyncSocket.cpp.
References getNextZeroCopyBufId(), idZeroCopyBufInfoMap_, idZeroCopyBufPtrMap_, ptr, and uint32_t.
|
protected |
Definition at line 909 of file AsyncSocket.cpp.
References folly::unSet(), folly::WRITE_MSG_ZEROCOPY, zeroCopyEnabled_, and zeroCopyReenableCounter_.
Referenced by getNextZeroCopyBufId(), folly::AsyncSocket::BytesWriteRequest::performWrite(), and writeChain().
|
static |
Definition at line 394 of file AsyncSocket.cpp.
Referenced by connect(), folly::AsyncSSLSocket::getSecurityProtocol(), main(), and proxygen::HTTPConnector::Callback::~Callback().
|
overridevirtual |
Attach the transport to a EventBase.
This may only be called if the transport is not currently attached to a EventBase (by an earlier call to detachEventBase()).
This method must be invoked in the EventBase's thread.
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1500 of file AsyncSocket.cpp.
References folly::EventHandler::attachEventBase(), folly::AsyncTimeout::attachEventBase(), folly::EventBase::dcheckIsInEventBaseThread(), evbChangeCb_, eventBase_, eventFlags_, fd_, ioHandler_, state_, updateEventRegistration(), and writeTimeout_.
Referenced by folly::AsyncSSLSocket::attachEventBase(), and writeRequestReady().
void folly::AsyncSocket::cacheAddresses | ( | ) |
Attempt to cache the current local and peer addresses (if not already cached) so that they are available from getPeerAddress() and getLocalAddress() even after the socket is closed.
Definition at line 1544 of file AsyncSocket.cpp.
References cacheLocalAddress(), cachePeerAddress(), and fd_.
Referenced by setEvbChangedCallback(), folly::AsyncSSLSocket::sslAccept(), and folly::AsyncSSLSocket::sslConn().
|
protected |
Definition at line 1558 of file AsyncSocket.cpp.
References fd_, folly::SocketAddress::isInitialized(), localAddr_, and folly::SocketAddress::setFromLocalAddress().
Referenced by cacheAddresses(), getLocalAddress(), scheduleInitialReadWrite(), and setErrMessageCB().
|
protected |
Definition at line 1564 of file AsyncSocket.cpp.
References addr_, fd_, folly::SocketAddress::isInitialized(), and folly::SocketAddress::setFromPeerAddress().
Referenced by cacheAddresses(), getPeerAddress(), and scheduleInitialReadWrite().
void folly::AsyncSocket::cancelConnect | ( | ) |
If a connect request is in-flight, cancels it and closes the socket immediately. Otherwise, this is a no-op.
This does not invoke any connection related callbacks. Call this to prevent any connect callback while cleaning up, etc.
Definition at line 659 of file AsyncSocket.cpp.
References closeNow(), connectCallback_, CONNECTING, FAST_OPEN, and state_.
|
protectedvirtualnoexcept |
Reimplemented in AsyncSocketImmediateRead, and folly::AsyncSSLSocket.
Definition at line 2147 of file AsyncSocket.cpp.
References handleRead(), and preReceivedData_.
Referenced by folly::AsyncSSLSocket::checkForImmediateRead(), handleInitialReadWrite(), scheduleInitialReadWrite(), and setReadCB().
|
overridevirtual |
Close the transport.
This gracefully closes the transport, waiting for all pending write requests to complete before actually closing the underlying transport.
If a read callback is set, readEOF() will be called immediately. If there are outstanding write requests, the close will be delayed until all remaining writes have completed. No new writes may be started after close() has been called.
Implements folly::AsyncTransport.
Definition at line 1198 of file AsyncSocket.cpp.
References closeNow(), CONNECTING, folly::EventBase::dcheckIsInEventBaseThread(), ERROR, ESTABLISHED, eventBase_, fd_, folly::EventHandler::READ, readCallback_, folly::AsyncReader::ReadCallback::readEOF(), SHUT_READ, SHUT_WRITE_PENDING, shutdownFlags_, state_, updateEventRegistration(), and writeReqHead_.
Referenced by doClose(), folly::AsyncSSLSocket::shutdownWrite(), TEST(), and writeRequestReady().
|
overridevirtual |
Close the transport immediately.
This closes the transport immediately, dropping any outstanding data waiting to be written.
If a read callback is set, readEOF() will be called immediately. If there are outstanding write requests, these requests will be aborted and writeError() will be invoked immediately on all outstanding write callbacks.
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1252 of file AsyncSocket.cpp.
References folly::EventBase::LoopCallback::cancelLoopCallback(), folly::AsyncTimeout::cancelTimeout(), folly::EventHandler::changeHandlerFD(), CLOSED, connectCallback_, CONNECTING, folly::EventBase::dcheckIsInEventBaseThread(), folly::DFATAL, doClose(), ERROR, ESTABLISHED, eventBase_, eventFlags_, failAllWrites(), FAST_OPEN, fd_, immediateReadHandler_, invokeConnectErr(), ioHandler_, folly::EventBase::LoopCallback::isLoopCallbackScheduled(), folly::EventHandler::NONE, readCallback_, folly::AsyncReader::ReadCallback::readEOF(), SHUT_READ, SHUT_WRITE, shutdownFlags_, folly::socketClosedLocallyEx, state_, UNINIT, updateEventRegistration(), writeReqHead_, and writeTimeout_.
Referenced by cancelConnect(), close(), folly::AsyncSSLSocket::closeNow(), closeWithReset(), folly::test::MockAsyncSocket::connect(), destroy(), detachFd(), shutdownWriteNow(), and writeRequestReady().
|
overridevirtual |
Reset the transport immediately.
This closes the transport immediately, sending a reset to the remote peer if possible to indicate abnormal shutdown.
Note that not all subclasses implement this reset functionality: some subclasses may treat reset() the same as closeNow(). Subclasses that use TCP transports should terminate the connection with a TCP reset.
Reimplemented from folly::AsyncTransport.
Definition at line 1324 of file AsyncSocket.cpp.
References closeNow(), fd_, and setSockOpt().
Referenced by writeRequestReady().
|
virtualnoexcept |
Initiate a connection.
callback | The callback to inform when the connection attempt completes. |
address | The address to connect to. |
timeout | A timeout value, in milliseconds. If the connection does not succeed within this period, callback->connectError() will be invoked. |
Reimplemented in folly::AsyncSSLSocket, folly::test::MockAsyncSSLSocket, and folly::test::MockAsyncSocket.
Definition at line 431 of file AsyncSocket.cpp.
References folly::ShutdownSocketSet::add(), addr_, anyAddress(), folly::netops::bind(), folly::EventHandler::changeHandlerFD(), connectCallback_, connectEndTime_, CONNECTING, connectStartTime_, connectTimeout_, folly::EventBase::dcheckIsInEventBaseThread(), doClose(), errMessageCallback_, ESTABLISHED, eventBase_, failConnect(), FAST_OPEN, fd_, folly::SocketAddress::getActualSize(), folly::AsyncSocketException::INTERNAL_ERROR, invalidState(), invokeConnectSuccess(), ioHandler_, name, folly::AsyncSocketException::NOT_OPEN, noTransparentTls_, noTSocks_, now(), readCallback_, setCloseOnExec(), setNoDelay(), folly::netops::setsockopt(), setZeroCopy(), folly::test::shutdownSocketSet, folly::netops::socket(), socketConnect(), state_, tfoAttempted_, tfoEnabled_, folly::detail::timeout, UNINIT, withAddr(), writeReqHead_, wShutdownSocketSet_, and zeroCopyVal_.
Referenced by AsyncSocket(), folly::AsyncSSLSocket::connect(), connect(), folly::AsyncSSLSocket::getSecurityProtocol(), SSLCacheClient::start(), and TEST().
|
noexcept |
Definition at line 643 of file AsyncSocket.cpp.
References connect(), connectCallback_, failConnect(), folly::AsyncSocketException::INTERNAL_ERROR, and folly::detail::timeout.
|
inlineoverridevirtual |
Determine if transport is connected to the endpoint
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 567 of file AsyncSocket.h.
References CONNECTING, and state_.
Referenced by folly::AsyncSSLSocket::connecting(), and writeImpl().
|
protected |
Definition at line 963 of file AsyncSocket.cpp.
References idZeroCopyBufInfoMap_.
Referenced by getNextZeroCopyBufId(), and folly::AsyncSocket::BytesWriteRequest::performWrite().
|
overridevirtual |
Destroy the socket.
AsyncSocket::destroy() must be called to destroy the socket. The normal destructor is private, and should not be invoked directly. This prevents callers from deleting a AsyncSocket while it is invoking a callback.
Reimplemented from folly::DelayedDestruction.
Definition at line 364 of file AsyncSocket.cpp.
References closeNow(), folly::DelayedDestruction::destroy(), eventBase_, fd_, and state_.
Referenced by newSocket(), SSLCacheClient::start(), folly::AsyncSocket::WriteRequest::start(), and SSLCacheClient::~SSLCacheClient().
|
overridevirtual |
Detach the transport from its EventBase.
This may only be called when the transport is idle and has no reads or writes pending. Once detached, the transport may not be used again until it is re-attached to a EventBase by calling attachEventBase().
This method must be called from the current EventBase's thread.
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1519 of file AsyncSocket.cpp.
References folly::EventBase::dcheckIsInEventBaseThread(), folly::EventHandler::detachEventBase(), folly::AsyncTimeout::detachEventBase(), evbChangeCb_, eventBase_, eventFlags_, fd_, ioHandler_, state_, folly::EventHandler::unregisterHandler(), and writeTimeout_.
Referenced by folly::AsyncSSLSocket::detachEventBase(), and writeRequestReady().
|
virtual |
Extract the file descriptor from the AsyncSocket.
This will immediately cause any installed callbacks to be invoked with an error. The AsyncSocket may no longer be used after the file descriptor has been extracted.
This method should be used with care as the resulting fd is not guaranteed to perfectly reflect the state of the AsyncSocket (security state, pre-received data, etc.).
Returns the file descriptor. The caller assumes ownership of the descriptor, and it will not be closed when the AsyncSocket is destroyed.
Definition at line 375 of file AsyncSocket.cpp.
References folly::EventHandler::changeHandlerFD(), closeNow(), eventBase_, eventFlags_, fd_, ioHandler_, state_, and wShutdownSocketSet_.
Referenced by folly::test::MockAsyncSocket::connect(), SSLCacheClient::connectSuccess(), and getFd().
|
inline |
Definition at line 789 of file AsyncSocket.h.
References noTransparentTls_.
Referenced by fizz::client::AsyncFizzClientT< SM >::connect().
|
inline |
|
protected |
Definition at line 2790 of file AsyncSocket.cpp.
References folly::ShutdownSocketSet::close(), close(), fd_, idZeroCopyBufInfoMap_, idZeroCopyBufPtrMap_, folly::test::shutdownSocketSet, and wShutdownSocketSet_.
Referenced by closeNow(), connect(), handleWrite(), scheduleInitialReadWrite(), and startFail().
|
inline |
Enables TFO behavior on the AsyncSocket if FOLLY_ALLOW_TFO is set.
Definition at line 782 of file AsyncSocket.h.
References tfoEnabled_.
|
overridevirtual |
Determine if an error has occurred with this transport.
Implements folly::AsyncTransport.
Definition at line 1496 of file AsyncSocket.cpp.
Referenced by handleConnect(), folly::AsyncSSLSocket::handleInitialReadWrite(), and writeRequestReady().
|
protected |
Definition at line 2569 of file AsyncSocket.cpp.
References addr_, folly::SocketAddress::describe(), fd_, finishFail(), startFail(), and state_.
Referenced by gtest_xml_test_utils.GTestXMLTestCase::_GetChildren(), fatal_test.FatalTests::is_debug_build(), scheduleInitialReadWrite(), and updateEventRegistration().
|
protected |
Definition at line 2661 of file AsyncSocket.cpp.
References folly::AsyncSocket::WriteRequest::destroy(), folly::AsyncSocket::WriteRequest::getCallback(), folly::AsyncSocket::WriteRequest::getNext(), folly::AsyncSocket::WriteRequest::getTotalBytesWritten(), folly::AsyncWriter::WriteCallback::writeErr(), and writeReqHead_.
Referenced by closeNow(), invokeAllErrors(), scheduleInitialReadWrite(), and shutdownWriteNow().
|
protected |
Definition at line 2577 of file AsyncSocket.cpp.
References addr_, folly::SocketAddress::describe(), fd_, finishFail(), invokeConnectErr(), startFail(), and state_.
Referenced by connect(), handleConnect(), scheduleInitialReadWrite(), and timeoutExpired().
|
protected |
Definition at line 2602 of file AsyncSocket.cpp.
References addr_, folly::SocketAddress::describe(), errMessageCallback_, folly::AsyncSocket::ErrMessageCallback::errMessageError(), fd_, finishFail(), startFail(), and state_.
Referenced by handleErrMessages(), and scheduleInitialReadWrite().
|
protected |
Definition at line 2587 of file AsyncSocket.cpp.
References addr_, folly::SocketAddress::describe(), fd_, finishFail(), readCallback_, folly::AsyncReader::ReadCallback::readErr(), startFail(), and state_.
Referenced by handleRead(), and scheduleInitialReadWrite().
|
protected |
Definition at line 2642 of file AsyncSocket.cpp.
References addr_, folly::SocketAddress::describe(), fd_, finishFail(), startFail(), state_, and folly::AsyncWriter::WriteCallback::writeErr().
Referenced by handleWrite(), scheduleInitialReadWrite(), setSendTimeout(), timeoutExpired(), and writeImpl().
|
protected |
Definition at line 2619 of file AsyncSocket.cpp.
References addr_, folly::SocketAddress::describe(), folly::AsyncSocket::WriteRequest::destroy(), fd_, finishFail(), folly::AsyncSocket::WriteRequest::getCallback(), folly::AsyncSocket::WriteRequest::getNext(), folly::AsyncSocket::WriteRequest::getTotalBytesWritten(), startFail(), state_, uint32_t, folly::AsyncWriter::WriteCallback::writeErr(), and writeReqHead_.
|
protected |
Definition at line 2553 of file AsyncSocket.cpp.
References ERROR, folly::DelayedDestructionBase::getDestructorGuardCount(), folly::AsyncSocketException::INTERNAL_ERROR, invokeAllErrors(), state_, and withAddr().
Referenced by fail(), failConnect(), failErrMessageRead(), folly::AsyncSSLSocket::failHandshake(), failRead(), failWrite(), invalidState(), and scheduleInitialReadWrite().
|
protected |
Definition at line 2563 of file AsyncSocket.cpp.
References ERROR, folly::DelayedDestructionBase::getDestructorGuardCount(), invokeAllErrors(), and state_.
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 591 of file AsyncSocket.h.
References appBytesReceived_.
Referenced by getRawBytesReceived().
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 583 of file AsyncSocket.h.
References appBytesWritten_.
Referenced by getRawBytesWritten().
|
inline |
Definition at line 611 of file AsyncSocket.h.
References connectEndTime_.
|
inline |
Definition at line 607 of file AsyncSocket.h.
References connectStartTime_.
|
inline |
Definition at line 599 of file AsyncSocket.h.
References connectEndTime_, and connectStartTime_.
|
inline |
Definition at line 603 of file AsyncSocket.h.
References connectTimeout_.
|
virtual |
Get a pointer to ErrMessageCallback implementation currently registered with this socket.
Definition at line 756 of file AsyncSocket.cpp.
References errMessageCallback_.
Referenced by getMaxReadsPerEvent().
|
inlineoverridevirtual |
Get the EventBase used by this socket.
Implements folly::AsyncSocketBase.
Definition at line 328 of file AsyncSocket.h.
References eventBase_.
Referenced by folly::HandshakeTimeoutCallback::connAccepted(), folly::TestSSLAsyncCacheServer::getSessionCallback(), and tmpDisableReads().
|
inlinevirtual |
Get the file descriptor used by the AsyncSocket.
Definition at line 335 of file AsyncSocket.h.
References detachFd(), and fd_.
Referenced by folly::SSLServerAcceptCallbackDelay::connAccepted(), folly::test::MockAsyncSocket::connect(), wangle::SSLSessionCacheManager::getSession(), wangle::TransportInfo::readRTT(), and folly::AsyncSSLSocket::sslAccept().
|
overridevirtual |
Get the address of the local endpoint of this transport.
This function may throw AsyncSocketException on error.
address | The local address will be stored in the specified SocketAddress. |
Implements folly::AsyncTransport.
Definition at line 1575 of file AsyncSocket.cpp.
References cacheLocalAddress(), and localAddr_.
|
inline |
Get the maximum number of reads this object will execute from the underlying socket each time the EventBase detects that new ingress data is available.
Definition at line 463 of file AsyncSocket.h.
References getErrMessageCallback(), getReadCallback(), getSendMsgParamsCB(), maxReadsPerEvent_, setErrMessageCB(), setReadCB(), setSendMsgParamCB(), and setZeroCopy().
|
inlineprotected |
Definition at line 1202 of file AsyncSocket.h.
References addZeroCopyBuf(), adjustZeroCopyFlags(), containsZeroCopyBuf(), ptr, releaseZeroCopyBuf(), setZeroCopyBuf(), uint32_t, and zeroCopyBufId_.
Referenced by addZeroCopyBuf().
|
overridevirtual |
Get the address of the remote endpoint to which this transport is connected.
This function may throw AsyncSocketException on error.
address | The remote endpoint's address will be stored in the specified SocketAddress. |
Implements folly::AsyncTransport.
Definition at line 1580 of file AsyncSocket.cpp.
References addr_, and cachePeerAddress().
|
inlineoverridevirtual |
Get the peer certificate information if any
Reimplemented from folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 837 of file AsyncSocket.h.
References peerCertData_.
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 595 of file AsyncSocket.h.
References getAppBytesReceived().
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 587 of file AsyncSocket.h.
References getAppBytesWritten().
Referenced by folly::test::MockAsyncSocket::connect().
|
overridevirtual |
Implements folly::AsyncTransportWrapper.
Definition at line 856 of file AsyncSocket.cpp.
References readCallback_.
Referenced by getMaxReadsPerEvent(), and wangle::SocketPeeker::~SocketPeeker().
|
inlineoverridevirtual |
Get the certificate information of this transport, if any
Reimplemented from folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 846 of file AsyncSocket.h.
References selfCertData_.
|
virtual |
Get a pointer to SendMsgParamsCallback implementation currently registered with this socket.
Definition at line 764 of file AsyncSocket.cpp.
References sendMsgParamCallback_.
Referenced by getMaxReadsPerEvent().
|
inlineoverridevirtual |
Get the send timeout.
Implements folly::AsyncTransport.
Definition at line 437 of file AsyncSocket.h.
References sendTimeout_.
|
inline |
Generic API for reading a socket option.
level | same as the "level" parameter in getsockopt(). |
optname | same as the "optname" parameter in getsockopt(). |
optval | pointer to the variable in which the option value should be returned. |
optlen | value-result argument, initially containing the size of the buffer pointed to by optval, and modified on return to indicate the actual size of the value returned. |
Definition at line 714 of file AsyncSocket.h.
References fd_, and folly::netops::getsockopt().
|
inlinevirtual |
Virtual method for reading a socket option returning integer value, which is the most typical case. Convenient for overriding and mocking.
level | same as the "level" parameter in getsockopt(). |
optname | same as the "optname" parameter in getsockopt(). |
optval | same as "optval" parameter in getsockopt(). |
optlen | same as "optlen" parameter in getsockopt(). |
Definition at line 743 of file AsyncSocket.h.
References fd_, and folly::netops::getsockopt().
|
inline |
|
inline |
Returns whether or not the attempt to use TFO finished successfully. This does not necessarily mean TFO worked, just that trying to use TFO succeeded.
Definition at line 625 of file AsyncSocket.h.
References getTFOSucceded(), setCloseOnExec(), setCongestionFlavor(), setNoDelay(), setQuickAck(), setRecvBufSize(), setSendBufSize(), string, and tfoFinished_.
bool folly::AsyncSocket::getTFOSucceded | ( | ) | const |
Returns whether or not TFO attempt succeded on this connection. For servers this is pretty straightforward API and can be invoked right after the connection is accepted. This API will perform one syscall. This API is a bit tricky to use for clients, since clients only know this for sure after the SYN-ACK is returned. So it's appropriate to call this only after the first application data is read from the socket when the caller knows that the SYN has been ACKed by the server.
Definition at line 1585 of file AsyncSocket.cpp.
References fd_, and folly::detail::tfo_succeeded().
Referenced by getTFOFinished().
|
inline |
Definition at line 504 of file AsyncSocket.h.
References zeroCopyEnabled_.
Referenced by folly::AsyncSocket::BytesWriteRequest::performWrite().
|
inline |
|
inline |
Definition at line 512 of file AsyncSocket.h.
References count, folly::NONE, setZeroCopyReenableThreshold(), write(), writeChain(), writeRequest(), writev(), and zeroCopyReenableThreshold_.
|
overridevirtual |
Determine if transport is open and ready to read or write.
Note that this function returns false on EOF; you must also call error() to distinguish between an EOF and an error.
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1489 of file AsyncSocket.cpp.
References CONNECTING, ESTABLISHED, eventBase_, FAST_OPEN, shutdownFlags_, and state_.
Referenced by folly::test::MockAsyncSocket::connect(), folly::AsyncSSLSocket::connecting(), folly::AsyncSSLSocket::good(), scheduleImmediateRead(), scheduleInitialReadWrite(), and writeRequestReady().
|
protectedvirtualnoexcept |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 2206 of file AsyncSocket.cpp.
References addr_, folly::AsyncTimeout::cancelTimeout(), CONNECTING, folly::SocketAddress::describe(), error(), ESTABLISHED, eventBase_, eventFlags_, failConnect(), fd_, folly::netops::getsockopt(), handleInitialReadWrite(), folly::AsyncSocketException::INTERNAL_ERROR, invokeConnectSuccess(), folly::EventHandler::NONE, folly::AsyncSocketException::NOT_OPEN, SHUT_READ, SHUT_WRITE, SHUT_WRITE_PENDING, folly::shutdown(), shutdownFlags_, state_, withAddr(), folly::EventHandler::WRITE, writeReqHead_, and writeTimeout_.
Referenced by folly::AsyncSSLSocket::handleConnect(), handleWrite(), and scheduleInitialReadWrite().
|
protectedvirtualnoexcept |
Definition at line 1804 of file AsyncSocket.cpp.
References folly::data(), folly::AsyncSocket::ErrMessageCallback::errMessage(), errMessageCallback_, failErrMessageRead(), fd_, idZeroCopyBufPtrMap_, folly::AsyncSocketException::INTERNAL_ERROR, isZeroCopyMsg(), processZeroCopyMsg(), folly::netops::recvmsg(), state_, uint8_t, and withAddr().
Referenced by ioReady(), processZeroCopyWriteInProgress(), and scheduleInitialReadWrite().
|
protectedvirtualnoexcept |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 2169 of file AsyncSocket.cpp.
References checkForImmediateRead(), ERROR, ESTABLISHED, eventFlags_, handleWrite(), folly::EventHandler::READ, readCallback_, SHUT_READ, shutdownFlags_, state_, updateEventRegistration(), folly::EventHandler::WRITE, and writeReqHead_.
Referenced by folly::AsyncSSLSocket::handleConnect(), handleConnect(), folly::AsyncSSLSocket::handleReturnFromSSLAccept(), and scheduleInitialReadWrite().
|
protectedvirtualnoexcept |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1881 of file AsyncSocket.cpp.
References folly::AsyncSocketException::BAD_ARGS, ERROR, ESTABLISHED, eventBase_, eventFlags_, failRead(), fd_, folly::AsyncSocketException::INTERNAL_ERROR, isBufferMovable_, kOpenSslModeMoveBufferOwnership, maxReadsPerEvent_, folly::gen::move, performRead(), prepareReadBuffer(), folly::EventHandler::READ, READ_BLOCKING, READ_EOF, READ_ERROR, fizz::detail::readBuf(), folly::AsyncReader::ReadCallback::readBufferAvailable(), readCallback_, folly::AsyncReader::ReadCallback::readDataAvailable(), folly::AsyncReader::ReadCallback::readEOF(), readErr_, scheduleImmediateRead(), SHUT_READ, shutdownFlags_, state_, folly::IOBuf::takeOwnership(), uint16_t, updateEventRegistration(), and withAddr().
Referenced by folly::AsyncSSLSocket::checkForImmediateRead(), checkForImmediateRead(), AsyncSocketImmediateRead::checkForImmediateRead(), folly::AsyncSSLSocket::handleRead(), ioReady(), and scheduleInitialReadWrite().
|
protectedvirtualnoexcept |
This function attempts to write as much data as possible, until no more data can be written.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 2019 of file AsyncSocket.cpp.
References bufferCallback_, folly::AsyncTimeout::cancelTimeout(), folly::EventHandler::changeHandlerFD(), CLOSED, connectCallback_, CONNECTING, folly::AsyncSocket::WriteRequest::consume(), folly::AsyncSocket::WriteRequest::destroy(), doClose(), ERROR, ESTABLISHED, eventBase_, eventFlags_, failWrite(), fd_, folly::AsyncSocket::WriteRequest::getCallback(), folly::AsyncSocket::WriteRequest::getNext(), handleConnect(), folly::AsyncSocketException::INTERNAL_ERROR, ioHandler_, folly::AsyncSocket::WriteRequest::isComplete(), folly::AsyncTimeout::isScheduled(), folly::AsyncTransport::BufferCallback::onEgressBufferCleared(), folly::AsyncTransport::BufferCallback::onEgressBuffered(), folly::AsyncSocket::WriteRequest::performWrite(), readCallback_, folly::AsyncTimeout::scheduleTimeout(), sendTimeout_, SHUT_READ, SHUT_WRITE, SHUT_WRITE_PENDING, folly::shutdown(), shutdownFlags_, state_, updateEventRegistration(), withAddr(), folly::EventHandler::WRITE, writeReqHead_, writeReqTail_, folly::AsyncWriter::WriteCallback::writeSuccess(), and writeTimeout_.
Referenced by handleInitialReadWrite(), folly::AsyncSSLSocket::handleWrite(), ioReady(), scheduleInitialReadWrite(), and writeRequestReady().
|
virtual |
Definition at line 1471 of file AsyncSocket.cpp.
References fd_, and folly::netops::poll().
Referenced by folly::test::MockAsyncSocket::connect(), folly::test::MockAsyncSSLSocket::connect(), and writeRequestReady().
|
protected |
Definition at line 337 of file AsyncSocket.cpp.
References appBytesReceived_, appBytesWritten_, connectCallback_, folly::EventBase::dcheckIsInEventBaseThread(), errMessageCallback_, eventBase_, eventFlags_, fd_, maxReadsPerEvent_, folly::EventHandler::NONE, readCallback_, sendMsgParamCallback_, sendTimeout_, shutdownFlags_, state_, UNINIT, writeReqHead_, writeReqTail_, and wShutdownSocketSet_.
Referenced by AsyncSocket().
|
protected |
Definition at line 2676 of file AsyncSocket.cpp.
References folly::AsyncSocketException::ALREADY_OPEN, CLOSED, connectEndTime_, folly::AsyncSocket::ConnectCallback::connectErr(), ERROR, fd_, finishFail(), now(), startFail(), and state_.
Referenced by connect(), scheduleInitialReadWrite(), setErrMessageCB(), setReadCB(), and writeImpl().
|
protected |
Definition at line 2707 of file AsyncSocket.cpp.
References CLOSED, folly::AsyncSocket::ErrMessageCallback::errMessageError(), ERROR, fd_, finishFail(), folly::AsyncSocketException::NOT_OPEN, startFail(), and state_.
|
protected |
Definition at line 2748 of file AsyncSocket.cpp.
References CLOSED, ERROR, fd_, finishFail(), folly::AsyncSocketException::NOT_OPEN, folly::AsyncReader::ReadCallback::readErr(), startFail(), and state_.
|
protected |
Definition at line 2770 of file AsyncSocket.cpp.
References CLOSED, ERROR, fd_, finishFail(), folly::AsyncSocketException::NOT_OPEN, startFail(), state_, withAddr(), and folly::AsyncWriter::WriteCallback::writeErr().
|
protected |
Definition at line 2542 of file AsyncSocket.cpp.
References failAllWrites(), invokeConnectErr(), readCallback_, and folly::AsyncReader::ReadCallback::readErr().
Referenced by finishFail(), and scheduleInitialReadWrite().
|
protectedvirtual |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 2730 of file AsyncSocket.cpp.
References connectCallback_, connectEndTime_, folly::AsyncSocket::ConnectCallback::connectErr(), and now().
Referenced by closeNow(), failConnect(), invokeAllErrors(), folly::AsyncSSLSocket::invokeConnectErr(), and scheduleInitialReadWrite().
|
protectedvirtual |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 2739 of file AsyncSocket.cpp.
References connectCallback_, connectEndTime_, folly::AsyncSocket::ConnectCallback::connectSuccess(), and now().
Referenced by connect(), handleConnect(), folly::AsyncSSLSocket::invokeConnectSuccess(), and scheduleInitialReadWrite().
|
protectednoexcept |
Definition at line 1713 of file AsyncSocket.cpp.
References folly::EventBase::dcheckIsInEventBaseThread(), eventBase_, fd_, handleErrMessages(), handleRead(), handleWrite(), folly::EventHandler::READ, folly::EventHandler::READ_WRITE, readCallback_, state_, uint16_t, and folly::EventHandler::WRITE.
Referenced by scheduleInitialReadWrite().
|
inlinevirtual |
Definition at line 571 of file AsyncSocket.h.
References CLOSED, READ_EOF, READ_ERROR, readErr_, and state_.
Referenced by proxygen::HTTPSession::connCloseByRemote(), and TEST().
|
inlinevirtual |
Definition at line 577 of file AsyncSocket.h.
References CLOSED, READ_EOF, READ_ERROR, readErr_, and state_.
Referenced by TEST().
|
overridevirtual |
Determine if the transport can be detached.
This method must be called from the current EventBase's thread.
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1537 of file AsyncSocket.cpp.
References folly::EventBase::dcheckIsInEventBaseThread(), eventBase_, folly::AsyncTimeout::isScheduled(), and writeTimeout_.
Referenced by folly::AsyncSSLSocket::isDetachable(), and writeRequestReady().
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Definition at line 559 of file AsyncSocket.h.
References trackEor_.
Referenced by folly::AsyncSSLSocket::eorAwareSSLWrite(), and folly::AsyncSSLSocket::setEorTracking().
|
overridevirtual |
Determine if the there is pending data on the transport.
Reimplemented from folly::AsyncTransport.
Definition at line 1467 of file AsyncSocket.cpp.
References ioHandler_, and folly::EventHandler::isPending().
Referenced by writeRequestReady().
|
protected |
Definition at line 967 of file AsyncSocket.cpp.
References SO_EE_ORIGIN_ZEROCOPY.
Referenced by handleErrMessages(), and scheduleInitialReadWrite().
|
protected |
Definition at line 905 of file AsyncSocket.cpp.
References folly::isSet(), folly::WRITE_MSG_ZEROCOPY, and zeroCopyEnabled_.
Referenced by folly::AsyncSocket::BytesWriteRequest::consume(), folly::AsyncSocket::BytesWriteRequest::performWrite(), scheduleInitialReadWrite(), and writeImpl().
|
noexcept |
Returns true if there is any zero copy write in progress Needs to be called from within the socket's EVB thread
Definition at line 1570 of file AsyncSocket.cpp.
References folly::EventBase::dcheckIsInEventBaseThread(), eventBase_, and idZeroCopyBufPtrMap_.
Referenced by setEvbChangedCallback().
|
inlinestatic |
Helper function to create a shared_ptr<AsyncSocket>.
This passes in the correct destructor object, since AsyncSocket's destructor is protected and cannot be invoked directly.
Definition at line 281 of file AsyncSocket.h.
References AsyncSocket().
Referenced by TestServer::acceptAsync(), wangle::ClientBootstrap< DefaultPipeline >::connect(), ProxyService::ProxyHandler::onRequest(), folly::TEST(), TEST(), TEST_P(), and testConnectOptWrite().
|
inlinestatic |
Helper function to create a shared_ptr<AsyncSocket>.
Definition at line 288 of file AsyncSocket.h.
References AsyncSocket().
|
inlinestatic |
Helper function to create a shared_ptr<AsyncSocket>.
Definition at line 299 of file AsyncSocket.h.
References AsyncSocket().
|
inlinestatic |
Helper function to create a shared_ptr<AsyncSocket>.
Definition at line 311 of file AsyncSocket.h.
References AsyncSocket(), and destroy().
|
protectedvirtual |
Attempt to read from the socket.
buf | The buffer to read data into. |
buflen | The length of the buffer. |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1764 of file AsyncSocket.cpp.
References appBytesReceived_, folly::IOBufQueue::append(), fd_, folly::IOBufQueue::move(), folly::gen::move, preReceivedData_, folly::io::detail::CursorBase< Derived, BufType >::pullAtMost(), READ_BLOCKING, READ_ERROR, folly::netops::recv(), and folly::IOBufQueue::trimStart().
Referenced by handleRead(), folly::AsyncSSLSocket::performRead(), and scheduleInitialReadWrite().
|
protectedvirtual |
Attempt to write to the socket.
vec | The iovec array pointing to the buffers to write. |
count | The length of the iovec array. |
flags | Set of write flags. |
countWritten | On return, the value pointed to by this parameter will contain the number of iovec entries that were fully written. |
partialWritten | On return, the value pointed to by this parameter will contain the number of bytes written in the partially written iovec entry. |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 2387 of file AsyncSocket.cpp.
References appBytesWritten_, count, fd_, folly::AsyncSocket::SendMsgParamsCallback::getAncillaryData(), folly::AsyncSocket::SendMsgParamsCallback::getAncillaryDataSize(), folly::AsyncSocket::SendMsgParamsCallback::getFlags(), folly::kIovMax, folly::AsyncSocket::SendMsgParamsCallback::maxAncillaryDataSize, sendMsgParamCallback_, sendSocketMessage(), uint32_t, zeroCopyEnabled_, zeroCopyReenableCounter_, and zeroCopyReenableThreshold_.
Referenced by folly::AsyncSocket::BytesWriteRequest::performWrite(), folly::AsyncSSLSocket::performWrite(), scheduleInitialReadWrite(), folly::AsyncSocket::WriteRequest::start(), and writeImpl().
|
protectedvirtual |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1798 of file AsyncSocket.cpp.
References folly::AsyncReader::ReadCallback::getReadBuffer(), and readCallback_.
Referenced by handleRead(), and scheduleInitialReadWrite().
|
protected |
Definition at line 981 of file AsyncSocket.cpp.
References fd_, i, releaseZeroCopyBuf(), SO_EE_CODE_ZEROCOPY_COPIED, uint32_t, and zeroCopyEnabled_.
Referenced by handleErrMessages(), and scheduleInitialReadWrite().
|
noexcept |
Tries to process the msg error queue And returns true if there are no more zero copy writes in progress
Definition at line 1870 of file AsyncSocket.cpp.
References folly::EventBase::dcheckIsInEventBaseThread(), eventBase_, handleErrMessages(), and idZeroCopyBufPtrMap_.
Referenced by setEvbChangedCallback().
|
overridevirtual |
Determine if the transport is readable or not.
Implements folly::AsyncTransport.
Definition at line 1443 of file AsyncSocket.cpp.
References fd_, and folly::netops::poll().
Referenced by folly::test::MockAsyncSocket::connect(), folly::test::MockAsyncSSLSocket::connect(), and writeRequestReady().
|
protected |
Definition at line 630 of file AsyncSocket.cpp.
References eventFlags_, folly::AsyncSocketException::INTERNAL_ERROR, ioHandler_, folly::EventHandler::NONE, folly::EventHandler::registerHandler(), withAddr(), and folly::EventHandler::WRITE.
Referenced by scheduleInitialReadWrite(), sendSocketMessage(), and socketConnect().
|
protected |
Definition at line 942 of file AsyncSocket.cpp.
References idZeroCopyBufInfoMap_, idZeroCopyBufPtrMap_, and ptr.
Referenced by getNextZeroCopyBufId(), and processZeroCopyMsg().
|
protectedvirtual |
Reimplemented in folly::AsyncSSLSocket.
Definition at line 617 of file AsyncSocket.cpp.
References connectTimeout_, folly::AsyncSocketException::INTERNAL_ERROR, folly::AsyncTimeout::scheduleTimeout(), folly::detail::timeout, uint32_t, withAddr(), and writeTimeout_.
Referenced by folly::AsyncSSLSocket::scheduleConnectTimeout(), scheduleInitialReadWrite(), sendSocketMessage(), and socketConnect().
|
inlineprotectednoexcept |
Schedule checkForImmediateRead to be executed in the next loop iteration.
Definition at line 1031 of file AsyncSocket.h.
References eventBase_, good(), immediateReadHandler_, and folly::EventBase::runInLoop().
Referenced by handleRead().
|
inlineprotectednoexcept |
Schedule handleInitalReadWrite to run in the next iteration.
Definition at line 1040 of file AsyncSocket.h.
References addr, cacheLocalAddress(), cachePeerAddress(), checkForImmediateRead(), doClose(), eventBase_, fail(), failAllWrites(), failConnect(), failErrMessageRead(), failRead(), failWrite(), finishFail(), good(), handleConnect(), handleErrMessages(), handleInitialReadWrite(), handleRead(), handleWrite(), invalidState(), invokeAllErrors(), invokeConnectErr(), invokeConnectSuccess(), ioReady(), isZeroCopyMsg(), isZeroCopyRequest(), folly::pushmi::__adl::noexcept(), folly::NONE, performRead(), performWrite(), prepareReadBuffer(), processZeroCopyMsg(), registerForConnectEvents(), folly::EventBase::runInLoop(), s, scheduleConnectTimeout(), sendSocketMessage(), socketConnect(), startFail(), string, tfoSendMsg(), timeoutExpired(), uint16_t, uint32_t, updateEventRegistration(), withAddr(), writeChainImpl(), and writeImpl().
Referenced by sendSocketMessage().
|
protected |
Sends the message over the socket using sendmsg
msg | Message to send |
msg_flags | Flags to pass to sendmsg |
Definition at line 2321 of file AsyncSocket.cpp.
References addr, addr_, CONNECTING, ESTABLISHED, FAST_OPEN, fd_, folly::SocketAddress::getAddress(), registerForConnectEvents(), scheduleConnectTimeout(), scheduleInitialReadWrite(), folly::netops::sendmsg(), socketConnect(), state_, tfoFinished_, tfoSendMsg(), folly::AsyncSocketException::UNKNOWN, and WRITE_ERROR.
Referenced by performWrite(), and scheduleInitialReadWrite().
void folly::AsyncSocket::setBufferCallback | ( | BufferCallback * | cb | ) |
Definition at line 2829 of file AsyncSocket.cpp.
References bufferCallback_.
Referenced by proxygen::HTTPSession::checkForShutdown(), and proxygen::HTTPUpstreamSession::HTTPUpstreamSession().
void folly::AsyncSocket::setCloseOnExec | ( | ) |
Set the FD_CLOEXEC flag so that the socket will be closed if the program later forks and execs.
Definition at line 420 of file AsyncSocket.cpp.
References fd_, folly::AsyncSocketException::INTERNAL_ERROR, and withAddr().
Referenced by AsyncSocket(), connect(), and getTFOFinished().
int folly::AsyncSocket::setCongestionFlavor | ( | const std::string & | cname | ) |
Definition at line 1608 of file AsyncSocket.cpp.
References folly::errnoStr(), fd_, folly::netops::setsockopt(), state_, and TCP_CONGESTION.
Referenced by getTFOFinished().
|
inlineoverridevirtual |
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 563 of file AsyncSocket.h.
References trackEor_.
Referenced by folly::AsyncSSLSocket::setEorTracking().
|
virtual |
Set a pointer to ErrMessageCallback implementation which will be receiving notifications for messages posted to the error queue associated with the socket. ErrMessageCallback is implemented only for platforms with per-socket error message queus support (recvmsg() system call must )
Definition at line 691 of file AsyncSocket.cpp.
References cacheLocalAddress(), CLOSED, CONNECTING, folly::EventBase::dcheckIsInEventBaseThread(), errMessageCallback_, ERROR, ESTABLISHED, eventBase_, FAST_OPEN, fd_, folly::SocketAddress::getFamily(), invalidState(), localAddr_, state_, and UNINIT.
Referenced by folly::test::MockAsyncSocket::connect(), and getMaxReadsPerEvent().
|
inline |
Definition at line 810 of file AsyncSocket.h.
References cacheAddresses(), evbChangeCb_, isZeroCopyWriteInProgress(), folly::gen::move, folly::pushmi::__adl::noexcept(), and processZeroCopyWriteInProgress().
|
inline |
Set the maximum number of reads to execute from the underlying socket each time the EventBase detects that new ingress data is available. The default is unlimited, but callers can use this method to limit the amount of data read from the socket per event loop iteration.
maxReads | Maximum number of reads per data-available event; a value of zero means unlimited. |
Definition at line 451 of file AsyncSocket.h.
References maxReadsPerEvent_.
Referenced by wangle::Acceptor::connectionReady(), and TEST().
int folly::AsyncSocket::setNoDelay | ( | bool | noDelay | ) |
Force writes to be transmitted immediately.
This controls the TCP_NODELAY socket option. When enabled, TCP segments are sent as soon as possible, even if it is not a full frame of data. When disabled, the data may be buffered briefly to try and wait for a full frame of data.
By default, TCP_NODELAY is enabled for AsyncSocket objects.
This method will fail if the socket is not currently open.
Definition at line 1589 of file AsyncSocket.cpp.
References folly::errnoStr(), fd_, folly::netops::setsockopt(), state_, and folly::value().
Referenced by connect(), and getTFOFinished().
|
inline |
Definition at line 833 of file AsyncSocket.h.
References folly::gen::move, and peerCertData_.
|
inlinevirtual |
Set pre-received data, to be returned to read callback before any data from the socket.
Reimplemented in folly::test::MockAsyncSocket.
Definition at line 770 of file AsyncSocket.h.
References folly::gen::move, and preReceivedData_.
Referenced by wangle::SocketPeeker::readDataAvailable().
int folly::AsyncSocket::setQuickAck | ( | bool | quickack | ) |
Definition at line 1635 of file AsyncSocket.cpp.
References folly::errnoStr(), fd_, folly::netops::setsockopt(), state_, and folly::value().
Referenced by getTFOFinished().
|
overridevirtual |
Implements folly::AsyncTransportWrapper.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 768 of file AsyncSocket.cpp.
References folly::EventBase::LoopCallback::cancelLoopCallback(), checkForImmediateRead(), CLOSED, CONNECTING, folly::EventBase::dcheckIsInEventBaseThread(), ERROR, ESTABLISHED, eventBase_, eventFlags_, FAST_OPEN, fd_, immediateReadHandler_, invalidState(), folly::EventBase::LoopCallback::isLoopCallbackScheduled(), folly::EventHandler::READ, readCallback_, SHUT_READ, shutdownFlags_, state_, uint16_t, UNINIT, and updateEventRegistration().
Referenced by folly::test::MockAsyncSocket::connect(), getMaxReadsPerEvent(), wangle::SocketPeeker::readDataAvailable(), wangle::SocketPeeker::readErr(), folly::AsyncSSLSocket::setReadCB(), wangle::SocketPeeker::start(), TEST(), testConnectOptWrite(), tmpDisableReads(), and wangle::SocketPeeker::~SocketPeeker().
int folly::AsyncSocket::setRecvBufSize | ( | size_t | bufsize | ) |
Set the recv bufsize
Definition at line 1677 of file AsyncSocket.cpp.
References folly::errnoStr(), fd_, folly::netops::setsockopt(), and state_.
Referenced by getTFOFinished().
|
inline |
Definition at line 841 of file AsyncSocket.h.
References folly::gen::move, and selfCertData_.
int folly::AsyncSocket::setSendBufSize | ( | size_t | bufsize | ) |
Set the send bufsize
Definition at line 1659 of file AsyncSocket.cpp.
References folly::errnoStr(), fd_, folly::netops::setsockopt(), and state_.
Referenced by getTFOFinished().
|
virtual |
Set a pointer to SendMsgParamsCallback implementation which will be used to form sendmsg() system call parameters
Definition at line 760 of file AsyncSocket.cpp.
References sendMsgParamCallback_.
Referenced by folly::test::MockAsyncSocket::connect(), and getMaxReadsPerEvent().
|
overridevirtual |
Set the send timeout.
If write requests do not make any progress for more than the specified number of milliseconds, fail all pending writes and close the socket.
If write requests are currently pending when setSendTimeout() is called, the timeout interval is immediately restarted using the new value.
(See the comments for AsyncSocket for an explanation of why AsyncSocket provides setSendTimeout() but not setRecvTimeout().)
milliseconds | The timeout duration, in milliseconds. If 0, no timeout will be used. |
Implements folly::AsyncTransport.
Definition at line 666 of file AsyncSocket.cpp.
References folly::AsyncTimeout::cancelTimeout(), CONNECTING, folly::EventBase::dcheckIsInEventBaseThread(), ESTABLISHED, eventBase_, eventFlags_, failWrite(), FAST_OPEN, folly::AsyncSocketException::INTERNAL_ERROR, folly::AsyncTimeout::scheduleTimeout(), sendTimeout_, SHUT_WRITE, shutdownFlags_, state_, withAddr(), folly::EventHandler::WRITE, and writeTimeout_.
void folly::AsyncSocket::setShutdownSocketSet | ( | const std::weak_ptr< ShutdownSocketSet > & | wSS | ) |
Definition at line 400 of file AsyncSocket.cpp.
References fd_, folly::ShutdownSocketSet::remove(), folly::test::shutdownSocketSet, and wShutdownSocketSet_.
Referenced by folly::AsyncSocket::SendMsgParamsCallback::getFlagsImpl().
|
inline |
Generic API for setting a socket option.
level | same as the "level" parameter in getsockopt(). |
optname | same as the "optname" parameter in getsockopt(). |
optval | the option value to set. |
Definition at line 727 of file AsyncSocket.h.
References fd_, folly::netops::setsockopt(), and folly::T.
Referenced by closeWithReset().
|
inlinevirtual |
Virtual method for setting a socket option accepting integer value, which is the most typical case. Convenient for overriding and mocking.
level | same as the "level" parameter in setsockopt(). |
optname | same as the "optname" parameter in setsockopt(). |
optval | same as "optval" parameter in setsockopt(). |
optlen | same as "optlen" parameter in setsockopt(). |
Definition at line 758 of file AsyncSocket.h.
References fd_, and folly::netops::setsockopt().
Referenced by folly::test::MockAsyncSocket::connect().
int folly::AsyncSocket::setTCPProfile | ( | int | profd | ) |
Definition at line 1695 of file AsyncSocket.cpp.
References folly::errnoStr(), fd_, folly::netops::setsockopt(), SO_SET_NAMESPACE, and state_.
bool folly::AsyncSocket::setZeroCopy | ( | bool | enable | ) |
Definition at line 860 of file AsyncSocket.cpp.
References fd_, folly::netops::getsockopt(), folly::netops::setsockopt(), SO_ZEROCOPY, val, zeroCopyEnabled_, and zeroCopyVal_.
Referenced by connect(), and getMaxReadsPerEvent().
|
protected |
Definition at line 955 of file AsyncSocket.cpp.
References idZeroCopyBufInfoMap_, folly::gen::move, and ptr.
Referenced by getNextZeroCopyBufId(), and folly::AsyncSocket::BytesWriteRequest::performWrite().
void folly::AsyncSocket::setZeroCopyReenableThreshold | ( | size_t | threshold | ) |
Definition at line 901 of file AsyncSocket.cpp.
References zeroCopyReenableThreshold_.
Referenced by getZeroCopyReenableThreshold().
|
overridevirtual |
Perform a half-shutdown of the write side of the transport.
The caller should not make any more calls to write() or writev() after shutdownWrite() is called. Any future write attempts will fail immediately.
Not all transport types support half-shutdown. If the underlying transport does not support half-shutdown, it will fully shutdown both the read and write sides of the transport. (Fully shutting down the socket is better than doing nothing at all, since the caller may rely on the shutdownWrite() call to notify the other end of the connection that no more data can be read.)
If there is pending data still waiting to be written on the transport, the actual shutdown will be delayed until the pending data has been written.
Note: There is no corresponding shutdownRead() equivalent. Simply uninstall the read callback if you wish to stop reading. (On TCP sockets at least, shutting down the read side of the socket is a no-op anyway.)
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1339 of file AsyncSocket.cpp.
References folly::EventBase::dcheckIsInEventBaseThread(), eventBase_, fd_, SHUT_WRITE_PENDING, shutdownFlags_, shutdownWriteNow(), state_, and writeReqHead_.
Referenced by writeRequestReady().
|
overridevirtual |
Perform a half-shutdown of the write side of the transport.
shutdownWriteNow() is identical to shutdownWrite(), except that it immediately performs the shutdown, rather than waiting for pending writes to complete. Any pending write requests will be immediately failed when shutdownWriteNow() is called.
Implements folly::AsyncTransport.
Reimplemented in folly::AsyncSSLSocket.
Definition at line 1358 of file AsyncSocket.cpp.
References folly::AsyncTimeout::cancelTimeout(), CLOSED, closeNow(), CONNECTING, folly::EventBase::dcheckIsInEventBaseThread(), folly::DFATAL, ERROR, ESTABLISHED, eventBase_, failAllWrites(), FAST_OPEN, fd_, SHUT_READ, SHUT_WRITE, SHUT_WRITE_PENDING, folly::shutdown(), shutdownFlags_, folly::socketShutdownForWritesEx, state_, UNINIT, updateEventRegistration(), folly::EventHandler::WRITE, and writeTimeout_.
Referenced by shutdownWrite(), and writeRequestReady().
|
protected |
Definition at line 600 of file AsyncSocket.cpp.
References folly::netops::connect(), fd_, folly::AsyncSocketException::NOT_OPEN, registerForConnectEvents(), and scheduleConnectTimeout().
Referenced by connect(), scheduleInitialReadWrite(), and sendSocketMessage().
|
protected |
Definition at line 2516 of file AsyncSocket.cpp.
References folly::EventBase::LoopCallback::cancelLoopCallback(), folly::AsyncTimeout::cancelTimeout(), folly::EventHandler::changeHandlerFD(), doClose(), ERROR, eventFlags_, fd_, folly::DelayedDestructionBase::getDestructorGuardCount(), immediateReadHandler_, ioHandler_, folly::EventBase::LoopCallback::isLoopCallbackScheduled(), folly::EventHandler::NONE, SHUT_READ, SHUT_WRITE, shutdownFlags_, state_, folly::EventHandler::unregisterHandler(), and writeTimeout_.
Referenced by fail(), failConnect(), failErrMessageRead(), folly::AsyncSSLSocket::failHandshake(), failRead(), failWrite(), invalidState(), and scheduleInitialReadWrite().
|
protectedvirtual |
Definition at line 2316 of file AsyncSocket.cpp.
References folly::detail::tfo_sendmsg().
Referenced by scheduleInitialReadWrite(), and sendSocketMessage().
|
protectednoexcept |
Definition at line 2285 of file AsyncSocket.cpp.
References connectCallback_, CONNECTING, connectTimeout_, folly::EventBase::dcheckIsInEventBaseThread(), eventBase_, eventFlags_, failConnect(), failWrite(), fd_, sendTimeout_, folly::sformat(), state_, and folly::AsyncSocketException::TIMED_OUT.
Referenced by folly::AsyncSSLSocket::getSSLContext(), and scheduleInitialReadWrite().
|
protected |
Re-register the EventHandler after eventFlags_ has changed.
If an error occurs, fail() is called to move the socket into the error state and call all currently installed callbacks. After an error, the AsyncSocket is completely unregistered.
Definition at line 2480 of file AsyncSocket.cpp.
References folly::EventBase::dcheckIsInEventBaseThread(), eventBase_, eventFlags_, fail(), fd_, folly::AsyncSocketException::INTERNAL_ERROR, ioHandler_, folly::EventHandler::NONE, folly::EventHandler::PERSIST, folly::EventHandler::registerHandler(), state_, uint16_t, folly::EventHandler::unregisterHandler(), and withAddr().
Referenced by attachEventBase(), close(), closeNow(), folly::AsyncSSLSocket::handleAccept(), folly::AsyncSSLSocket::handleConnect(), handleInitialReadWrite(), handleRead(), folly::AsyncSSLSocket::handleReturnFromSSLAccept(), handleWrite(), scheduleInitialReadWrite(), setReadCB(), shutdownWriteNow(), folly::AsyncSSLSocket::sslAccept(), updateEventRegistration(), folly::AsyncSSLSocket::willBlock(), and writeImpl().
Update event registration.
enable | Flags of events to enable. Set it to 0 if no events need to be enabled in this call. |
disable | Flags of events to disable. Set it to 0 if no events need to be disabled in this call. |
Definition at line 2505 of file AsyncSocket.cpp.
References eventFlags_, uint16_t, and updateEventRegistration().
|
protected |
Definition at line 2814 of file AsyncSocket.cpp.
References folly::SocketAddress::describe(), folly::AsyncTransport::getLocalAddress(), folly::AsyncTransport::getPeerAddress(), and folly::fibers::local().
Referenced by connect(), finishFail(), handleConnect(), handleErrMessages(), handleRead(), handleWrite(), invalidState(), registerForConnectEvents(), folly::AsyncSSLSocket::scheduleConnectTimeout(), scheduleConnectTimeout(), scheduleInitialReadWrite(), setCloseOnExec(), setSendTimeout(), updateEventRegistration(), and writeImpl().
|
overridevirtual |
Determine if the transport is writable or not.
Reimplemented from folly::AsyncTransport.
Definition at line 1455 of file AsyncSocket.cpp.
References fd_, and folly::netops::poll().
Referenced by writeRequestReady().
|
overridevirtual |
If you supply a non-null WriteCallback, exactly one of writeSuccess() or writeErr() will be invoked when the write completes. If you supply the same WriteCallback object for multiple write() calls, it will be invoked exactly once per call. The only way to cancel outstanding write requests is to close the socket (e.g., with closeNow() or shutdownWriteNow()). When closing the socket this way, writeErr() will still be invoked once for each outstanding write operation.
Implements folly::AsyncTransportWrapper.
Definition at line 1003 of file AsyncSocket.cpp.
References writeImpl().
Referenced by getZeroCopyReenableThreshold(), and TEST().
|
overridevirtual |
If you supply a non-null WriteCallback, exactly one of writeSuccess() or writeErr() will be invoked when the write completes. If you supply the same WriteCallback object for multiple write() calls, it will be invoked exactly once per call. The only way to cancel outstanding write requests is to close the socket (e.g., with closeNow() or shutdownWriteNow()). When closing the socket this way, writeErr() will still be invoked once for each outstanding write operation.
Implements folly::AsyncTransportWrapper.
Definition at line 1022 of file AsyncSocket.cpp.
References adjustZeroCopyFlags(), count, FOLLY_GNU_DISABLE_WARNING, FOLLY_HAVE_VLA_01, FOLLY_POP_WARNING, FOLLY_PUSH_WARNING, folly::gen::move, and writeChainImpl().
Referenced by getZeroCopyReenableThreshold().
|
protected |
Populate an iovec array from an IOBuf and attempt to write it.
callback | Write completion/error callback. |
vec | Target iovec array; caller retains ownership. |
count | Number of IOBufs to write, beginning at start of buf. |
buf | Chain of iovecs. |
flags | set of flags for the underlying write calls, like cork |
Definition at line 1045 of file AsyncSocket.cpp.
References folly::gen::move, and writeImpl().
Referenced by scheduleInitialReadWrite(), and writeChain().
|
protected |
Write as much data as possible to the socket without blocking, and queue up any leftover data to send when the socket can handle writes again.
callback | The callback to invoke when the write is completed. |
vec | Array of buffers to write; this method will make a copy of the vector (but not the buffers themselves) if the write has to be completed asynchronously. |
count | Number of elements in vec. |
buf | The IOBuf that manages the buffers referenced by vec, or a pointer to nullptr if the buffers are not associated with an IOBuf. Note that ownership of the IOBuf is transferred here; upon completion of the write, the AsyncSocket deletes the IOBuf. |
flags | Set of write flags. |
Definition at line 1055 of file AsyncSocket.cpp.
References addZeroCopyBuf(), folly::AsyncSocket::WriteRequest::append(), bufferCallback_, connecting(), folly::AsyncSocket::WriteRequest::consume(), folly::EventBase::dcheckIsInEventBaseThread(), ERROR, ESTABLISHED, eventBase_, eventFlags_, failWrite(), FAST_OPEN, fd_, folly::AsyncSocketException::INTERNAL_ERROR, invalidState(), isZeroCopyRequest(), folly::gen::move, folly::AsyncSocket::BytesWriteRequest::newRequest(), folly::AsyncTransport::BufferCallback::onEgressBuffered(), performWrite(), folly::AsyncTimeout::scheduleTimeout(), sendTimeout_, SHUT_WRITE, SHUT_WRITE_PENDING, shutdownFlags_, state_, uint32_t, updateEventRegistration(), withAddr(), folly::EventHandler::WRITE, writeReqHead_, writeReqTail_, folly::AsyncWriter::WriteCallback::writeSuccess(), and writeTimeout_.
Referenced by scheduleInitialReadWrite(), write(), writeChainImpl(), and writev().
|
virtual |
Definition at line 1187 of file AsyncSocket.cpp.
References folly::AsyncSocket::WriteRequest::append(), folly::AsyncSocket::WriteRequest::start(), writeReqHead_, and writeReqTail_.
Referenced by getZeroCopyReenableThreshold().
|
inline |
Definition at line 535 of file AsyncSocket.h.
References attachEventBase(), close(), closeNow(), closeWithReset(), detachEventBase(), error(), folly::AsyncTransport::getLocalAddress(), folly::AsyncTransport::getPeerAddress(), good(), handleWrite(), hangup(), isDetachable(), isPending(), readable(), shutdownWrite(), shutdownWriteNow(), and writable().
|
overridevirtual |
If you supply a non-null WriteCallback, exactly one of writeSuccess() or writeErr() will be invoked when the write completes. If you supply the same WriteCallback object for multiple write() calls, it will be invoked exactly once per call. The only way to cancel outstanding write requests is to close the socket (e.g., with closeNow() or shutdownWriteNow()). When closing the socket this way, writeErr() will still be invoked once for each outstanding write operation.
Implements folly::AsyncTransportWrapper.
Definition at line 1014 of file AsyncSocket.cpp.
References writeImpl().
Referenced by getZeroCopyReenableThreshold().
|
friend |
Definition at line 2807 of file AsyncSocket.cpp.
|
mutableprotected |
The address we tried to connect to.
Definition at line 1230 of file AsyncSocket.h.
Referenced by cachePeerAddress(), connect(), fail(), failConnect(), failErrMessageRead(), failRead(), failWrite(), getPeerAddress(), handleConnect(), and sendSocketMessage().
|
protected |
Num of bytes received from socket.
Definition at line 1253 of file AsyncSocket.h.
Referenced by getAppBytesReceived(), init(), folly::AsyncSSLSocket::performRead(), and performRead().
|
protected |
Num of bytes written to socket.
Definition at line 1254 of file AsyncSocket.h.
Referenced by folly::AsyncSSLSocket::eorAwareSSLWrite(), getAppBytesWritten(), init(), and performWrite().
|
protected |
Definition at line 1267 of file AsyncSocket.h.
Referenced by handleWrite(), setBufferCallback(), and writeImpl().
|
protected |
Definition at line 1245 of file AsyncSocket.h.
Referenced by cancelConnect(), closeNow(), connect(), handleWrite(), init(), invokeConnectErr(), invokeConnectSuccess(), folly::AsyncSSLSocket::scheduleConnectTimeout(), and timeoutExpired().
|
protected |
Definition at line 1261 of file AsyncSocket.h.
Referenced by connect(), getConnectEndTime(), getConnectTime(), invalidState(), invokeConnectErr(), and invokeConnectSuccess().
|
protected |
Definition at line 1260 of file AsyncSocket.h.
Referenced by connect(), getConnectStartTime(), and getConnectTime().
|
protected |
Definition at line 1263 of file AsyncSocket.h.
Referenced by connect(), getConnectTimeout(), folly::AsyncSSLSocket::scheduleConnectTimeout(), scheduleConnectTimeout(), and timeoutExpired().
|
static |
Definition at line 378 of file AsyncSocket.h.
Referenced by folly::AsyncSSLSocket::getSecurityProtocol(), and proxygen::HTTPConnector::Callback::~Callback().
|
protected |
TimestampCallback.
Definition at line 1246 of file AsyncSocket.h.
Referenced by connect(), failErrMessageRead(), getErrMessageCallback(), handleErrMessages(), init(), and setErrMessageCB().
|
protected |
Definition at line 1265 of file AsyncSocket.h.
Referenced by attachEventBase(), detachEventBase(), and setEvbChangedCallback().
|
protected |
The EventBase.
Definition at line 1240 of file AsyncSocket.h.
Referenced by attachEventBase(), close(), closeNow(), connect(), destroy(), detachEventBase(), detachFd(), getEventBase(), good(), folly::AsyncSSLSocket::handleConnect(), handleConnect(), handleRead(), folly::AsyncSSLSocket::handleReturnFromSSLAccept(), handleWrite(), init(), ioReady(), isDetachable(), isZeroCopyWriteInProgress(), processZeroCopyWriteInProgress(), scheduleImmediateRead(), scheduleInitialReadWrite(), setErrMessageCB(), setReadCB(), setSendTimeout(), shutdownWrite(), shutdownWriteNow(), folly::AsyncSSLSocket::sslAccept(), folly::AsyncSSLSocket::sslConn(), timeoutExpired(), updateEventRegistration(), folly::AsyncSSLSocket::willBlock(), writeImpl(), ~AsyncSocket(), and folly::AsyncSSLSocket::~AsyncSSLSocket().
|
protected |
EventBase::HandlerFlags settings.
Definition at line 1228 of file AsyncSocket.h.
Referenced by attachEventBase(), closeNow(), detachEventBase(), detachFd(), folly::AsyncSSLSocket::handleAccept(), folly::AsyncSSLSocket::handleConnect(), handleConnect(), handleInitialReadWrite(), folly::AsyncSSLSocket::handleRead(), handleRead(), folly::AsyncSSLSocket::handleReturnFromSSLAccept(), folly::AsyncSSLSocket::handleWrite(), handleWrite(), init(), folly::AsyncSSLSocket::interpretSSLError(), folly::AsyncSSLSocket::invalidState(), folly::AsyncSSLSocket::performRead(), folly::AsyncSSLSocket::performWrite(), registerForConnectEvents(), folly::AsyncSSLSocket::restartSSLAccept(), setReadCB(), setSendTimeout(), startFail(), timeoutExpired(), updateEventRegistration(), folly::AsyncSSLSocket::willBlock(), writeImpl(), and folly::AsyncSSLSocket::~AsyncSSLSocket().
|
protected |
The socket file descriptor.
Definition at line 1229 of file AsyncSocket.h.
Referenced by AsyncSocket(), attachEventBase(), cacheAddresses(), cacheLocalAddress(), cachePeerAddress(), close(), folly::AsyncSSLSocket::closeNow(), closeNow(), closeWithReset(), connect(), destroy(), detachEventBase(), detachFd(), doClose(), fail(), failConnect(), failErrMessageRead(), failRead(), failWrite(), getFd(), getSockOpt(), getSockOptVirtual(), getTFOSucceded(), folly::AsyncSSLSocket::handleAccept(), folly::AsyncSSLSocket::handleConnect(), handleConnect(), handleErrMessages(), folly::AsyncSSLSocket::handleRead(), handleRead(), folly::AsyncSSLSocket::handleReturnFromSSLAccept(), folly::AsyncSSLSocket::handleWrite(), handleWrite(), hangup(), init(), folly::AsyncSSLSocket::interpretSSLError(), folly::AsyncSSLSocket::invalidState(), invalidState(), ioReady(), folly::AsyncSSLSocket::performRead(), performRead(), folly::AsyncSSLSocket::performWrite(), performWrite(), processZeroCopyMsg(), readable(), folly::AsyncSSLSocket::restartSSLAccept(), sendSocketMessage(), setCloseOnExec(), setCongestionFlavor(), setErrMessageCB(), setNoDelay(), setQuickAck(), setReadCB(), setRecvBufSize(), setSendBufSize(), setShutdownSocketSet(), setSockOpt(), setSockOptVirtual(), setTCPProfile(), folly::AsyncSSLSocket::setupSSLBio(), setZeroCopy(), shutdownWrite(), shutdownWriteNow(), socketConnect(), folly::AsyncSSLSocket::sslConn(), startFail(), timeoutExpired(), updateEventRegistration(), folly::AsyncSSLSocket::willBlock(), writable(), writeImpl(), ~AsyncSocket(), and folly::AsyncSSLSocket::~AsyncSSLSocket().
|
protected |
Definition at line 1224 of file AsyncSocket.h.
Referenced by addZeroCopyBuf(), containsZeroCopyBuf(), doClose(), releaseZeroCopyBuf(), and setZeroCopyBuf().
|
protected |
Definition at line 1223 of file AsyncSocket.h.
Referenced by addZeroCopyBuf(), doClose(), handleErrMessages(), isZeroCopyWriteInProgress(), processZeroCopyWriteInProgress(), and releaseZeroCopyBuf().
|
protected |
LoopCallback for checking read.
Definition at line 1243 of file AsyncSocket.h.
Referenced by closeNow(), scheduleImmediateRead(), setReadCB(), and startFail().
|
protected |
A EventHandler to monitor the fd.
Definition at line 1242 of file AsyncSocket.h.
Referenced by attachEventBase(), closeNow(), connect(), detachEventBase(), detachFd(), handleWrite(), isPending(), registerForConnectEvents(), startFail(), and updateEventRegistration().
|
protected |
Definition at line 1236 of file AsyncSocket.h.
Referenced by handleRead(), folly::AsyncSSLSocket::performRead(), folly::AsyncSSLSocket::prepareReadBuffer(), and folly::AsyncSSLSocket::setReadCB().
|
mutableprotected |
The address we are connecting from.
Definition at line 1231 of file AsyncSocket.h.
Referenced by cacheLocalAddress(), getLocalAddress(), and setErrMessageCB().
|
protected |
Max reads per event loop iteration.
Definition at line 1234 of file AsyncSocket.h.
Referenced by getMaxReadsPerEvent(), handleRead(), init(), and setMaxReadsPerEvent().
|
protected |
Definition at line 1271 of file AsyncSocket.h.
Referenced by AsyncSocket(), folly::AsyncSSLSocket::AsyncSSLSocket(), connect(), folly::AsyncSSLSocket::connect(), and disableTransparentTls().
|
protected |
Definition at line 1272 of file AsyncSocket.h.
Referenced by AsyncSocket(), connect(), and disableTSocks().
|
mutableprotected |
Definition at line 1282 of file AsyncSocket.h.
Referenced by folly::AsyncSSLSocket::getPeerCertificate(), getPeerCertificate(), and setPeerCertificate().
|
protected |
Definition at line 1258 of file AsyncSocket.h.
Referenced by AsyncSocket(), checkForImmediateRead(), performRead(), and setPreReceivedData().
|
protected |
Definition at line 1249 of file AsyncSocket.h.
Referenced by close(), closeNow(), connect(), failRead(), getReadCallback(), handleInitialReadWrite(), handleRead(), handleWrite(), init(), invokeAllErrors(), ioReady(), folly::AsyncSSLSocket::prepareReadBuffer(), prepareReadBuffer(), and setReadCB().
|
protected |
The read error encountered, if any.
Definition at line 1238 of file AsyncSocket.h.
Referenced by handleRead(), isClosedByPeer(), and isClosedBySelf().
|
mutableprotected |
Definition at line 1284 of file AsyncSocket.h.
Referenced by folly::AsyncSSLSocket::getSelfCertificate(), getSelfCertificate(), and setSelfCertificate().
|
protected |
< Callback for retrieving
sendmsg() parameters
Definition at line 1248 of file AsyncSocket.h.
Referenced by getSendMsgParamsCB(), init(), performWrite(), and setSendMsgParamCB().
|
protected |
The send timeout, in milliseconds.
Definition at line 1233 of file AsyncSocket.h.
Referenced by getSendTimeout(), handleWrite(), init(), setSendTimeout(), timeoutExpired(), and writeImpl().
|
protected |
Shutdown state (ShutdownFlags)
Definition at line 1227 of file AsyncSocket.h.
Referenced by close(), closeNow(), good(), handleConnect(), handleInitialReadWrite(), handleRead(), handleWrite(), init(), setReadCB(), setSendTimeout(), shutdownWrite(), shutdownWriteNow(), startFail(), and writeImpl().
|
protected |
StateEnum describing current state.
Definition at line 1226 of file AsyncSocket.h.
Referenced by AsyncSocket(), attachEventBase(), cancelConnect(), close(), closeNow(), connect(), folly::AsyncSSLSocket::connect(), connecting(), destroy(), detachEventBase(), detachFd(), error(), fail(), failConnect(), failErrMessageRead(), failRead(), failWrite(), finishFail(), good(), folly::AsyncSSLSocket::handleAccept(), folly::AsyncSSLSocket::handleConnect(), handleConnect(), handleErrMessages(), handleInitialReadWrite(), folly::AsyncSSLSocket::handleRead(), handleRead(), folly::AsyncSSLSocket::handleReturnFromSSLAccept(), folly::AsyncSSLSocket::handleWrite(), handleWrite(), init(), folly::AsyncSSLSocket::interpretSSLError(), folly::AsyncSSLSocket::invalidState(), invalidState(), ioReady(), isClosedByPeer(), isClosedBySelf(), folly::AsyncSSLSocket::performRead(), folly::AsyncSSLSocket::performWrite(), folly::AsyncSSLSocket::restartSSLAccept(), sendSocketMessage(), setCongestionFlavor(), setErrMessageCB(), setNoDelay(), setQuickAck(), setReadCB(), setRecvBufSize(), setSendBufSize(), setSendTimeout(), setTCPProfile(), shutdownWrite(), shutdownWriteNow(), folly::test::MockAsyncSSLSocket::sslAccept(), folly::test::MockAsyncSSLSocket::sslConn(), startFail(), folly::AsyncSSLSocket::timeoutExpired(), timeoutExpired(), updateEventRegistration(), folly::AsyncSSLSocket::willBlock(), writeImpl(), ~AsyncSocket(), and folly::AsyncSSLSocket::~AsyncSSLSocket().
|
protected |
Definition at line 1269 of file AsyncSocket.h.
Referenced by connect(), getTFOAttempted(), and folly::AsyncSSLSocket::invokeConnectSuccess().
|
protected |
Definition at line 1268 of file AsyncSocket.h.
Referenced by connect(), and enableTFO().
|
protected |
Definition at line 1270 of file AsyncSocket.h.
Referenced by getTFOFinished(), and sendSocketMessage().
|
protected |
Definition at line 1274 of file AsyncSocket.h.
Referenced by isEorTrackingEnabled(), and setEorTracking().
|
protected |
Chain of WriteRequests.
Definition at line 1250 of file AsyncSocket.h.
Referenced by close(), closeNow(), connect(), failAllWrites(), failWrite(), handleConnect(), handleInitialReadWrite(), handleWrite(), init(), shutdownWrite(), writeImpl(), and writeRequest().
|
protected |
End of WriteRequest chain.
Definition at line 1251 of file AsyncSocket.h.
Referenced by handleWrite(), init(), writeImpl(), and writeRequest().
|
protected |
A timeout for connect and write.
Definition at line 1241 of file AsyncSocket.h.
Referenced by attachEventBase(), closeNow(), detachEventBase(), handleConnect(), handleWrite(), isDetachable(), scheduleConnectTimeout(), setSendTimeout(), shutdownWriteNow(), startFail(), and writeImpl().
|
protected |
Definition at line 1252 of file AsyncSocket.h.
Referenced by connect(), detachFd(), doClose(), init(), and setShutdownSocketSet().
|
protected |
Definition at line 1216 of file AsyncSocket.h.
Referenced by getNextZeroCopyBufId(), and getZeroCopyBufId().
|
protected |
Definition at line 1275 of file AsyncSocket.h.
Referenced by adjustZeroCopyFlags(), getZeroCopy(), isZeroCopyRequest(), performWrite(), processZeroCopyMsg(), and setZeroCopy().
|
protected |
Definition at line 1279 of file AsyncSocket.h.
Referenced by adjustZeroCopyFlags(), and performWrite().
|
protected |
Definition at line 1278 of file AsyncSocket.h.
Referenced by getZeroCopyReenableThreshold(), performWrite(), and setZeroCopyReenableThreshold().
|
protected |
Definition at line 1276 of file AsyncSocket.h.
Referenced by connect(), and setZeroCopy().