Skip to content

Commit

Permalink
chore: format fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Oct 10, 2021
1 parent 2bbffed commit 92f3c78
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 42 deletions.
84 changes: 51 additions & 33 deletions c_src/quicer_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,31 @@ static ERL_NIF_TERM set_listener_opt(ErlNifEnv *env,

static ERL_NIF_TERM
get_config_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname);
static ERL_NIF_TERM
set_config_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM optval);
static ERL_NIF_TERM set_config_opt(ErlNifEnv *env,
HQUIC Hanlder,
ERL_NIF_TERM optname,
ERL_NIF_TERM optval);

static ERL_NIF_TERM
get_reg_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname);
static ERL_NIF_TERM
set_reg_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM optval);
static ERL_NIF_TERM set_reg_opt(ErlNifEnv *env,
HQUIC Hanlder,
ERL_NIF_TERM optname,
ERL_NIF_TERM optval);

static ERL_NIF_TERM
get_tls_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname);
static ERL_NIF_TERM
set_tls_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM optval);
static ERL_NIF_TERM set_tls_opt(ErlNifEnv *env,
HQUIC Hanlder,
ERL_NIF_TERM optname,
ERL_NIF_TERM optval);

static ERL_NIF_TERM
get_global_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname);
static ERL_NIF_TERM
set_global_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM optval);
static ERL_NIF_TERM set_global_opt(ErlNifEnv *env,
HQUIC Hanlder,
ERL_NIF_TERM optname,
ERL_NIF_TERM optval);

static ERL_NIF_TERM get_level_param(ErlNifEnv *env,
HQUIC Handle,
Expand All @@ -74,8 +82,7 @@ static ERL_NIF_TERM set_level_param(ErlNifEnv *env,
HQUIC Handle,
ERL_NIF_TERM level,
ERL_NIF_TERM eopt,
ERL_NIF_TERM optval
);
ERL_NIF_TERM optval);

bool
ReloadCertConfig(HQUIC Configuration, QUIC_CREDENTIAL_CONFIG_HELPER *Config)
Expand Down Expand Up @@ -684,15 +691,18 @@ setopt4(ErlNifEnv *env,
}
if (enif_get_resource(env, ctx, ctx_stream_t, &q_ctx))
{
res = set_stream_opt(env, (QuicerStreamCTX *)q_ctx, eopt, evalue, elevel);
res = set_stream_opt(
env, (QuicerStreamCTX *)q_ctx, eopt, evalue, elevel);
}
else if (enif_get_resource(env, ctx, ctx_connection_t, &q_ctx))
{
res = set_connection_opt(env, (QuicerConnCTX *)q_ctx, eopt, evalue, elevel);
res = set_connection_opt(
env, (QuicerConnCTX *)q_ctx, eopt, evalue, elevel);
}
else if (enif_get_resource(env, ctx, ctx_listener_t, &q_ctx))
{
res = set_listener_opt(env, (QuicerListenerCTX *)q_ctx, eopt, evalue, elevel);
res = set_listener_opt(
env, (QuicerListenerCTX *)q_ctx, eopt, evalue, elevel);
}
else
{ //@todo support GLOBAL, REGISTRATION and CONFIGURATION
Expand Down Expand Up @@ -1213,8 +1223,7 @@ set_stream_opt(ErlNifEnv *env,
goto Exit;
}

status
= MsQuic->SetParam(s_ctx->Stream, Level, Param, BufferLength, Buffer);
status = MsQuic->SetParam(s_ctx->Stream, Level, Param, BufferLength, Buffer);

if (QUIC_SUCCEEDED(status))
{
Expand Down Expand Up @@ -1522,7 +1531,7 @@ set_connection_opt(ErlNifEnv *env,
QUIC_SETTINGS Settings = { 0 };
if (!create_settings(env, &optval, &Settings))
{
res = ERROR_TUPLE_2(ATOM_BADARG);
res = ERROR_TUPLE_2(ATOM_BADARG);
goto Exit;
}
Buffer = &Settings;
Expand Down Expand Up @@ -1805,11 +1814,8 @@ set_listener_opt(ErlNifEnv *env,
}

assert(Param);
status = MsQuic->SetParam(l_ctx->Listener,
QUIC_PARAM_LEVEL_LISTENER,
Param,
BufferLength,
Buffer);
status = MsQuic->SetParam(
l_ctx->Listener, QUIC_PARAM_LEVEL_LISTENER, Param, BufferLength, Buffer);

if (QUIC_SUCCEEDED(status))
{
Expand Down Expand Up @@ -1870,7 +1876,10 @@ get_tls_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname)
}

static ERL_NIF_TERM
set_tls_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, __unused_parm__ ERL_NIF_TERM optval)
set_tls_opt(ErlNifEnv *env,
HQUIC Hanlder,
ERL_NIF_TERM optname,
__unused_parm__ ERL_NIF_TERM optval)
{
QUIC_STATUS status = QUIC_STATUS_SUCCESS;
void *Buffer = NULL;
Expand Down Expand Up @@ -1988,7 +1997,10 @@ get_global_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname)
}

