Skip to content

Commit a65ad5e

Browse files
authored
Add ConnectionOpenInPartition (#4987)
1 parent b9c0061 commit a65ad5e

File tree

11 files changed

+184
-7
lines changed

11 files changed

+184
-7
lines changed

Diff for: docs/api/ConnectionOpen.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Once the connection has been shutdown, it must be cleaned up with a call to [Con
5252
5353
# See Also
5454
55+
[ConnectionOpenInPartition](ConnectionOpenInPartition.md)<br>
5556
[ConnectionClose](ConnectionClose.md)<br>
5657
[ConnectionShutdown](ConnectionShutdown.md)<br>
5758
[ConnectionStart](ConnectionStart.md)<br>

Diff for: docs/api/ConnectionOpenInPartition.md

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
ConnectionOpenInPartition function
2+
======
3+
4+
Creates a new connection in a specific partition.
5+
6+
# Syntax
7+
8+
```C
9+
typedef
10+
_IRQL_requires_max_(DISPATCH_LEVEL)
11+
QUIC_STATUS
12+
(QUIC_API * QUIC_CONNECTION_OPEN_IN_PARTITION_FN)(
13+
_In_ _Pre_defensive_ HQUIC Registration,
14+
_In_ uint16_t PartitionIndex,
15+
_In_ _Pre_defensive_ QUIC_CONNECTION_CALLBACK_HANDLER Handler,
16+
_In_opt_ void* Context,
17+
_Outptr_ _At_(*Connection, __drv_allocatesMem(Mem)) _Pre_defensive_
18+
HQUIC* Connection
19+
);
20+
```
21+
22+
# Parameters
23+
24+
`Registration`
25+
26+
The valid handle to an open registration object.
27+
28+
`PartitionIndex`
29+
30+
An index into the global partition set.
31+
32+
`Handler`
33+
34+
A pointer to the app's callback handler to be invoked for all connection events.
35+
36+
`Context`
37+
38+
The app context pointer (possibly null) to be associated with the connection object.
39+
40+
`Connection`
41+
42+
On success, returns a handle to the newly opened connection object.
43+
44+
# Return Value
45+
46+
The function returns a [QUIC_STATUS](QUIC_STATUS.md). The app may use `QUIC_FAILED` or `QUIC_SUCCEEDED` to determine if the function failed or succeeded.
47+
48+
# Remarks
49+
50+
See [ConnectionOpen](ConnectionOpen.md#Remarks) for more remarks.
51+
52+
This function is the same as `ConnectionOpen` with the exception that this puts the connection in an explicit partition instead of inferring it based on the calling thread's current processor.
53+
54+
# See Also
55+
56+
[ConnectionOpen](ConnectionOpen.md)<br>
57+
[ConnectionClose](ConnectionClose.md)<br>
58+
[ConnectionShutdown](ConnectionShutdown.md)<br>
59+
[ConnectionStart](ConnectionStart.md)<br>
60+
[QUIC_CONNECTION_CALLBACK](QUIC_CONNECTION_CALLBACK.md)<br>
61+
[QUIC_CONNECTION_EVENT](QUIC_CONNECTION_EVENT.md)<br>

Diff for: src/core/api.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ MsQuicConnectionOpen(
4040
_Outptr_ _At_(*NewConnection, __drv_allocatesMem(Mem)) _Pre_defensive_
4141
HQUIC *NewConnection
4242
)
43+
{
44+
return
45+
MsQuicConnectionOpenInPartition(
46+
RegistrationHandle,
47+
QuicLibraryGetCurrentPartition()->Index,
48+
Handler,
49+
Context,
50+
NewConnection);
51+
}
52+
53+
_IRQL_requires_max_(DISPATCH_LEVEL)
54+
QUIC_STATUS
55+
QUIC_API
56+
MsQuicConnectionOpenInPartition(
57+
_In_ _Pre_defensive_ HQUIC RegistrationHandle,
58+
_In_ uint16_t PartitionIndex,
59+
_In_ _Pre_defensive_ QUIC_CONNECTION_CALLBACK_HANDLER Handler,
60+
_In_opt_ void* Context,
61+
_Outptr_ _At_(*NewConnection, __drv_allocatesMem(Mem)) _Pre_defensive_
62+
HQUIC *NewConnection
63+
)
4364
{
4465
QUIC_STATUS Status;
4566
QUIC_REGISTRATION* Registration;
@@ -52,6 +73,7 @@ MsQuicConnectionOpen(
5273
RegistrationHandle);
5374

5475
if (!IS_REGISTRATION_HANDLE(RegistrationHandle) ||
76+
PartitionIndex >= MsQuicLib.PartitionCount ||
5577
NewConnection == NULL ||
5678
Handler == NULL) {
5779
Status = QUIC_STATUS_INVALID_PARAMETER;
@@ -68,7 +90,7 @@ MsQuicConnectionOpen(
6890
Status =
6991
QuicConnAlloc(
7092
Registration,
71-
QuicLibraryGetCurrentPartition(),
93+
&MsQuicLib.Partitions[PartitionIndex],
7294
NULL,
7395
NULL,
7496
&Connection);

Diff for: src/core/api.h

+12
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ MsQuicConnectionOpen(
111111
HQUIC *Connection
112112
);
113113

114+
_IRQL_requires_max_(DISPATCH_LEVEL)
115+
QUIC_STATUS
116+
QUIC_API
117+
MsQuicConnectionOpenInPartition(
118+
_In_ _Pre_defensive_ HQUIC Registration,
119+
_In_ uint16_t PartitionIndex,
120+
_In_ _Pre_defensive_ QUIC_CONNECTION_CALLBACK_HANDLER Handler,
121+
_In_opt_ void* Context,
122+
_Outptr_ _At_(*Connection, __drv_allocatesMem(Mem)) _Pre_defensive_
123+
HQUIC *Connection
124+
);
125+
114126
_IRQL_requires_max_(PASSIVE_LEVEL)
115127
void
116128
QUIC_API

Diff for: src/core/library.c

+1
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ MsQuicOpenVersion(
17871787
Api->ListenerStop = MsQuicListenerStop;
17881788

17891789
Api->ConnectionOpen = MsQuicConnectionOpen;
1790+
Api->ConnectionOpenInPartition = MsQuicConnectionOpenInPartition;
17901791
Api->ConnectionClose = MsQuicConnectionClose;
17911792
Api->ConnectionShutdown = MsQuicConnectionShutdown;
17921793
Api->ConnectionStart = MsQuicConnectionStart;

Diff for: src/cs/lib/msquic_generated.cs

+3
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,9 @@ internal unsafe partial struct QUIC_API_TABLE
33883388
[NativeTypeName("QUIC_CONNECTION_COMP_CERT_FN")]
33893389
internal delegate* unmanaged[Cdecl]<QUIC_HANDLE*, byte, QUIC_TLS_ALERT_CODES, int> ConnectionCertificateValidationComplete;
33903390

3391+
[NativeTypeName("QUIC_CONNECTION_OPEN_IN_PARTITION_FN")]
3392+
internal delegate* unmanaged[Cdecl]<QUIC_HANDLE*, ushort, delegate* unmanaged[Cdecl]<QUIC_HANDLE*, void*, QUIC_CONNECTION_EVENT*, int>, void*, QUIC_HANDLE**, int> ConnectionOpenInPartition;
3393+
33913394
[NativeTypeName("QUIC_STREAM_PROVIDE_RECEIVE_BUFFERS_FN")]
33923395
internal delegate* unmanaged[Cdecl]<QUIC_HANDLE*, uint, QUIC_BUFFER*, int> StreamProvideReceiveBuffers;
33933396

Diff for: src/inc/msquic.h

+14
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,17 @@ QUIC_STATUS
13161316
_Outptr_ _At_(*Connection, __drv_allocatesMem(Mem)) _Pre_defensive_
13171317
HQUIC* Connection
13181318
);
1319+
typedef
1320+
_IRQL_requires_max_(DISPATCH_LEVEL)
1321+
QUIC_STATUS
1322+
(QUIC_API * QUIC_CONNECTION_OPEN_IN_PARTITION_FN)(
1323+
_In_ _Pre_defensive_ HQUIC Registration,
1324+
_In_ uint16_t PartitionIndex,
1325+
_In_ _Pre_defensive_ QUIC_CONNECTION_CALLBACK_HANDLER Handler,
1326+
_In_opt_ void* Context,
1327+
_Outptr_ _At_(*Connection, __drv_allocatesMem(Mem)) _Pre_defensive_
1328+
HQUIC* Connection
1329+
);
13191330

13201331
//
13211332
// Closes an existing connection.
@@ -1714,6 +1725,9 @@ typedef struct QUIC_API_TABLE {
17141725
QUIC_CONNECTION_COMP_RESUMPTION_FN ConnectionResumptionTicketValidationComplete; // Available from v2.2
17151726
QUIC_CONNECTION_COMP_CERT_FN ConnectionCertificateValidationComplete; // Available from v2.2
17161727

1728+
QUIC_CONNECTION_OPEN_IN_PARTITION_FN
1729+
ConnectionOpenInPartition; // Available from v2.5
1730+
17171731
#ifdef QUIC_API_ENABLE_PREVIEW_FEATURES
17181732
QUIC_STREAM_PROVIDE_RECEIVE_BUFFERS_FN
17191733
StreamProvideReceiveBuffers; // Available from v2.5

Diff for: src/inc/msquic.hpp

+23
Original file line numberDiff line numberDiff line change
@@ -1024,6 +1024,29 @@ struct MsQuicConnection {
10241024
}
10251025
}
10261026

1027+
MsQuicConnection(
1028+
_In_ const MsQuicRegistration& Registration,
1029+
_In_ uint16_t PartitionIndex,
1030+
_In_ MsQuicCleanUpMode CleanUpMode = CleanUpManual,
1031+
_In_ MsQuicConnectionCallback* Callback = NoOpCallback,
1032+
_In_ void* Context = nullptr
1033+
) noexcept : CleanUpMode(CleanUpMode), Callback(Callback), Context(Context) {
1034+
if (!Registration.IsValid()) {
1035+
InitStatus = Registration.GetInitStatus();
1036+
return;
1037+
}
1038+
if (QUIC_FAILED(
1039+
InitStatus =
1040+
MsQuic->ConnectionOpenInPartition(
1041+
Registration,
1042+
PartitionIndex,
1043+
(QUIC_CONNECTION_CALLBACK_HANDLER)MsQuicCallback,
1044+
this,
1045+
&Handle))) {
1046+
Handle = nullptr;
1047+
}
1048+
}
1049+
10271050
MsQuicConnection(
10281051
_In_ HQUIC ConnectionHandle,
10291052
_In_ MsQuicCleanUpMode CleanUpMode,

Diff for: src/rs/ffi/linux_bindings.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -5697,6 +5697,15 @@ pub type QUIC_CONNECTION_OPEN_FN = ::std::option::Option<
56975697
Connection: *mut HQUIC,
56985698
) -> ::std::os::raw::c_uint,
56995699
>;
5700+
pub type QUIC_CONNECTION_OPEN_IN_PARTITION_FN = ::std::option::Option<
5701+
unsafe extern "C" fn(
5702+
Registration: HQUIC,
5703+
PartitionIndex: u16,
5704+
Handler: QUIC_CONNECTION_CALLBACK_HANDLER,
5705+
Context: *mut ::std::os::raw::c_void,
5706+
Connection: *mut HQUIC,
5707+
) -> ::std::os::raw::c_uint,
5708+
>;
57005709
pub type QUIC_CONNECTION_CLOSE_FN = ::std::option::Option<unsafe extern "C" fn(Connection: HQUIC)>;
57015710
pub type QUIC_CONNECTION_SHUTDOWN_FN = ::std::option::Option<
57025711
unsafe extern "C" fn(
@@ -6367,12 +6376,13 @@ pub struct QUIC_API_TABLE {
63676376
pub DatagramSend: QUIC_DATAGRAM_SEND_FN,
63686377
pub ConnectionResumptionTicketValidationComplete: QUIC_CONNECTION_COMP_RESUMPTION_FN,
63696378
pub ConnectionCertificateValidationComplete: QUIC_CONNECTION_COMP_CERT_FN,
6379+
pub ConnectionOpenInPartition: QUIC_CONNECTION_OPEN_IN_PARTITION_FN,
63706380
pub StreamProvideReceiveBuffers: QUIC_STREAM_PROVIDE_RECEIVE_BUFFERS_FN,
63716381
pub ConnectionPoolCreate: QUIC_CONN_POOL_CREATE_FN,
63726382
}
63736383
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
63746384
const _: () = {
6375-
["Size of QUIC_API_TABLE"][::std::mem::size_of::<QUIC_API_TABLE>() - 264usize];
6385+
["Size of QUIC_API_TABLE"][::std::mem::size_of::<QUIC_API_TABLE>() - 272usize];
63766386
["Alignment of QUIC_API_TABLE"][::std::mem::align_of::<QUIC_API_TABLE>() - 8usize];
63776387
["Offset of field: QUIC_API_TABLE::SetContext"]
63786388
[::std::mem::offset_of!(QUIC_API_TABLE, SetContext) - 0usize];
@@ -6440,10 +6450,12 @@ const _: () = {
64406450
QUIC_API_TABLE,
64416451
ConnectionCertificateValidationComplete
64426452
) - 240usize];
6453+
["Offset of field: QUIC_API_TABLE::ConnectionOpenInPartition"]
6454+
[::std::mem::offset_of!(QUIC_API_TABLE, ConnectionOpenInPartition) - 248usize];
64436455
["Offset of field: QUIC_API_TABLE::StreamProvideReceiveBuffers"]
6444-
[::std::mem::offset_of!(QUIC_API_TABLE, StreamProvideReceiveBuffers) - 248usize];
6456+
[::std::mem::offset_of!(QUIC_API_TABLE, StreamProvideReceiveBuffers) - 256usize];
64456457
["Offset of field: QUIC_API_TABLE::ConnectionPoolCreate"]
6446-
[::std::mem::offset_of!(QUIC_API_TABLE, ConnectionPoolCreate) - 256usize];
6458+
[::std::mem::offset_of!(QUIC_API_TABLE, ConnectionPoolCreate) - 264usize];
64476459
};
64486460
pub const QUIC_STATUS_SUCCESS: QUIC_STATUS = 0;
64496461
pub const QUIC_STATUS_PENDING: QUIC_STATUS = 4294967294;

Diff for: src/rs/ffi/win_bindings.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -5726,6 +5726,15 @@ pub type QUIC_CONNECTION_OPEN_FN = ::std::option::Option<
57265726
Connection: *mut HQUIC,
57275727
) -> HRESULT,
57285728
>;
5729+
pub type QUIC_CONNECTION_OPEN_IN_PARTITION_FN = ::std::option::Option<
5730+
unsafe extern "C" fn(
5731+
Registration: HQUIC,
5732+
PartitionIndex: u16,
5733+
Handler: QUIC_CONNECTION_CALLBACK_HANDLER,
5734+
Context: *mut ::std::os::raw::c_void,
5735+
Connection: *mut HQUIC,
5736+
) -> HRESULT,
5737+
>;
57295738
pub type QUIC_CONNECTION_CLOSE_FN = ::std::option::Option<unsafe extern "C" fn(Connection: HQUIC)>;
57305739
pub type QUIC_CONNECTION_SHUTDOWN_FN = ::std::option::Option<
57315740
unsafe extern "C" fn(
@@ -6388,12 +6397,13 @@ pub struct QUIC_API_TABLE {
63886397
pub DatagramSend: QUIC_DATAGRAM_SEND_FN,
63896398
pub ConnectionResumptionTicketValidationComplete: QUIC_CONNECTION_COMP_RESUMPTION_FN,
63906399
pub ConnectionCertificateValidationComplete: QUIC_CONNECTION_COMP_CERT_FN,
6400+
pub ConnectionOpenInPartition: QUIC_CONNECTION_OPEN_IN_PARTITION_FN,
63916401
pub StreamProvideReceiveBuffers: QUIC_STREAM_PROVIDE_RECEIVE_BUFFERS_FN,
63926402
pub ConnectionPoolCreate: QUIC_CONN_POOL_CREATE_FN,
63936403
}
63946404
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
63956405
const _: () = {
6396-
["Size of QUIC_API_TABLE"][::std::mem::size_of::<QUIC_API_TABLE>() - 264usize];
6406+
["Size of QUIC_API_TABLE"][::std::mem::size_of::<QUIC_API_TABLE>() - 272usize];
63976407
["Alignment of QUIC_API_TABLE"][::std::mem::align_of::<QUIC_API_TABLE>() - 8usize];
63986408
["Offset of field: QUIC_API_TABLE::SetContext"]
63996409
[::std::mem::offset_of!(QUIC_API_TABLE, SetContext) - 0usize];
@@ -6461,10 +6471,12 @@ const _: () = {
64616471
QUIC_API_TABLE,
64626472
ConnectionCertificateValidationComplete
64636473
) - 240usize];
6474+
["Offset of field: QUIC_API_TABLE::ConnectionOpenInPartition"]
6475+
[::std::mem::offset_of!(QUIC_API_TABLE, ConnectionOpenInPartition) - 248usize];
64646476
["Offset of field: QUIC_API_TABLE::StreamProvideReceiveBuffers"]
6465-
[::std::mem::offset_of!(QUIC_API_TABLE, StreamProvideReceiveBuffers) - 248usize];
6477+
[::std::mem::offset_of!(QUIC_API_TABLE, StreamProvideReceiveBuffers) - 256usize];
64666478
["Offset of field: QUIC_API_TABLE::ConnectionPoolCreate"]
6467-
[::std::mem::offset_of!(QUIC_API_TABLE, ConnectionPoolCreate) - 256usize];
6479+
[::std::mem::offset_of!(QUIC_API_TABLE, ConnectionPoolCreate) - 264usize];
64686480
};
64696481
pub const QUIC_STATUS_SUCCESS: QUIC_STATUS = 0;
64706482
pub const QUIC_STATUS_PENDING: QUIC_STATUS = 459749;

Diff for: src/test/lib/ApiTest.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,22 @@ void QuicTestValidateConnection()
692692
&Connection.Handle));
693693
}
694694

695+
//
696+
// Invalid partition index.
697+
//
698+
{
699+
TestScopeLogger logScope("Invalid partition index");
700+
ConnectionScope Connection;
701+
TEST_QUIC_STATUS(
702+
QUIC_STATUS_INVALID_PARAMETER,
703+
MsQuic->ConnectionOpenInPartition(
704+
Registration,
705+
UINT16_MAX,
706+
DummyConnectionCallback,
707+
nullptr,
708+
&Connection.Handle));
709+
}
710+
695711
//
696712
// Null connection parameter.
697713
//

0 commit comments

Comments
 (0)