Skip to content

Commit

Permalink
remove write_queue since it was not required and move shared constans…
Browse files Browse the repository at this point in the history
… to separate file
  • Loading branch information
radkesvat committed May 31, 2024
1 parent b9ccfa9 commit be1c9da
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
2 changes: 2 additions & 0 deletions tunnels/client/halfduplex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ target_link_libraries(HalfDuplexClient PUBLIC ww)
# add dependencies
include(${CMAKE_BINARY_DIR}/cmake/CPM.cmake)

target_include_directories(HalfDuplexClient PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../shared/halfduplex)


target_compile_definitions(HalfDuplexClient PRIVATE HalfDuplexClient_VERSION=0.1)
35 changes: 6 additions & 29 deletions tunnels/client/halfduplex/halfduplex_client.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#include "halfduplex_client.h"
#include "buffer_pool.h"
#include "context_queue.h"
#include "frand.h"
#include "shiftbuffer.h"
#include "tunnel.h"
#include "halfduplex_constants.h"
#include <stdatomic.h>
#include <stdint.h>
#include <stdlib.h>
Expand All @@ -18,23 +17,13 @@ typedef struct halfduplex_con_state_s
line_t *main_line;
line_t *upload_line;
line_t *download_line;
//--------------
context_queue_t *write_queue;

} halfduplex_con_state_t;

enum
{
kCmdUpload = 0x1,
kCmdDownload = 0x2,
};

static void cleanup(halfduplex_con_state_t *cstate)
{
if (cstate->write_queue != NULL)
{
destroyContextQueue(cstate->write_queue);
}

if (cstate->upload_line)
{
doneLineDownSide(cstate->upload_line);
Expand All @@ -49,16 +38,6 @@ static void cleanup(halfduplex_con_state_t *cstate)
free(cstate);
}

static void flushWriteQueue(tunnel_t *self, context_t *c)
{
halfduplex_con_state_t *cstate = CSTATE(c);

while (isAlive(c->line) && contextQueueLen(cstate->write_queue) > 0)
{
self->upStream(self, contextQueuePop(cstate->write_queue));
}
}

static void onMainLinePaused(void *cstate)
{
pauseLineUpSide(((halfduplex_con_state_t *) cstate)->upload_line);
Expand Down Expand Up @@ -94,14 +73,14 @@ static void upStream(tunnel_t *self, context_t *c)
shiftl(intro_context->payload, 2);
writeUI16(intro_context->payload, cid);
shiftl(intro_context->payload, 1);
writeUI8(intro_context->payload, kCmdDownload);
writeUI8(intro_context->payload, kHLFDCmdDownload);

self->up->upStream(self->up, intro_context);

shiftl(c->payload, 2);
writeUI16(c->payload, cid);
shiftl(intro_context->payload, 1);
writeUI8(intro_context->payload, kCmdUpload);
writeUI8(intro_context->payload, kHLFDCmdUpload);
}
self->up->upStream(self->up, switchLine(c, cstate->upload_line));
}
Expand All @@ -112,10 +91,8 @@ static void upStream(tunnel_t *self, context_t *c)
{
halfduplex_con_state_t *cstate = malloc(sizeof(halfduplex_con_state_t));

*cstate = (halfduplex_con_state_t){.download_line = newLine(c->line->tid),
.upload_line = newLine(c->line->tid),
.main_line = c->line,
.write_queue = newContextQueue(getContextBufferPool(c))};
*cstate = (halfduplex_con_state_t){
.download_line = newLine(c->line->tid), .upload_line = newLine(c->line->tid), .main_line = c->line};

CSTATE_MUT(c) = cstate;
LSTATE_MUT(cstate->upload_line) = cstate;
Expand Down
7 changes: 7 additions & 0 deletions tunnels/shared/halfduplex/halfduplex_constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

enum
{
kHLFDCmdUpload = 0x1,
kHLFDCmdDownload = 0x2,
};

0 comments on commit be1c9da

Please sign in to comment.