Skip to content

Commit

Permalink
fix some very easy bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Apr 3, 2024
1 parent e2599f5 commit 5072cfa
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
22 changes: 20 additions & 2 deletions tunnels/adapters/connector/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,30 @@ static void cleanup(connector_con_state_t *cstate)
{
if (cstate->current_w)
{
if (cstate->current_w->src_io)
{
hio_read(cstate->current_w->src_io);
}
if (cstate->current_w->payload)
{
DISCARD_CONTEXT(cstate->current_w);
}

destroyContext(cstate->current_w);
}
while (contextQueueLen(cstate->queue) > 0)
{
context_t *cw = contextQueuePop(cstate->queue);
if (cw->src_io)
{
hio_read(cw->src_io);
}
if (cw->payload)
{
DISCARD_CONTEXT(cw);
}
destroyContext(cw);
}
destroyContextQueue(cstate->queue);
free(cstate);
}
Expand All @@ -29,7 +47,7 @@ static bool resume_write_queue(connector_con_state_t *cstate)
{
destroyContext(cw);

if (upstream_io && last_resumed_io != upstream_io)
if (upstream_io != NULL && (last_resumed_io != upstream_io))
{
last_resumed_io = upstream_io;
hio_read(upstream_io);
Expand Down Expand Up @@ -63,7 +81,7 @@ static void on_write_complete(hio_t *io, const void *buf, int writebytes)

if (hio_write_is_complete(io))
{
hio_setcb_write(io, NULL);
hio_setcb_write(cstate->io, NULL);
cstate->write_paused = false;
context_t *cw = cstate->current_w;
cstate->current_w = NULL;
Expand Down
20 changes: 19 additions & 1 deletion tunnels/adapters/tcp_connector/tcp_connector.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,30 @@ static void cleanup(tcp_connector_con_state_t *cstate)
{
if (cstate->current_w)
{
if (cstate->current_w->src_io)
{
hio_read(cstate->current_w->src_io);
}
if (cstate->current_w->payload)
{
DISCARD_CONTEXT(cstate->current_w);
}

destroyContext(cstate->current_w);
}
while (contextQueueLen(cstate->queue) > 0)
{
context_t *cw = contextQueuePop(cstate->queue);
if (cw->src_io)
{
hio_read(cw->src_io);
}
if (cw->payload)
{
DISCARD_CONTEXT(cw);
}
destroyContext(cw);
}
destroyContextQueue(cstate->queue);
free(cstate);
}
Expand All @@ -31,7 +49,7 @@ static bool resume_write_queue(tcp_connector_con_state_t *cstate)
{
destroyContext(cw);

if (upstream_io && last_resumed_io != upstream_io)
if (upstream_io != NULL && (last_resumed_io != upstream_io))
{
last_resumed_io = upstream_io;
hio_read(upstream_io);
Expand Down
22 changes: 20 additions & 2 deletions tunnels/adapters/tcp_listener/tcp_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,30 @@ static void cleanup(tcp_listener_con_state_t *cstate)
{
if (cstate->current_w)
{
if (cstate->current_w->src_io)
{
hio_read(cstate->current_w->src_io);
}
if (cstate->current_w->payload)
{
DISCARD_CONTEXT(cstate->current_w);
}

destroyContext(cstate->current_w);
}
while (contextQueueLen(cstate->queue) > 0)
{
context_t *cw = contextQueuePop(cstate->queue);
if (cw->src_io)
{
hio_read(cstate->current_w->src_io);
}
if (cw->payload)
{
DISCARD_CONTEXT(cstate->current_w);
}
destroyContext(cw);
}
destroyContextQueue(cstate->queue);
free(cstate);
}
Expand All @@ -70,7 +88,7 @@ static bool resume_write_queue(tcp_listener_con_state_t *cstate)
{
destroyContext(cw);

if (upstream_io && last_resumed_io != upstream_io)
if (upstream_io != NULL && (last_resumed_io != upstream_io))
{
last_resumed_io = upstream_io;
hio_read(upstream_io);
Expand Down Expand Up @@ -104,7 +122,7 @@ static void on_write_complete(hio_t *io, const void *buf, int writebytes)

if (hio_write_is_complete(io))
{
hio_setcb_write(io, NULL);
hio_setcb_write(cstate->io, NULL);
cstate->write_paused = false;
context_t *cw = cstate->current_w;
cstate->current_w = NULL;
Expand Down

0 comments on commit 5072cfa

Please sign in to comment.