Skip to content

Commit bb2cff9

Browse files
committed
chore(format): code style alignment
1 parent 0eeb8ca commit bb2cff9

13 files changed

+549
-332
lines changed

.clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
---
22
BasedOnStyle: GNU
33
SpaceBeforeParens: ControlStatements
4+
BinPackArguments: false
5+
BinPackParameters: false

c_src/quicer_config.c

+305-147
Large diffs are not rendered by default.

c_src/quicer_config.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ bool load_alpn(ErlNifEnv *env,
5151
unsigned *alpn_buffer_length,
5252
QUIC_BUFFER alpn_buffers[]);
5353
bool get_uint8_from_map(ErlNifEnv *env,
54-
const ERL_NIF_TERM map,
55-
ERL_NIF_TERM key,
56-
uint8_t* value);
54+
const ERL_NIF_TERM map,
55+
ERL_NIF_TERM key,
56+
uint8_t *value);
5757
bool get_uint16_from_map(ErlNifEnv *env,
5858
const ERL_NIF_TERM map,
5959
ERL_NIF_TERM key,
60-
uint16_t* value);
60+
uint16_t *value);
6161
bool get_uint32_from_map(ErlNifEnv *env,
6262
const ERL_NIF_TERM map,
6363
ERL_NIF_TERM key,
64-
uint32_t* value);
64+
uint32_t *value);
6565
bool get_uint64_from_map(ErlNifEnv *env,
6666
const ERL_NIF_TERM map,
6767
ERL_NIF_TERM key,
68-
uint64_t* value);
68+
uint64_t *value);
6969

7070
ERL_NIF_TERM getopt3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
7171
ERL_NIF_TERM setopt3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
7272

7373
bool create_settings(ErlNifEnv *env,
74-
const ERL_NIF_TERM* emap,
75-
QUIC_SETTINGS* Settings);
74+
const ERL_NIF_TERM *emap,
75+
QUIC_SETTINGS *Settings);
7676

7777
#endif // __QUICER_CONFIG_H_

c_src/quicer_connection.c

+80-62
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ limitations under the License.
1515
-------------------------------------------------------------------*/
1616

1717
#include "quicer_connection.h"
18+
1819
#include <assert.h>
1920
#include <unistd.h>
2021

@@ -23,7 +24,8 @@ limitations under the License.
2324
//
2425
_IRQL_requires_max_(DISPATCH_LEVEL)
2526
_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,
2729
_Inout_ QUIC_CONNECTION_EVENT *Event)
2830
{
2931
QuicerConnCTX *c_ctx = (QuicerConnCTX *)Context;
@@ -39,8 +41,11 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
3941
// A monitor is automatically removed when it triggers or when the
4042
// resource is deallocated.
4143
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"),
4449
enif_make_atom(env, "connected"),
4550
enif_make_resource(env, c_ctx))))
4651
{
@@ -69,8 +74,11 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
6974

7075
enif_monitor_process(NULL, s_ctx, &s_ctx->owner->Pid, s_ctx->owner_mon);
7176

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"),
7482
enif_make_atom(env, "new_stream"),
7583
enif_make_resource(env, s_ctx))))
7684
{
@@ -81,7 +89,8 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
8189
}
8290

8391
MsQuic->SetCallbackHandler(Event->PEER_STREAM_STARTED.Stream,
84-
(void *)ClientStreamCallback, s_ctx);
92+
(void *)ClientStreamCallback,
93+
s_ctx);
8594
break;
8695
case QUIC_CONNECTION_EVENT_SHUTDOWN_INITIATED_BY_TRANSPORT:
8796
//
@@ -94,30 +103,27 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
94103
//
95104
// The connection was explicitly shut down by the peer.
96105
//
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+
}
107116
break;
108117
case QUIC_CONNECTION_EVENT_SHUTDOWN_COMPLETE:
109118
//
110119
// The connection has completed the shutdown process and is ready to be
111120
// safely cleaned up.
112121
//
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));
117124

118125
enif_send(NULL, &(c_ctx->owner->Pid), NULL, report);
119126

