Skip to content

Commit

Permalink
AsyncSocket: add ReadCallback::ReadMode::ReadRecvZc
Browse files Browse the repository at this point in the history
Summary:
Issue recvzc request in AsyncSocket using the EVB backend.

Only IoUringBackend is going to support this. It is expected for the ReadCallback to check and set the ReadMode to ReadRecvZc if this is desired and supported by the backend. There are no checks here in the AsyncSocket. By default `issueRecvZc` will return -1 and this will be converted into an error code.

# Context
This and the rest of the stack is needed to support peeking done at the crypto layer in wangle::Acceptor to determine things like StopTLS and at the Thrift layer to determine the protocol. 9 bytes are peeked for crypto and 13 bytes are peeked for Thrift.

The peeking happens early on before an AsyncIoUringSocket is created on top of AsyncSSLSocket. Prior to this, the only way to read a socket configured for io_uring zc rx is via AsyncIoUringSocket.

Reviewed By: dmm-fb

Differential Revision: D70057958

fbshipit-source-id: ef0b4e7c03ac765c2606b10f73ac423f008e51b3
  • Loading branch information
spikeh authored and facebook-github-bot committed Feb 25, 2025
1 parent 5cc2c46 commit bb1b33e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions folly/io/async/AsyncSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,7 @@ AsyncSocket::ReadResult AsyncSocket::performReadMsg(
struct ::msghdr& msg,
// This is here only to preserve AsyncSSLSocket's legacy semi-broken
// behavior (D43648653 for context).
AsyncReader::ReadCallback::ReadMode) {
AsyncReader::ReadCallback::ReadMode readMode) {
VLOG(5) << "AsyncSocket::performReadMsg() this=" << this
<< ", iovs=" << msg.msg_iov << ", num=" << msg.msg_iovlen;

Expand Down Expand Up @@ -2725,7 +2725,11 @@ AsyncSocket::ReadResult AsyncSocket::performReadMsg(
}

ssize_t bytes = 0;
if (readAncillaryDataCallback_ == nullptr && msg.msg_iovlen == 1) {
if (readMode == AsyncReader::ReadCallback::ReadMode::ReadZC) {
auto backend = getEventBase()->getBackend();
bytes = backend->issueRecvZc(
fd_.toFd(), msg.msg_iov[0].iov_base, msg.msg_iov[0].iov_len);
} else if (readAncillaryDataCallback_ == nullptr && msg.msg_iovlen == 1) {
bytes = netops_->recv(
fd_, msg.msg_iov[0].iov_base, msg.msg_iov[0].iov_len, MSG_DONTWAIT);
} else {
Expand Down
1 change: 1 addition & 0 deletions folly/io/async/AsyncTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class AsyncReader {
enum class ReadMode : uint8_t {
ReadBuffer = 0,
ReadVec = 1,
ReadZC = 2,
};

virtual ~ReadCallback() = default;
Expand Down

0 comments on commit bb1b33e

Please sign in to comment.