Fixed rigctl server

This commit is contained in:
AlexandreRouma 2022-01-22 16:36:48 +01:00
parent 983c4c0f87
commit 0dc2f5f7c9
3 changed files with 11 additions and 7 deletions

View File

@ -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);

View File

@ -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:

View File

@ -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) {