120-
121127
if (!Event->SHUTDOWN_COMPLETE.AppCloseInProgress)
122128
{
123129
MsQuic->ConnectionClose(Connection);
@@ -139,7 +145,8 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
139145
}
140146

141147
QUIC_STATUS
142-
ServerConnectionCallback(HQUIC Connection, void *Context,
148+
ServerConnectionCallback(HQUIC Connection,
149+
void *Context,
143150
QUIC_CONNECTION_EVENT *Event)
144151
{
145152
QuicerConnCTX *c_ctx = (QuicerConnCTX *)Context;
@@ -179,8 +186,11 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
179186
ERL_NIF_TERM ConnHandler = enif_make_resource(c_ctx->env, c_ctx);
180187
// testing this, just unblock accecptor
181188
// 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,
184194
enif_make_atom(c_ctx->env, "new_conn"),
185195
ConnHandler)))
186196
{
@@ -204,27 +214,25 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
204214
//
205215
// The connection was explicitly shut down by the peer.
206216
//
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));
211219

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+
}
217227

218228
break;
219229
case QUIC_CONNECTION_EVENT_SHUTDOWN_COMPLETE:
220230
//
221231
// The connection has completed the shutdown process and is ready to be
222232
// safely cleaned up.
223233
//
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));
228236

229237
enif_send(NULL, &(c_ctx->owner->Pid), NULL, report);
230238

@@ -264,8 +272,11 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
264272
s_ctx->owner = acc;
265273

266274
// @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"),
269280
enif_make_atom(env, "new_stream"),
270281
enif_make_resource(env, s_ctx))))
271282
{
@@ -274,13 +285,14 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
274285
// shutdown the connection gracefully.
275286
// @todo, check rfc for the error code
276287
MsQuic->ConnectionShutdown(
277-
Connection, QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, NO_ERROR);
288+
Connection, QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, NO_ERROR);
278289
return QUIC_STATUS_UNREACHABLE;
279290
}
280291
else
281292
{
282293
MsQuic->SetCallbackHandler(Event->PEER_STREAM_STARTED.Stream,
283-
(void *)ServerStreamCallback, s_ctx);
294+
(void *)ServerStreamCallback,
295+
s_ctx);
284296
}
285297
break;
286298
case QUIC_CONNECTION_EVENT_RESUMED:
@@ -296,7 +308,8 @@ ServerConnectionCallback(HQUIC Connection, void *Context,
296308
}
297309

