Skip to content

Commit

Permalink
Set TCP listener created sockets to non blocking (#4541)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThadHouse authored Sep 10, 2024
1 parent 376265a commit 44f096a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/platform/datapath_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
--*/

#include "platform_internal.h"
#include <fcntl.h>
#include <linux/filter.h>
#include <linux/in6.h>
#include <netinet/udp.h>
Expand Down Expand Up @@ -1578,6 +1579,42 @@ CxPlatSocketContextAcceptCompletion(
&SocketContext->AcceptSocket->RemoteAddress,
&SocketContext->AcceptSocket->RemoteAddress);

//
// Set non blocking mode
//
int Flags =
fcntl(
SocketContext->AcceptSocket->SocketContexts[0].SocketFd,
F_GETFL,
NULL);
if (Flags < 0) {
Status = errno;
QuicTraceEvent(
DatapathErrorStatus,
"[data][%p] ERROR, %u, %s.",
SocketContext->Binding,
Status,
"fcntl(F_GETFL) failed");
goto Error;
}

Flags |= O_NONBLOCK;
Result =
fcntl(
SocketContext->AcceptSocket->SocketContexts[0].SocketFd,
F_SETFL,
Flags);
if (Result < 0) {
Status = errno;
QuicTraceEvent(
DatapathErrorStatus,
"[data][%p] ERROR, %u, %s.",
SocketContext->Binding,
Status,
"fcntl(F_SETFL) failed");
goto Error;
}

CxPlatSocketContextSetEvents(&SocketContext->AcceptSocket->SocketContexts[0], EPOLL_CTL_ADD, EPOLLIN);
SocketContext->AcceptSocket->SocketContexts[0].IoStarted = TRUE;
Status = Datapath->TcpHandlers.Accept(
Expand Down

0 comments on commit 44f096a

Please sign in to comment.