From 0dc2f5f7c9ee58ae29c5a912a1baefea34b5e272 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Sat, 22 Jan 2022 16:36:48 +0100 Subject: [PATCH] Fixed rigctl server --- core/src/utils/networking.cpp | 9 ++++++--- core/src/utils/networking.h | 5 +++-- misc_modules/rigctl_server/src/main.cpp | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/utils/networking.cpp b/core/src/utils/networking.cpp index 4b7968c3..25ead323 100644 --- a/core/src/utils/networking.cpp +++ b/core/src/utils/networking.cpp @@ -63,7 +63,7 @@ namespace net { connectionOpenCnd.wait(lck, [this]() { return !connectionOpen; }); } - int ConnClass::read(int count, uint8_t* buf) { + int ConnClass::read(int count, uint8_t* buf, bool enforceSize) { if (!connectionOpen) { return -1; } std::lock_guard lck(readMtx); int ret; @@ -95,6 +95,8 @@ namespace net { return -1; } + if (!enforceSize) { return ret; } + beenRead += ret; } @@ -135,7 +137,7 @@ namespace net { return true; } - void ConnClass::readAsync(int count, uint8_t* buf, void (*handler)(int count, uint8_t* buf, void* ctx), void* ctx) { + void ConnClass::readAsync(int count, uint8_t* buf, void (*handler)(int count, uint8_t* buf, void* ctx), void* ctx, bool enforceSize) { if (!connectionOpen) { return; } // Create entry ConnReadEntry entry; @@ -143,6 +145,7 @@ namespace net { entry.buf = buf; entry.handler = handler; entry.ctx = ctx; + entry.enforceSize = enforceSize; // Add entry to queue { @@ -184,7 +187,7 @@ namespace net { lck.unlock(); // Read from socket and send data to the handler - int ret = read(entry.count, entry.buf); + int ret = read(entry.count, entry.buf, entry.enforceSize); if (ret <= 0) { { std::lock_guard lck(connectionOpenMtx); diff --git a/core/src/utils/networking.h b/core/src/utils/networking.h index 1cd7534d..65b404c5 100644 --- a/core/src/utils/networking.h +++ b/core/src/utils/networking.h @@ -33,6 +33,7 @@ namespace net { uint8_t* buf; void (*handler)(int count, uint8_t* buf, void* ctx); void* ctx; + bool enforceSize; }; struct ConnWriteEntry { @@ -49,9 +50,9 @@ namespace net { bool isOpen(); void waitForEnd(); - int read(int count, uint8_t* buf); + int read(int count, uint8_t* buf, bool enforceSize = true); bool write(int count, uint8_t* buf); - void readAsync(int count, uint8_t* buf, void (*handler)(int count, uint8_t* buf, void* ctx), void* ctx); + void readAsync(int count, uint8_t* buf, void (*handler)(int count, uint8_t* buf, void* ctx), void* ctx, bool enforceSize = true); void writeAsync(int count, uint8_t* buf); private: diff --git a/misc_modules/rigctl_server/src/main.cpp b/misc_modules/rigctl_server/src/main.cpp index 068f8277..85d970eb 100644 --- a/misc_modules/rigctl_server/src/main.cpp +++ b/misc_modules/rigctl_server/src/main.cpp @@ -310,7 +310,7 @@ private: //spdlog::info("New client!"); _this->client = std::move(_client); - _this->client->readAsync(1024, _this->dataBuf, dataHandler, _this); + _this->client->readAsync(1024, _this->dataBuf, dataHandler, _this, false); _this->client->waitForEnd(); _this->client->close(); @@ -331,7 +331,7 @@ private: if (_this->command.size() < MAX_COMMAND_LENGTH) { _this->command += (char)data[i]; } } - _this->client->readAsync(1024, _this->dataBuf, dataHandler, _this); + _this->client->readAsync(1024, _this->dataBuf, dataHandler, _this, false); } void commandHandler(std::string cmd) {