Skip to content

Commit

Permalink
Return void for CxPlatSocketSend
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks committed Aug 29, 2024
1 parent c6e28b0 commit 6fac5c4
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 222 deletions.
33 changes: 3 additions & 30 deletions src/core/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ QuicBindingUnreachable(
}

_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
void
QuicBindingSend(
_In_ QUIC_BINDING* Binding,
_In_ const CXPLAT_ROUTE* Route,
Expand All @@ -1790,8 +1790,6 @@ QuicBindingSend(
_In_ uint32_t DatagramsToSend
)
{
QUIC_STATUS Status;

#if QUIC_TEST_DATAPATH_HOOKS_ENABLED
QUIC_TEST_DATAPATH_HOOKS* Hooks = MsQuicLib.TestDatapathHooks;
if (Hooks != NULL) {
Expand All @@ -1810,42 +1808,17 @@ QuicBindingSend(
"[bind][%p] Test dropped packet",
Binding);
CxPlatSendDataFree(SendData);
Status = QUIC_STATUS_SUCCESS;
} else {
Status =
CxPlatSocketSend(
Binding->Socket,
&RouteCopy,
SendData);
if (QUIC_FAILED(Status)) {
QuicTraceLogWarning(
BindingSendFailed,
"[bind][%p] Send failed, 0x%x",
Binding,
Status);
}
CxPlatSocketSend(Binding->Socket, &RouteCopy, SendData);
}
} else {
#endif
Status =
CxPlatSocketSend(
Binding->Socket,
Route,
SendData);
if (QUIC_FAILED(Status)) {
QuicTraceLogWarning(
BindingSendFailed,
"[bind][%p] Send failed, 0x%x",
Binding,
Status);
}
CxPlatSocketSend(Binding->Socket, Route, SendData);
#if QUIC_TEST_DATAPATH_HOOKS_ENABLED
}
#endif

QuicPerfCounterAdd(QUIC_PERF_COUNTER_UDP_SEND, DatagramsToSend);
QuicPerfCounterAdd(QUIC_PERF_COUNTER_UDP_SEND_BYTES, BytesToSend);
QuicPerfCounterIncrement(QUIC_PERF_COUNTER_UDP_SEND_CALLS);

return Status;
}
2 changes: 1 addition & 1 deletion src/core/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ QuicBindingReleaseStatelessOperation(
// the duration of the send operation.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
void
QuicBindingSend(
_In_ QUIC_BINDING* Binding,
_In_ const CXPLAT_ROUTE* Route,
Expand Down
2 changes: 1 addition & 1 deletion src/inc/quic_datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ CxPlatSendDataIsFull(
// Sends the data over the socket.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
void
CxPlatSocketSend(
_In_ CXPLAT_SOCKET* Socket,
_In_ const CXPLAT_ROUTE* Route,
Expand Down
48 changes: 25 additions & 23 deletions src/perf/lib/Tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,11 @@ TcpConnection::ConnectCallback(
Connected);
if (Connected) {
This->StartTls = true;
} else {
This->Queue();
} else if (!This->Shutdown) {
This->Shutdown = true;
This->Queue();
}
This->Queue();
}

_IRQL_requires_max_(DISPATCH_LEVEL)
Expand Down Expand Up @@ -566,22 +567,30 @@ void
TcpConnection::SendCompleteCallback(
_In_ CXPLAT_SOCKET* /* Socket */,
_In_ void* Context,
_In_ QUIC_STATUS /* Status */,
_In_ QUIC_STATUS Status,
_In_ uint32_t ByteCount
)
{
TcpConnection* This = (TcpConnection*)Context;
bool QueueWork = false;
QuicTraceLogVerbose(
PerfTcpSendCompleteCallback,
"[perf][tcp][%p] SendComplete callback",
This);
"[perf][tcp][%p] SendComplete callback, %u",
This,
(uint32_t)Status);
CxPlatDispatchLockAcquire(&This->Lock);
if (This->TotalSendCompleteOffset != UINT64_MAX) {
if (QUIC_FAILED(Status)) {
if (!This->Shutdown) {
This->Shutdown = true;
QueueWork = true;
}
} else if (This->TotalSendCompleteOffset != UINT64_MAX) {
This->TotalSendCompleteOffset += ByteCount;
This->IndicateSendComplete = true;
QueueWork = true;
}
CxPlatDispatchLockRelease(&This->Lock);
if (This->TotalSendCompleteOffset != UINT64_MAX) {
if (QueueWork) {
This->Queue();
}
}
Expand Down Expand Up @@ -656,10 +665,7 @@ void TcpConnection::Process()
}
}
if (BatchedSendData && !Shutdown) {
if (QUIC_FAILED(
CxPlatSocketSend(Socket, &Route, BatchedSendData))) {
Shutdown = true;
}
CxPlatSocketSend(Socket, &Route, BatchedSendData);
BatchedSendData = nullptr;
}
if (IndicateSendComplete) {
Expand Down Expand Up @@ -754,7 +760,7 @@ bool TcpConnection::ProcessTls(const uint8_t* Buffer, uint32_t BufferLength)
IndicateConnect = true;
}

while (BaseOffset < TlsState.BufferTotalLength) {
while (!Shutdown && BaseOffset < TlsState.BufferTotalLength) {
if (TlsState.BufferOffsetHandshake) {
if (BaseOffset < TlsState.BufferOffsetHandshake) {
uint16_t Length = (uint16_t)(TlsState.BufferOffsetHandshake - BaseOffset);
Expand Down Expand Up @@ -808,7 +814,9 @@ bool TcpConnection::SendTlsData(const uint8_t* Buffer, uint16_t BufferLength, ui
}

SendBuffer->Length = sizeof(TcpFrame) + Frame->Length + CXPLAT_ENCRYPTION_OVERHEAD;
return FinalizeSendBuffer(SendBuffer);
FinalizeSendBuffer(SendBuffer);

return true;
}

bool TcpConnection::ProcessReceive()
Expand Down Expand Up @@ -1008,11 +1016,9 @@ bool TcpConnection::ProcessSend()
}

SendBuffer->Length = sizeof(TcpFrame) + Frame->Length + CXPLAT_ENCRYPTION_OVERHEAD;
if (!FinalizeSendBuffer(SendBuffer)) {
return false;
}
FinalizeSendBuffer(SendBuffer);

} while (NextSendData->Length > Offset);
} while (!Shutdown && NextSendData->Length > Offset);

NextSendData->Offset = TotalSendOffset;
NextSendData = NextSendData->Next;
Expand Down Expand Up @@ -1088,18 +1094,14 @@ void TcpConnection::FreeSendBuffer(QUIC_BUFFER* SendBuffer)
CxPlatSendDataFreeBuffer(BatchedSendData, SendBuffer);
}

bool TcpConnection::FinalizeSendBuffer(QUIC_BUFFER* SendBuffer)
void TcpConnection::FinalizeSendBuffer(QUIC_BUFFER* SendBuffer)
{
TotalSendOffset += SendBuffer->Length;
if (SendBuffer->Length != TLS_BLOCK_SIZE ||
CxPlatSendDataIsFull(BatchedSendData)) {
auto Status = CxPlatSocketSend(Socket, &Route, BatchedSendData);
CxPlatSocketSend(Socket, &Route, BatchedSendData);
BatchedSendData = nullptr;
if (QUIC_FAILED(Status)) {
return false;
}
}
return true;
}

bool TcpConnection::Send(TcpSendData* Data)
Expand Down
2 changes: 1 addition & 1 deletion src/perf/lib/Tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class TcpConnection {
bool EncryptFrame(TcpFrame* Frame);
QUIC_BUFFER* NewSendBuffer();
void FreeSendBuffer(QUIC_BUFFER* SendBuffer);
bool FinalizeSendBuffer(QUIC_BUFFER* SendBuffer);
void FinalizeSendBuffer(QUIC_BUFFER* SendBuffer);
bool TryAddRef() { return CxPlatRefIncrementNonZero(&Ref, 1) != FALSE; }
void Release() { if (CxPlatRefDecrement(&Ref)) delete this; }
public:
Expand Down
6 changes: 2 additions & 4 deletions src/platform/datapath_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ CxPlatSendDataSend(
_In_ CXPLAT_SEND_DATA* SendData
);

QUIC_STATUS
void
SocketSend(
_In_ CXPLAT_SOCKET* Socket,
_In_ const CXPLAT_ROUTE* Route,
Expand Down Expand Up @@ -2272,7 +2272,7 @@ SocketSend(
&SocketContext->FlushTxSqe.Sqe,
&SocketContext->FlushTxSqe));
}
return QUIC_STATUS_SUCCESS;
return;
}

