Skip to content

Commit f77e143

Browse files
committed
more fixes
1 parent ec0a8e6 commit f77e143

File tree

5 files changed

+152
-64
lines changed

5 files changed

+152
-64
lines changed

src/core/api.c

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ QuicConnectionOpenInPartition(
7979
goto Error;
8080
}
8181

82+
//
83+
// Hard partitioning is only supported on a subset of platforms.
84+
//
85+
#if defined(__linux__) && !defined(CXPLAT_USE_IO_URING) && !defined(CXPLAT_LINUX_XDP_ENABLED)
8286
Connection->State.Partitioned = Partitioned;
87+
#endif
8388
Connection->ClientCallbackHandler = Handler;
8489
Connection->ClientContext = Context;
8590

@@ -150,6 +155,7 @@ MsQuicConnectionClose(
150155
)
151156
{
152157
QUIC_CONNECTION* Connection;
158+
BOOLEAN WaitForCompletion = TRUE;
153159

154160
CXPLAT_PASSIVE_CODE();
155161

@@ -182,7 +188,7 @@ MsQuicConnectionClose(
182188

183189
CXPLAT_TEL_ASSERT(!Connection->State.HandleClosed);
184190

185-
if (MsQuicLib.CustomExecutions || IsWorkerThread) {
191+
if (IsWorkerThread) {
186192
//
187193
// Execute this blocking API call inline if called on the worker thread.
188194
//
@@ -198,39 +204,51 @@ MsQuicConnectionClose(
198204
} else {
199205

200206
CXPLAT_EVENT CompletionEvent;
201-
QUIC_OPERATION Oper = { 0 };
202-
QUIC_API_CONTEXT ApiCtx;
203207

204-
Oper.Type = QUIC_OPER_TYPE_API_CALL;
205-
Oper.FreeAfterProcess = FALSE;
206-
Oper.API_CALL.Context = &ApiCtx;
208+
Connection->CloseOper.Type = QUIC_OPER_TYPE_API_CALL;
209+
Connection->CloseOper.FreeAfterProcess = FALSE;
210+
Connection->CloseOper.API_CALL.Context = &Connection->CloseApiContext;
207211

208-
ApiCtx.Type = QUIC_API_TYPE_CONN_CLOSE;
209-
CxPlatEventInitialize(&CompletionEvent, TRUE, FALSE);
210-
ApiCtx.Completed = &CompletionEvent;
211-
ApiCtx.Status = NULL;
212+
Connection->CloseApiContext.Type = QUIC_API_TYPE_CONN_CLOSE;
213+
Connection->CloseApiContext.Status = NULL;
214+
215+
if (MsQuicLib.CustomExecutions) {
216+
//
217+
// For custom executions, ConnectionClose completes asynchronously.
218+
//
219+
Connection->CloseApiContext.Completed = NULL;
220+
WaitForCompletion = FALSE;
221+
} else {
222+
CxPlatEventInitialize(&CompletionEvent, TRUE, FALSE);
223+
Connection->CloseApiContext.Completed = &CompletionEvent;
224+
}
212225

213226
//
214227
// Queue the operation and wait for it to be processed.
215228
//
216-
QuicConnQueueOper(Connection, &Oper);
217-
QuicTraceEvent(
218-
ApiWaitOperation,
219-
"[ api] Waiting on operation");
220-
CxPlatEventWaitForever(CompletionEvent);
221-
CxPlatEventUninitialize(CompletionEvent);
229+
QuicConnQueueOper(Connection, &Connection->CloseOper);
230+
231+
if (WaitForCompletion) {
232+
QuicTraceEvent(
233+
ApiWaitOperation,
234+
"[ api] Waiting on operation");
235+
CxPlatEventWaitForever(CompletionEvent);
236+
CxPlatEventUninitialize(CompletionEvent);
237+
}
222238
}
223239

224240
//
225241
// Connection can only be released by the application after the released
226242
// flag was set, in response to the CONN_CLOSE operation was processed.
227243
//
228-
CXPLAT_TEL_ASSERT(Connection->State.HandleClosed);
244+
if (WaitForCompletion) {
245+
CXPLAT_TEL_ASSERT(Connection->State.HandleClosed);
229246

230-
//
231-
// Release the reference to the Connection.
232-
//
233-
QuicConnRelease(Connection, QUIC_CONN_REF_HANDLE_OWNER);
247+
//
248+
// Release the reference to the Connection.
249+
//
250+
QuicConnRelease(Connection, QUIC_CONN_REF_HANDLE_OWNER);
251+
}
234252

235253
Error:
236254

src/core/connection.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5597,8 +5597,8 @@ QuicConnRecvDatagramBatch(
55975597
RecvState->ResetIdleTimeout |= Packet->CompletelyValid;
55985598

55995599
if (Connection->Registration != NULL && !Connection->Registration->NoPartitioning &&
5600-
!Connection->State.Partitioned && Path->IsActive && !Path->PartitionUpdated &&
5601-
Packet->CompletelyValid &&
5600+
!Path->Binding->Partitioned && !Connection->State.Partitioned && Path->IsActive &&
5601+
!Path->PartitionUpdated && Packet->CompletelyValid &&
56025602
(Packets[i]->PartitionIndex % MsQuicLib.PartitionCount) != RecvState->PartitionIndex) {
56035603
RecvState->PartitionIndex = Packets[i]->PartitionIndex % MsQuicLib.PartitionCount;
56045604
RecvState->UpdatePartitionId = TRUE;
@@ -7579,6 +7579,14 @@ QuicConnProcessApiOperation(
75797579

75807580
case QUIC_API_TYPE_CONN_CLOSE:
75817581
QuicConnCloseHandle(Connection);
7582+
if (MsQuicLib.CustomExecutions && Connection->State.ExternalOwner) {
7583+
CXPLAT_TEL_ASSERT(Connection->State.HandleClosed);
7584+
//
7585+
// Release the external reference to the connection for async
7586+
// completion.
7587+
//
7588+
QuicConnRelease(Connection, QUIC_CONN_REF_HANDLE_OWNER);
7589+
}
75827590
break;
75837591

75847592
case QUIC_API_TYPE_CONN_SHUTDOWN:

src/core/connection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ typedef struct QUIC_CONNECTION {
559559
QUIC_OPERATION BackUpOper;
560560
QUIC_API_CONTEXT BackupApiContext;
561561
uint16_t BackUpOperUsed;
562+
QUIC_OPERATION CloseOper;
563+
QUIC_API_CONTEXT CloseApiContext;
562564

563565
//
564566
// The status code used for indicating transport closed notifications.

src/inc/msquic.hpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,19 +1149,22 @@ struct MsQuicConnection {
11491149
QUIC_UINT62 AppShutdownErrorCode {0};
11501150
bool HandshakeComplete {false};
11511151
bool HandshakeResumed {false};
1152+
bool Started {false};
11521153
uint32_t ResumptionTicketLength {0};
11531154
uint8_t* ResumptionTicket {nullptr};
11541155
#ifdef CX_PLATFORM_TYPE
11551156
CxPlatEvent HandshakeCompleteEvent;
11561157
CxPlatEvent ResumptionTicketReceivedEvent;
1158+
CxPlatEvent ShutdownCompleteEvent {true};
11571159
#endif // CX_PLATFORM_TYPE
11581160

11591161
MsQuicConnection(
11601162
_In_ const MsQuicRegistration& Registration,
11611163
_In_ MsQuicCleanUpMode CleanUpMode = CleanUpManual,
11621164
_In_ MsQuicConnectionCallback* Callback = NoOpCallback,
11631165
_In_ void* Context = nullptr
1164-
) noexcept : CleanUpMode(CleanUpMode), Callback(Callback), Context(Context) {
1166+
) noexcept : CleanUpMode(CleanUpMode), Callback(Callback), Context(Context)
1167+
{
11651168
if (!Registration.IsValid()) {
11661169
InitStatus = Registration.GetInitStatus();
11671170
return;
@@ -1213,6 +1216,11 @@ struct MsQuicConnection {
12131216

12141217
~MsQuicConnection() noexcept {
12151218
Close();
1219+
#ifdef CX_PLATFORM_TYPE
1220+
if (IsValid()) {
1221+
ShutdownCompleteEvent.WaitForever();
1222+
}
1223+
#endif // CX_PLATFORM_TYPE
12161224
delete[] ResumptionTicket;
12171225
}
12181226

@@ -1255,7 +1263,11 @@ struct MsQuicConnection {
12551263
const char* ServerName,
12561264
_In_ uint16_t ServerPort // Host byte order
12571265
) noexcept {
1258-
return MsQuic->ConnectionStart(Handle, Config, Family, ServerName, ServerPort);
1266+
QUIC_STATUS Status = MsQuic->ConnectionStart(Handle, Config, Family, ServerName, ServerPort);
1267+
if (QUIC_SUCCEEDED(Status)) {
1268+
Started = true;
1269+
}
1270+
return Status;
12591271
}
12601272

12611273
QUIC_STATUS
@@ -1485,6 +1497,9 @@ struct MsQuicConnection {
14851497
_Inout_ QUIC_CONNECTION_EVENT* Event
14861498
) noexcept {
14871499
CXPLAT_DBG_ASSERT(pThis);
1500+
auto DeleteOnExit =
1501+
Event->Type == QUIC_CONNECTION_EVENT_SHUTDOWN_COMPLETE &&
1502+
pThis->CleanUpMode == CleanUpAutoDelete;
14881503
if (Event->Type == QUIC_CONNECTION_EVENT_CONNECTED) {
14891504
pThis->HandshakeComplete = true;
14901505
pThis->HandshakeResumed = Event->CONNECTED.SessionResumed;
@@ -1516,10 +1531,10 @@ struct MsQuicConnection {
15161531
#endif // CX_PLATFORM_TYPE
15171532
}
15181533
}
1519-
auto DeleteOnExit =
1520-
Event->Type == QUIC_CONNECTION_EVENT_SHUTDOWN_COMPLETE &&
1521-
pThis->CleanUpMode == CleanUpAutoDelete;
15221534
auto Status = pThis->Callback(pThis, pThis->Context, Event);
1535+
if (Event->Type == QUIC_CONNECTION_EVENT_SHUTDOWN_COMPLETE) {
1536+
pThis->ShutdownCompleteEvent.Set();
1537+
}
15231538
if (DeleteOnExit) {
15241539
delete pThis;
15251540
}

0 commit comments

Comments
 (0)