298310
ERL_NIF_TERM
299-
async_connect3(ErlNifEnv *env, __unused_parm__ int argc,
311+
async_connect3(ErlNifEnv *env,
312+
__unused_parm__ int argc,
300313
__unused_parm__ const ERL_NIF_TERM argv[])
301314
{
302315
QUIC_STATUS Status;
@@ -331,17 +344,20 @@ async_connect3(ErlNifEnv *env, __unused_parm__ int argc,
331344
return ERROR_TUPLE_2(ATOM_CONFIG_ERROR);
332345
}
333346

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))))
337351
{
338352
destroy_c_ctx(c_ctx);
339353
return ERROR_TUPLE_2(ATOM_CONN_OPEN_ERROR);
340354
}
341355

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)))
345361
{
346362
MsQuic->ConnectionClose(c_ctx->Connection);
347363
destroy_c_ctx(c_ctx);
@@ -354,7 +370,8 @@ async_connect3(ErlNifEnv *env, __unused_parm__ int argc,
354370
}
355371

356372
ERL_NIF_TERM
357-
async_accept2(ErlNifEnv *env, __unused_parm__ int argc,
373+
async_accept2(ErlNifEnv *env,
374+
__unused_parm__ int argc,
358375
const ERL_NIF_TERM argv[])
359376
{
360377
QuicerListenerCTX *l_ctx;
@@ -384,7 +401,8 @@ async_accept2(ErlNifEnv *env, __unused_parm__ int argc,
384401

385402
//@todo, shutdown with error
386403
ERL_NIF_TERM
387-
close_connection1(ErlNifEnv *env, __unused_parm__ int argc,
404+
close_connection1(ErlNifEnv *env,
405+
__unused_parm__ int argc,
388406
const ERL_NIF_TERM argv[])
389407
{
390408
QuicerConnCTX *c_ctx;
@@ -394,7 +412,8 @@ close_connection1(ErlNifEnv *env, __unused_parm__ int argc,
394412
}
395413
MsQuic->ConnectionShutdown(c_ctx->Connection,
396414
//@todo, check rfc for the error code
397-
QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, NO_ERROR);
415+
QUIC_CONNECTION_SHUTDOWN_FLAG_NONE,
416+
NO_ERROR);
398417
return ATOM_OK;
399418
}
400419

@@ -450,17 +469,16 @@ addr2eterm(ErlNifEnv *env, QUIC_ADDR *addr)
450469
uint16_t *ip = (uint16_t *)&addr->Ipv6.sin6_addr;
451470
return enif_make_tuple2(
452471
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));
464482
}
465483
else
466484
{

c_src/quicer_connection.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ limitations under the License.
1818
#define __QUICER_CONNECTION_H_
1919
#include "quicer_nif.h"
2020

21-
ERL_NIF_TERM async_connect3(ErlNifEnv *env, int argc,
22-
const ERL_NIF_TERM argv[]);
23-
ERL_NIF_TERM async_accept2(ErlNifEnv *env, int argc,
24-
const ERL_NIF_TERM argv[]);
25-
ERL_NIF_TERM close_connection1(ErlNifEnv *env, int argc,
26-
const ERL_NIF_TERM argv[]);
27-
ERL_NIF_TERM sockname1(ErlNifEnv *env, int argc,
28-
const ERL_NIF_TERM argv[]);
21+
ERL_NIF_TERM
22+
async_connect3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
23+
ERL_NIF_TERM
24+
async_accept2(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
25+
ERL_NIF_TERM
26+
close_connection1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
27+
ERL_NIF_TERM sockname1(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]);
2928

30-
QUIC_STATUS ServerConnectionCallback(HQUIC Connection, void *Context,
29+
QUIC_STATUS ServerConnectionCallback(HQUIC Connection,
30+
void *Context,
3131
QUIC_CONNECTION_EVENT *Event);
3232

3333
ERL_NIF_TERM addr2eterm(ErlNifEnv *env, QUIC_ADDR *addr);

c_src/quicer_eterms.h

+3-5
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ extern ERL_NIF_TERM ATOM_QUIC;
213213
/* ATOMS ends here */
214214
/*----------------------------------------------------------*/
215215

216-
217216
#define SUCCESS(Term) enif_make_tuple(env, 2, ATOM_OK, Term)
218217
#define ERROR_TUPLE_2(Err) enif_make_tuple2(env, ATOM_ERROR, Err)
219218
#define ERROR_TUPLE_3(Err1, Err2) enif_make_tuple3(env, ATOM_ERROR, Err1, Err2)
@@ -229,14 +228,13 @@ extern ERL_NIF_TERM ATOM_QUIC;
229228
#define IS_SAME_TERM(x, y) enif_is_identical(x, y)
230229

231230
#define PropTupleStrInt(S, I) \
232-
enif_make_tuple2(env, enif_make_string(env, #S, ERL_NIF_LATIN1), \
231+
enif_make_tuple2(env, \
232+
enif_make_string(env, #S, ERL_NIF_LATIN1), \
233233
enif_make_uint64(env, (uint64_t)I))
234234

235235
#define PropTupleAtomInt(A, I) \
236236
enif_make_tuple2(env, A, enif_make_uint64(env, (uint64_t)I))
237237

238-
#define PropTupleAtomBool(A, I) \
239-
enif_make_tuple2(env, A, ETERM_BOOL(I))
240-
238+
#define PropTupleAtomBool(A, I) enif_make_tuple2(env, A, ETERM_BOOL(I))
241239

242240
#endif // __QUICER_ETERMS_H_

0 commit comments

Comments
 (0)