static ERL_NIF_TERM
set_global_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM optval)
set_global_opt(ErlNifEnv *env,
HQUIC Hanlder,
ERL_NIF_TERM optname,
ERL_NIF_TERM optval)
{
QUIC_STATUS status = QUIC_STATUS_SUCCESS;
void *Buffer = NULL;
Expand All @@ -2002,10 +2014,10 @@ set_global_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM
uint32_t percent = 0;
BufferLength = sizeof(uint32_t);
if (!enif_get_uint(env, optval, &percent) || percent > UINT16_MAX)
{
res = ERROR_TUPLE_2(ATOM_BADARG);
goto Exit;
}
{
res = ERROR_TUPLE_2(ATOM_BADARG);
goto Exit;
}
Buffer = &percent;
}
else if (IS_SAME_TERM(optname, ATOM_QUIC_PARAM_GLOBAL_SUPPORTED_VERSIONS))
Expand Down Expand Up @@ -2105,7 +2117,10 @@ get_config_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname)
}

static ERL_NIF_TERM
set_config_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM optval)
set_config_opt(ErlNifEnv *env,
HQUIC Hanlder,
ERL_NIF_TERM optname,
ERL_NIF_TERM optval)
{
QUIC_STATUS status = QUIC_STATUS_SUCCESS;
void *Buffer = NULL;
Expand Down Expand Up @@ -2185,7 +2200,10 @@ get_reg_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname)
}

static ERL_NIF_TERM
set_reg_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM optval)
set_reg_opt(ErlNifEnv *env,
HQUIC Hanlder,
ERL_NIF_TERM optname,
ERL_NIF_TERM optval)
{
QUIC_STATUS status = QUIC_STATUS_SUCCESS;
void *Buffer = NULL;
Expand All @@ -2197,10 +2215,10 @@ set_reg_opt(ErlNifEnv *env, HQUIC Hanlder, ERL_NIF_TERM optname, ERL_NIF_TERM op
{
Param = QUIC_PARAM_REGISTRATION_CID_PREFIX;
if (!enif_get_string(env, optval, Buffer, BufferLength, ERL_NIF_LATIN1))
{
res = ERROR_TUPLE_2(ATOM_BADARG);
goto Exit;
}
{
res = ERROR_TUPLE_2(ATOM_BADARG);
goto Exit;
}
}
else
{
Expand Down
19 changes: 10 additions & 9 deletions c_src/quicer_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ ServerConnectionCallback(HQUIC Connection,

assert(acc);

if(!acc->fast_conn)
{
enif_release_resource(c_ctx);
}
if (!acc->fast_conn)
{
enif_release_resource(c_ctx);
}

// A monitor is automatically removed when it triggers or when the
// resource is deallocated.
Expand Down Expand Up @@ -389,10 +389,11 @@ ServerConnectionCallback(HQUIC Connection,
Connection,
Event->SHUTDOWN_COMPLETE.AppCloseInProgress);

if(!c_ctx->owner->fast_conn && !Event->SHUTDOWN_COMPLETE.HandshakeCompleted)
{
enif_release_resource(c_ctx);
}
if (!c_ctx->owner->fast_conn
&& !Event->SHUTDOWN_COMPLETE.HandshakeCompleted)
{
enif_release_resource(c_ctx);
}
report = enif_make_tuple3(
env, ATOM_QUIC, ATOM_CLOSED, enif_make_resource(env, c_ctx));

Expand Down Expand Up @@ -776,7 +777,7 @@ continue_connection_handshake(QuicerConnCTX *c_ctx)

if (QUIC_FAILED(Status = MsQuic->ConnectionSetConfiguration(
c_ctx->Connection, c_ctx->l_ctx->Configuration)))
{
{
enif_release_resource(c_ctx);
return Status;
}
Expand Down

0 comments on commit 92f3c78

Please sign in to comment.