Skip to content

Commit

Permalink
refactor: disable some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed Jun 1, 2022
1 parent d5485e0 commit b983be5
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 100 deletions.
10 changes: 0 additions & 10 deletions c_src/quicer_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,11 +1011,6 @@ get_stream_opt(ErlNifEnv *env,
res = ERROR_TUPLE_2(ATOM_STATUS(QUIC_STATUS_NOT_SUPPORTED));
goto Exit;
}
else if (s_ctx->c_ctx)
{
res = get_connection_opt(env, s_ctx->c_ctx, optname, elevel);
goto Exit;
}
else
{
res = ERROR_TUPLE_2(ATOM_PARAM_ERROR);
Expand Down Expand Up @@ -1124,11 +1119,6 @@ set_stream_opt(ErlNifEnv *env,
return ERROR_TUPLE_2(ATOM_PARAM_ERROR);
}
}
else if (s_ctx->c_ctx)
{
res = set_connection_opt(env, s_ctx->c_ctx, optname, optval, elevel);
goto Exit;
}
else
{
res = ERROR_TUPLE_2(ATOM_PARAM_ERROR);
Expand Down
21 changes: 1 addition & 20 deletions c_src/quicer_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
enif_mutex_unlock(c_ctx->lock);
return QUIC_STATUS_UNREACHABLE;
}
else
{
enif_keep_resource(s_ctx->c_ctx);
}
s_ctx->owner = acc;

enif_monitor_process(NULL, s_ctx, &s_ctx->owner->Pid, &s_ctx->owner_mon);
Expand Down Expand Up @@ -426,7 +422,6 @@ ServerConnectionCallback(HQUIC Connection,
QuicerStreamCTX *s_ctx = init_s_ctx();
ErlNifEnv *env = s_ctx->env;
s_ctx->Stream = Event->PEER_STREAM_STARTED.Stream;
s_ctx->c_ctx = c_ctx;

acc = AcceptorDequeue(c_ctx->acceptor_queue);

Expand All @@ -450,10 +445,7 @@ ServerConnectionCallback(HQUIC Connection,
ATOM_NEW_STREAM,
enif_make_resource(env, s_ctx))))
{
// @todo log and step counter
// @todo, maybe we should just return error code and let msquic
// shutdown the connection gracefully.
// @todo, check rfc for the error code
// @TODO: check RFC for the error code
MsQuic->ConnectionShutdown(
Connection, QUIC_CONNECTION_SHUTDOWN_FLAG_NONE, 0);
enif_mutex_unlock(s_ctx->lock);
Expand All @@ -464,7 +456,6 @@ ServerConnectionCallback(HQUIC Connection,
MsQuic->SetCallbackHandler(Event->PEER_STREAM_STARTED.Stream,
(void *)ServerStreamCallback,
s_ctx);
enif_keep_resource(c_ctx);
}
break;
case QUIC_CONNECTION_EVENT_RESUMED:
Expand Down Expand Up @@ -684,9 +675,6 @@ async_connect3(ErlNifEnv *env,
else
{
destroy_c_ctx(c_ctx);

// @TODO Check if we need to call this
// MsQuic->ConnectionClose(c_ctx->connection)
}
return res;
}
Expand Down Expand Up @@ -776,8 +764,6 @@ close_connection1(ErlNifEnv *env,
c_ctx->Connection = NULL;
enif_mutex_unlock(c_ctx->lock);

// void return
MsQuic->ConnectionClose(c_ctx->Connection);
return ATOM_OK;
}

Expand All @@ -800,11 +786,6 @@ sockname1(ErlNifEnv *env, __unused_parm__ int args, const ERL_NIF_TERM argv[])
Handle = ((QuicerListenerCTX *)q_ctx)->Listener;
Param = QUIC_PARAM_LISTENER_LOCAL_ADDRESS;
}
else if (enif_get_resource(env, argv[0], ctx_stream_t, &q_ctx))
{
Handle = ((QuicerStreamCTX *)q_ctx)->c_ctx->Connection;
Param = QUIC_PARAM_CONN_LOCAL_ADDRESS;
}
else
{
return ERROR_TUPLE_2(ATOM_BADARG);
Expand Down
4 changes: 2 additions & 2 deletions c_src/quicer_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ init_c_ctx()
return NULL;
}
CxPlatZeroMemory(c_ctx, sizeof(QuicerConnCTX));
c_ctx->magic = 0xcfcfcfcf;
c_ctx->env = enif_alloc_env();
c_ctx->acceptor_queue = AcceptorQueueNew();
c_ctx->Connection = NULL;
Expand Down Expand Up @@ -136,7 +137,7 @@ init_s_ctx()
return NULL;
}
CxPlatZeroMemory(s_ctx, sizeof(QuicerStreamCTX));

s_ctx->magic = 0xefefefef; // 4025479151
s_ctx->env = enif_alloc_env();
s_ctx->lock = enif_mutex_create("quicer:s_ctx");
s_ctx->is_wait_for_data = FALSE;
Expand All @@ -163,7 +164,6 @@ destroy_s_ctx(QuicerStreamCTX *s_ctx)
// Since enif_release_resource is async call,
// we should demon the owner now!
enif_demonitor_process(s_ctx->env, s_ctx, &s_ctx->owner_mon);
enif_release_resource(s_ctx->c_ctx);
enif_release_resource(s_ctx);
}

