From be1c9da7ead1c8702cff6bd60ba21e735209e253 Mon Sep 17 00:00:00 2001 From: Radkesvat <134321679+radkesvat@users.noreply.github.com> Date: Fri, 31 May 2024 12:06:23 +0000 Subject: [PATCH] remove write_queue since it was not required and move shared constans to separate file --- tunnels/client/halfduplex/CMakeLists.txt | 2 ++ tunnels/client/halfduplex/halfduplex_client.c | 35 ++++--------------- .../shared/halfduplex/halfduplex_constants.h | 7 ++++ 3 files changed, 15 insertions(+), 29 deletions(-) create mode 100644 tunnels/shared/halfduplex/halfduplex_constants.h diff --git a/tunnels/client/halfduplex/CMakeLists.txt b/tunnels/client/halfduplex/CMakeLists.txt index ccb31eaa..e75654a1 100644 --- a/tunnels/client/halfduplex/CMakeLists.txt +++ b/tunnels/client/halfduplex/CMakeLists.txt @@ -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) diff --git a/tunnels/client/halfduplex/halfduplex_client.c b/tunnels/client/halfduplex/halfduplex_client.c index 54dfad6f..260559a6 100644 --- a/tunnels/client/halfduplex/halfduplex_client.c +++ b/tunnels/client/halfduplex/halfduplex_client.c @@ -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 #include #include @@ -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); @@ -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); @@ -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)); } @@ -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; diff --git a/tunnels/shared/halfduplex/halfduplex_constants.h b/tunnels/shared/halfduplex/halfduplex_constants.h new file mode 100644 index 00000000..711754e7 --- /dev/null +++ b/tunnels/shared/halfduplex/halfduplex_constants.h @@ -0,0 +1,7 @@ +#pragma once + +enum +{ + kHLFDCmdUpload = 0x1, + kHLFDCmdDownload = 0x2, +};