Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shim for sendmmsg when sendmmsg does not exist #1896

Merged
merged 5 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ else()
message(STATUS "SO_ATTACH_REUSEPORT_CBPF is missing. Server receive performance will be reduced")
endif()

check_c_source_compiles(
"
#define _GNU_SOURCE
#include <sys/socket.h>
#include <stddef.h>
int main() { return sendmmsg(0, NULL, 0, 0); }
"
HAS_SENDMMSG)
if(NOT HAS_SENDMMSG)
message(STATUS "sendmmsg is missing. Send performance will be reduced")
endif()

# Error if flags are missing in CI
if(QUIC_CI AND NOT QUIC_SKIP_CI_CHECKS)
if (NOT HAS_UDP_SEGMENT)
Expand Down Expand Up @@ -276,6 +288,9 @@ else()

set(QUIC_COMMON_FLAGS "")
set(QUIC_COMMON_DEFINES _GNU_SOURCE)
if (HAS_SENDMMSG)
list(APPEND QUIC_COMMON_DEFINES HAS_SENDMMSG)
endif()
set(QUIC_WARNING_FLAGS -Werror -Wall -Wextra -Wformat=2 -Wno-type-limits
-Wno-unknown-pragmas -Wno-multichar -Wno-missing-field-initializers
CACHE INTERNAL "")
Expand Down
27 changes: 26 additions & 1 deletion src/platform/datapath_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@
CXPLAT_STATIC_ASSERT((SIZEOF_STRUCT_MEMBER(QUIC_BUFFER, Length) <= sizeof(size_t)), "(sizeof(QUIC_BUFFER.Length) == sizeof(size_t) must be TRUE.");
CXPLAT_STATIC_ASSERT((SIZEOF_STRUCT_MEMBER(QUIC_BUFFER, Buffer) == sizeof(void*)), "(sizeof(QUIC_BUFFER.Buffer) == sizeof(void*) must be TRUE.");

#ifdef HAS_SENDMMSG
#define CXPLAT_SENDMMSG sendmmsg
nibanks marked this conversation as resolved.
Show resolved Hide resolved
#else
static
int
cxplat_sendmmsg_shim(
int fd,
struct mmsghdr* Messages,
unsigned int MessageLen,
int Flags
)
{
unsigned int SuccessCount = 0;
while (SuccessCount < MessageLen) {
int Result = sendmsg(fd, &Messages[SuccessCount].msg_hdr, Flags);
if (Result < 0) {
return SuccessCount == 0 ? Result : (int)SuccessCount;
}
Messages[SuccessCount].msg_len = Result;
SuccessCount++;
}
return SuccessCount;
}
#define CXPLAT_SENDMMSG cxplat_sendmmsg_shim
#endif

//
// The maximum single buffer size for sending coalesced payloads.
Expand Down Expand Up @@ -2573,7 +2598,7 @@ CxPlatSocketSendInternal(
while (SendData->SentMessagesCount < TotalMessagesCount) {

int SuccessfullySentMessages =
sendmmsg(
CXPLAT_SENDMMSG(
thhous-msft marked this conversation as resolved.
Show resolved Hide resolved
SocketContext->SocketFd,
Mhdrs + SendData->SentMessagesCount,
(unsigned int)(TotalMessagesCount - SendData->SentMessagesCount),
Expand Down