Expand Down
4 changes: 2 additions & 2 deletions c_src/quicer_ctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef struct

typedef struct QuicerConnCTX
{
uint32_t magic;
// config_resource
// for server, inherit from l_ctx
// for client, alloc on its own
Expand All @@ -78,8 +79,7 @@ typedef struct QuicerConnCTX

typedef struct QuicerStreamCTX
{
QuicerListenerCTX *l_ctx;
QuicerConnCTX *c_ctx;
uint32_t magic;
HQUIC Stream;
ACCEPTOR *owner;
ErlNifMonitor owner_mon;
Expand Down
2 changes: 1 addition & 1 deletion c_src/quicer_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ServerListenerCallback(__unused_parm__ HQUIC Listener,
if (!conn_owner)
{
TP_CB_3(missing_acceptor, (uintptr_t)c_ctx->Connection, 0);
destroy_c_ctx(c_ctx);
destroy_c_ctx(c_ctx); // no avail conn owner
// make msquic close the connection.
Status = QUIC_STATUS_UNREACHABLE;
goto Error;
Expand Down
11 changes: 0 additions & 11 deletions c_src/quicer_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ServerStreamCallback(HQUIC Stream, void *Context, QUIC_STREAM_EVENT *Event)
QuicerStreamSendCTX *send_ctx = NULL;
BOOLEAN is_destroy = FALSE;

enif_mutex_lock(s_ctx->c_ctx->lock);
enif_mutex_lock(s_ctx->lock);

TP_CB_3(event, (uintptr_t)Stream, Event->Type);
Expand Down Expand Up @@ -154,7 +153,6 @@ ServerStreamCallback(HQUIC Stream, void *Context, QUIC_STREAM_EVENT *Event)
s_ctx->is_closed = TRUE;
}
enif_mutex_unlock(s_ctx->lock);
enif_mutex_unlock(s_ctx->c_ctx->lock);

if (is_destroy)
{
Expand All @@ -177,7 +175,6 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
QuicerStreamCTX *s_ctx = (QuicerStreamCTX *)Context;
QuicerStreamSendCTX *send_ctx = NULL;
ERL_NIF_TERM report;
enif_mutex_lock(s_ctx->c_ctx->lock);
enif_mutex_lock(s_ctx->lock);
env = s_ctx->env;
BOOLEAN is_destroy = FALSE;
Expand Down Expand Up @@ -293,7 +290,6 @@ _IRQL_requires_max_(DISPATCH_LEVEL)
}

enif_mutex_unlock(s_ctx->lock);
enif_mutex_unlock(s_ctx->c_ctx->lock);

if (is_destroy)
{
Expand Down Expand Up @@ -334,11 +330,6 @@ async_start_stream2(ErlNifEnv *env,
return ERROR_TUPLE_2(ATOM_ERROR_NOT_ENOUGH_MEMORY);
}

s_ctx->c_ctx = c_ctx;

// note, will be released in destroy_s_ctx
enif_keep_resource(s_ctx->c_ctx);

// Caller should be the owner of this stream.
s_ctx->owner = AcceptorAlloc();

Expand Down Expand Up @@ -494,7 +485,6 @@ send3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
return ERROR_TUPLE_2(ATOM_BADARG);
}

enif_mutex_lock(s_ctx->c_ctx->lock);
enif_mutex_lock(s_ctx->lock);

send_ctx->s_ctx = s_ctx;
Expand Down Expand Up @@ -529,7 +519,6 @@ send3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
destroy_send_ctx(send_ctx);
Exit:
enif_mutex_unlock(s_ctx->lock);
enif_mutex_unlock(s_ctx->c_ctx->lock);
return res;
}

Expand Down
5 changes: 5 additions & 0 deletions docs/messages_to_owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ Data received in binary format

### peer_send_shutdown

Peer has sent all the data and wants to shutdown

```erlang
{quic, peer_send_shutdown, stream_handler(), ErrorCode}
```

### peer_send_aborted

Peer is no longer interested in receiving thus want
abort the receiving.

```erlang
{quic, peer_send_aborted, stream_handler(), ErrorCode}
```
Expand Down
16 changes: 3 additions & 13 deletions src/quicer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -504,22 +504,12 @@ async_send(Stream, Data) ->
%%
%% Suggested to use Len=0 if caller want to buffer or reassemble the data on its own.
%%
%% note, the requested Len cannot exceed the stream recv window size specified in connection opts
%% otherwise ```{error, stream_recv_window_too_small}''' will be returned.
%% note, the requested Len cannot exceed the 'stream_recv_window_default' specified in connection opts
%% otherwise the function will never return
-spec recv(stream_handler(), Count::non_neg_integer())
-> {ok, binary()} | {error, any()}.
recv(Stream, Count) ->
case quicer:getopt(Stream, param_conn_settings, false) of
{ok, Settings} ->
case proplists:get_value(stream_recv_window_default, Settings, 0) of
X when X < Count ->
{error, stream_recv_window_too_small};
_ ->
do_recv(Stream, Count)
end;
{error, _} = Error ->
Error
end.
do_recv(Stream, Count).

do_recv(Stream, Count) ->
case quicer_nif:recv(Stream, Count) of
Expand Down
Loading

0 comments on commit b983be5

Please sign in to comment.