//
Expand All @@ -2299,8 +2299,6 @@ SocketSend(
}
CxPlatSendDataFree(SendData);
}

return Status;
}

//
Expand Down
20 changes: 7 additions & 13 deletions src/platform/datapath_kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2089,7 +2089,7 @@ CxPlatSocketSendInternal(
return Status;
}

QUIC_STATUS
void
CxPlatSocketSend(
_In_ CXPLAT_SOCKET* Socket,
_In_ const CXPLAT_ROUTE* Route,
Expand All @@ -2098,18 +2098,12 @@ CxPlatSocketSend(
{
UNREFERENCED_PARAMETER(Socket);
CXPLAT_DBG_ASSERT(Route->Queue);
CXPLAT_SOCKET_CONTEXT* SocketContext = Route->Queue;
QUIC_STATUS Status =
CxPlatSocketSendInternal(
SocketContext,
&Route->LocalAddress,
&Route->RemoteAddress,
SendData,
FALSE);
if (Status == QUIC_STATUS_PENDING) {
Status = QUIC_STATUS_SUCCESS;
}
return Status;
CxPlatSocketSendInternal(
Route->Queue,
&Route->LocalAddress,
&Route->RemoteAddress,
SendData,
FALSE);
}

uint16_t
Expand Down
4 changes: 1 addition & 3 deletions src/platform/datapath_winkernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,7 @@ CxPlatSocketPrepareSendData(
}

_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
void
CxPlatSocketSend(
_In_ CXPLAT_SOCKET* Binding,
_In_ const CXPLAT_ROUTE* Route,
Expand Down Expand Up @@ -3120,8 +3120,6 @@ CxPlatSocketSend(
// Callback still gets invoked on failure to do the cleanup.
//
}

return STATUS_SUCCESS;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
Expand Down
Loading

0 comments on commit 6fac5c4

Please sign in to comment.