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

Support compile for Android and compatible to API-21 #4486

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,21 @@ else()
message(STATUS "sendmmsg is missing. Send performance will be reduced")
endif()

check_function_exists(recvmmsg HAS_RECVMMSG)
if(NOT HAS_RECVMMSG)
message(STATUS "recvmmsg is missing. Receive performance will be reduced")
endif()

check_function_exists(epoll_create1 HAS_EPOLL_CREATE1)
if(NOT HAS_EPOLL_CREATE1)
message(STATUS "epoll_create1 is missing.")
endif()

check_function_exists(pthread_condattr_setclock HAS_PTHREAD_SET_CLOCK)
if(NOT HAS_PTHREAD_SET_CLOCK)
message(STATUS "pthread_condattr_setclock is missing.")
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 @@ -295,6 +310,15 @@ else()
if (HAS_SENDMMSG)
list(APPEND QUIC_COMMON_DEFINES HAS_SENDMMSG)
endif()
if (HAS_RECVMMSG)
list(APPEND QUIC_COMMON_DEFINES HAS_RECVMMSG)
endif()
if (HAS_EPOLL_CREATE1)
list(APPEND QUIC_COMMON_DEFINES HAS_EPOLL_CREATE1)
endif()
if (HAS_PTHREAD_SET_CLOCK)
list(APPEND QUIC_COMMON_DEFINES HAS_PTHREAD_SET_CLOCK)
endif()
if (HAS__SC_PHYS_PAGES)
list(APPEND QUIC_COMMON_DEFINES HAS__SC_PHYS_PAGES)
endif()
Expand Down
6 changes: 6 additions & 0 deletions src/inc/quic_platform_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,8 +776,10 @@ CxPlatEventInitialize(
Result = pthread_condattr_init(&Attr);
CXPLAT_FRE_ASSERT(Result == 0);
#if defined(CX_PLATFORM_LINUX)
#if defined(HAS_PTHREAD_SET_CLOCK)
Result = pthread_condattr_setclock(&Attr, CLOCK_MONOTONIC);
CXPLAT_FRE_ASSERT(Result == 0);
#endif // HAS_PTHREAD_SET_CLOCK
#endif // CX_PLATFORM_LINUX
Result = pthread_cond_init(&Event->Cond, &Attr);
CXPLAT_FRE_ASSERT(Result == 0);
Expand Down Expand Up @@ -1028,7 +1030,11 @@ CxPlatEventQInitialize(
_Out_ CXPLAT_EVENTQ* queue
)
{
#ifdef HAS_EPOLL_CREATE1
return (*queue = epoll_create1(EPOLL_CLOEXEC)) != -1;
#else
return (*queue = epoll_create(32000)) != -1;
#endif
}

inline
Expand Down
30 changes: 26 additions & 4 deletions src/platform/datapath_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -1849,13 +1849,24 @@ CxPlatSocketReceiveCoalesced(
RecvIov.iov_base = (char*)IoBlock + DatapathPartition->Datapath->RecvBlockBufferOffset;
RecvIov.iov_len = CXPLAT_LARGE_IO_BUFFER_SIZE;

int Ret =
recvmmsg(
int Ret = 0;
#ifdef HAS_RECVMMSG
Ret = recvmmsg(
SocketContext->SocketFd,
&RecvMsgHdr,
1,
0,
NULL);
#else
Ret = recvmsg(
SocketContext->SocketFd,
&RecvMsgHdr.msg_hdr,
0);
if (Ret > 0) {
RecvMsgHdr.msg_len = Ret;
Ret = 1;
}
#endif
if (Ret < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
QuicTraceEvent(
Expand Down Expand Up @@ -1925,13 +1936,24 @@ CxPlatSocketReceiveMessages(
RecvIov[i].iov_len = CXPLAT_SMALL_IO_BUFFER_SIZE;
}

int Ret =
recvmmsg(
int Ret = 0;
#ifdef HAS_RECVMMSG
Ret = recvmmsg(
SocketContext->SocketFd,
RecvMsgHdr,
(int)CXPLAT_MAX_IO_BATCH_SIZE,
0,
NULL);
#else
Ret = recvmsg(
SocketContext->SocketFd,
&RecvMsgHdr[0].msg_hdr,
0);
if (Ret > 0) {
RecvMsgHdr[0].msg_len = Ret;
Ret = 1;
}
#endif
if (Ret < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
QuicTraceEvent(
Expand Down
4 changes: 4 additions & 0 deletions src/platform/platform_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,11 @@ CxPlatGetAbsoluteTime(
CxPlatZeroMemory(Time, sizeof(struct timespec));

#if defined(CX_PLATFORM_LINUX)
#if defined(HAS_PTHREAD_SET_CLOCK)
ErrorCode = clock_gettime(CLOCK_MONOTONIC, Time);
#else
ErrorCode = clock_gettime(CLOCK_REALTIME, Time);
#endif
#elif defined(CX_PLATFORM_DARWIN)
//
// timespec_get is used on darwin, as CLOCK_MONOTONIC isn't actually
Expand Down
Loading