@@ -15,6 +15,7 @@ limitations under the License.
15
15
-------------------------------------------------------------------*/
16
16
17
17
#include "quicer_connection.h"
18
+
18
19
#include <assert.h>
19
20
#include <unistd.h>
20
21
@@ -23,7 +24,8 @@ limitations under the License.
23
24
//
24
25
_IRQL_requires_max_ (DISPATCH_LEVEL )
25
26
_Function_class_ (QUIC_CONNECTION_CALLBACK ) QUIC_STATUS QUIC_API
26
- ClientConnectionCallback (_In_ HQUIC Connection , _In_opt_ void * Context ,
27
+ ClientConnectionCallback (_In_ HQUIC Connection ,
28
+ _In_opt_ void * Context ,
27
29
_Inout_ QUIC_CONNECTION_EVENT * Event )
28
30
{
29
31
QuicerConnCTX * c_ctx = (QuicerConnCTX * )Context ;
@@ -39,8 +41,11 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
39
41
// A monitor is automatically removed when it triggers or when the
40
42
// resource is deallocated.
41
43
enif_monitor_process (NULL , c_ctx , & c_ctx -> owner -> Pid , c_ctx -> owner_mon );
42
- if (!enif_send (NULL , & (c_ctx -> owner -> Pid ), NULL ,
43
- enif_make_tuple3 (env , enif_make_atom (env , "quic" ),
44
+ if (!enif_send (NULL ,
45
+ & (c_ctx -> owner -> Pid ),
46
+ NULL ,
47
+ enif_make_tuple3 (env ,
48
+ enif_make_atom (env , "quic" ),
44
49
enif_make_atom (env , "connected" ),
45
50
enif_make_resource (env , c_ctx ))))
46
51
{
@@ -69,8 +74,11 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
69
74
70
75
enif_monitor_process (NULL , s_ctx , & s_ctx -> owner -> Pid , s_ctx -> owner_mon );
71
76
72
- if (!enif_send (NULL , & (acc -> Pid ), NULL ,
73
- enif_make_tuple3 (env , enif_make_atom (env , "quic" ),
77
+ if (!enif_send (NULL ,
78
+ & (acc -> Pid ),
79
+ NULL ,
80
+ enif_make_tuple3 (env ,
81
+ enif_make_atom (env , "quic" ),
74
82
enif_make_atom (env , "new_stream" ),
75
83
enif_make_resource (env , s_ctx ))))
76
84
{
@@ -81,7 +89,8 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
81
89
}
82
90
83
91
MsQuic -> SetCallbackHandler (Event -> PEER_STREAM_STARTED .Stream ,
84
- (void * )ClientStreamCallback , s_ctx );
92
+ (void * )ClientStreamCallback ,
93
+ s_ctx );
85
94
break ;
86
95
case QUIC_CONNECTION_EVENT_SHUTDOWN_INITIATED_BY_TRANSPORT :
87
96
//
@@ -94,30 +103,27 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
94
103
//
95
104
// The connection was explicitly shut down by the peer.
96
105
//
97
- report = enif_make_tuple3 (env ,
98
- ATOM_QUIC , ATOM_SHUTDOWN ,
99
- enif_make_resource ( env , c_ctx )
100
- );
101
-
102
- if (! enif_send ( NULL , & ( c_ctx -> owner -> Pid ), NULL , report )) {
103
- // Owner is gone, we shutdown our side as well.
104
- MsQuic -> ConnectionShutdown ( Connection , QUIC_CONNECTION_SHUTDOWN_FLAG_NONE ,
105
- QUIC_STATUS_UNREACHABLE );
106
- }
106
+ report = enif_make_tuple3 (
107
+ env , ATOM_QUIC , ATOM_SHUTDOWN , enif_make_resource ( env , c_ctx ));
108
+
109
+ if (! enif_send ( NULL , & ( c_ctx -> owner -> Pid ), NULL , report ))
110
+ {
111
+ // Owner is gone, we shutdown our side as well.
112
+ MsQuic -> ConnectionShutdown ( Connection ,
113
+ QUIC_CONNECTION_SHUTDOWN_FLAG_NONE ,
114
+ QUIC_STATUS_UNREACHABLE );
115
+ }
107
116
break ;
108
117
case QUIC_CONNECTION_EVENT_SHUTDOWN_COMPLETE :
109
118
//
110
119
// The connection has completed the shutdown process and is ready to be
111
120
// safely cleaned up.
112
121
//
113
- report = enif_make_tuple3 (env ,
114
- ATOM_QUIC , ATOM_CLOSED ,
115
- enif_make_resource (env , c_ctx )
116
- );
122
+ report = enif_make_tuple3 (
123
+ env , ATOM_QUIC , ATOM_CLOSED , enif_make_resource (env , c_ctx ));
117
124
118
125
enif_send (NULL , & (c_ctx -> owner -> Pid ), NULL , report );
119
126
120
-
121
127
if (!Event -> SHUTDOWN_COMPLETE .AppCloseInProgress )
122
128
{
123
129
MsQuic -> ConnectionClose (Connection );
@@ -139,7 +145,8 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
139
145
}
140
146
141
147
QUIC_STATUS
142
- ServerConnectionCallback (HQUIC Connection , void * Context ,
148
+ ServerConnectionCallback (HQUIC Connection ,
149
+ void * Context ,
143
150
QUIC_CONNECTION_EVENT * Event )
144
151
{
145
152
QuicerConnCTX * c_ctx = (QuicerConnCTX * )Context ;
@@ -179,8 +186,11 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
179
186
ERL_NIF_TERM ConnHandler = enif_make_resource (c_ctx -> env , c_ctx );
180
187
// testing this, just unblock accecptor
181
188
// should pick a 'acceptor' here?
182
- if (!enif_send (NULL , acc_pid , NULL ,
183
- enif_make_tuple (c_ctx -> env , 2 ,
189
+ if (!enif_send (NULL ,
190
+ acc_pid ,
191
+ NULL ,
192
+ enif_make_tuple (c_ctx -> env ,
193
+ 2 ,
184
194
enif_make_atom (c_ctx -> env , "new_conn" ),
185
195
ConnHandler )))
186
196
{
@@ -204,27 +214,25 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
204
214
//
205
215
// The connection was explicitly shut down by the peer.
206
216
//
207
- report = enif_make_tuple3 (env ,
208
- ATOM_QUIC , ATOM_SHUTDOWN ,
209
- enif_make_resource (env , c_ctx )
210
- );
217
+ report = enif_make_tuple3 (
218
+ env , ATOM_QUIC , ATOM_SHUTDOWN , enif_make_resource (env , c_ctx ));
211
219
212
- if (!enif_send (NULL , & (c_ctx -> owner -> Pid ), NULL , report )) {
213
- // Owner is gone, we shutdown our side as well.
214
- MsQuic -> ConnectionShutdown (Connection , QUIC_CONNECTION_SHUTDOWN_FLAG_NONE ,
215
- QUIC_STATUS_UNREACHABLE );
216
- }
220
+ if (!enif_send (NULL , & (c_ctx -> owner -> Pid ), NULL , report ))
221
+ {
222
+ // Owner is gone, we shutdown our side as well.
223
+ MsQuic -> ConnectionShutdown (Connection ,
224
+ QUIC_CONNECTION_SHUTDOWN_FLAG_NONE ,
225
+ QUIC_STATUS_UNREACHABLE );
226
+ }
217
227
218
228
break ;
219
229
case QUIC_CONNECTION_EVENT_SHUTDOWN_COMPLETE :
220
230
//
221
231
// The connection has completed the shutdown process and is ready to be
222
232
// safely cleaned up.
223
233
//
224
- report = enif_make_tuple3 (env ,
225
- ATOM_QUIC , ATOM_CLOSED ,
226
- enif_make_resource (env , c_ctx )
227
- );
234
+ report = enif_make_tuple3 (
235
+ env , ATOM_QUIC , ATOM_CLOSED , enif_make_resource (env , c_ctx ));
228
236
229
237
enif_send (NULL , & (c_ctx -> owner -> Pid ), NULL , report );
230
238
@@ -264,8 +272,11 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
264
272
s_ctx -> owner = acc ;
265
273
266
274
// @todo add monitor here.
267
- if (!enif_send (NULL , acc_pid , NULL ,
268
- enif_make_tuple3 (env , enif_make_atom (env , "quic" ),
275
+ if (!enif_send (NULL ,
276
+ acc_pid ,
277
+ NULL ,
278
+ enif_make_tuple3 (env ,
279
+ enif_make_atom (env , "quic" ),
269
280
enif_make_atom (env , "new_stream" ),
270
281
enif_make_resource (env , s_ctx ))))
271
282
{
@@ -274,13 +285,14 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
274
285
// shutdown the connection gracefully.
275
286
// @todo, check rfc for the error code
276
287
MsQuic -> ConnectionShutdown (
277
- Connection , QUIC_CONNECTION_SHUTDOWN_FLAG_NONE , NO_ERROR );
288
+ Connection , QUIC_CONNECTION_SHUTDOWN_FLAG_NONE , NO_ERROR );
278
289
return QUIC_STATUS_UNREACHABLE ;
279
290
}
280
291
else
281
292
{
282
293
MsQuic -> SetCallbackHandler (Event -> PEER_STREAM_STARTED .Stream ,
283
- (void * )ServerStreamCallback , s_ctx );
294
+ (void * )ServerStreamCallback ,
295
+ s_ctx );
284
296
}
285
297
break ;
286
298
case QUIC_CONNECTION_EVENT_RESUMED :
@@ -296,7 +308,8 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
296
308
}
297
309
298
310
ERL_NIF_TERM
299
- async_connect3 (ErlNifEnv * env , __unused_parm__ int argc ,
311
+ async_connect3 (ErlNifEnv * env ,
312
+ __unused_parm__ int argc ,
300
313
__unused_parm__ const ERL_NIF_TERM argv [])
301
314
{
302
315
QUIC_STATUS Status ;
@@ -331,17 +344,20 @@ async_connect3(ErlNifEnv *env, __unused_parm__ int argc,
331
344
return ERROR_TUPLE_2 (ATOM_CONFIG_ERROR );
332
345
}
333
346
334
- if (QUIC_FAILED (Status = MsQuic -> ConnectionOpen (
335
- Registration , ClientConnectionCallback , c_ctx ,
336
- & (c_ctx -> Connection ))))
347
+ if (QUIC_FAILED (Status = MsQuic -> ConnectionOpen (Registration ,
348
+ ClientConnectionCallback ,
349
+ c_ctx ,
350
+ & (c_ctx -> Connection ))))
337
351
{
338
352
destroy_c_ctx (c_ctx );
339
353
return ERROR_TUPLE_2 (ATOM_CONN_OPEN_ERROR );
340
354
}
341
355
342
- if (QUIC_FAILED (Status = MsQuic -> ConnectionStart (
343
- c_ctx -> Connection , c_ctx -> Configuration ,
344
- QUIC_ADDRESS_FAMILY_UNSPEC , host , port )))
356
+ if (QUIC_FAILED (Status = MsQuic -> ConnectionStart (c_ctx -> Connection ,
357
+ c_ctx -> Configuration ,
358
+ QUIC_ADDRESS_FAMILY_UNSPEC ,
359
+ host ,
360
+ port )))
345
361
{
346
362
MsQuic -> ConnectionClose (c_ctx -> Connection );
347
363
destroy_c_ctx (c_ctx );
@@ -354,7 +370,8 @@ async_connect3(ErlNifEnv *env, __unused_parm__ int argc,
354
370
}
355
371
356
372
ERL_NIF_TERM
357
- async_accept2 (ErlNifEnv * env , __unused_parm__ int argc ,
373
+ async_accept2 (ErlNifEnv * env ,
374
+ __unused_parm__ int argc ,
358
375
const ERL_NIF_TERM argv [])
359
376
{
360
377
QuicerListenerCTX * l_ctx ;
@@ -384,7 +401,8 @@ async_accept2(ErlNifEnv *env, __unused_parm__ int argc,
384
401
385
402
//@todo, shutdown with error
386
403
ERL_NIF_TERM
387
- close_connection1 (ErlNifEnv * env , __unused_parm__ int argc ,
404
+ close_connection1 (ErlNifEnv * env ,
405
+ __unused_parm__ int argc ,
388
406
const ERL_NIF_TERM argv [])
389
407
{
390
408
QuicerConnCTX * c_ctx ;
@@ -394,7 +412,8 @@ close_connection1(ErlNifEnv *env, __unused_parm__ int argc,
394
412
}
395
413
MsQuic -> ConnectionShutdown (c_ctx -> Connection ,
396
414
//@todo, check rfc for the error code
397
- QUIC_CONNECTION_SHUTDOWN_FLAG_NONE , NO_ERROR );
415
+ QUIC_CONNECTION_SHUTDOWN_FLAG_NONE ,
416
+ NO_ERROR );
398
417
return ATOM_OK ;
399
418
}
400
419
@@ -450,17 +469,16 @@ addr2eterm(ErlNifEnv *env, QUIC_ADDR *addr)
450
469
uint16_t * ip = (uint16_t * )& addr -> Ipv6 .sin6_addr ;
451
470
return enif_make_tuple2 (
452
471
env ,
453
- enif_make_tuple8 (
454
- env ,
455
- enif_make_int (env , ntohs (ip [0 ])),
456
- enif_make_int (env , ntohs (ip [1 ])),
457
- enif_make_int (env , ntohs (ip [2 ])),
458
- enif_make_int (env , ntohs (ip [3 ])),
459
- enif_make_int (env , ntohs (ip [4 ])),
460
- enif_make_int (env , ntohs (ip [5 ])),
461
- enif_make_int (env , ntohs (ip [6 ])),
462
- enif_make_int (env , ntohs (ip [7 ]))),
463
- enif_make_int (env , addr -> Ipv6 .sin6_port ));
472
+ enif_make_tuple8 (env ,
473
+ enif_make_int (env , ntohs (ip [0 ])),
474
+ enif_make_int (env , ntohs (ip [1 ])),
475
+ enif_make_int (env , ntohs (ip [2 ])),
476
+ enif_make_int (env , ntohs (ip [3 ])),
477
+ enif_make_int (env , ntohs (ip [4 ])),
478
+ enif_make_int (env , ntohs (ip [5 ])),
479
+ enif_make_int (env , ntohs (ip [6 ])),
480
+ enif_make_int (env , ntohs (ip [7 ]))),
481
+ enif_make_int (env , addr -> Ipv6 .sin6_port ));
464
482
}
465
483
else
466
484
{
0 commit comments