From 485d9719b5c1d1307eb09eebb89d6c0f21146fde Mon Sep 17 00:00:00 2001 From: Sebastian Marsching Date: Sun, 1 Mar 2026 01:02:58 +0100 Subject: [PATCH] Send command and parameters in single operation. This significantly improves the performance because it reduces the number of round trips needed. --- src/xvc_client.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/xvc_client.cpp b/src/xvc_client.cpp index a8549df..dc717b9 100644 --- a/src/xvc_client.cpp +++ b/src/xvc_client.cpp @@ -267,20 +267,16 @@ ssize_t XVC_client::xfer_pkt(const string &instr, uint8_t *rx, uint32_t rx_size) { ssize_t len = tx_size; + vector buffer(instr.size() + (tx) ? tx_size : 0); + memcpy(buffer.data(), instr.c_str(), instr.size()); + if (tx) + memcpy(buffer.data() + instr.size(), tx, tx_size); - /* 1. instruction */ - if (sendall(_sock, instr.c_str(), instr.size(), 0) == -1) { - printError("Send instruction failed"); + if (sendall(_sock, buffer.data(), buffer.size(), 0) == -1) { + printError("Send failed"); return -1; } - if (tx) { - if (sendall(_sock, tx, tx_size, 0) == -1) { - printError("Send error"); - return -1; - } - } - if (rx) { len = recv(_sock, rx, rx_size, 0); if (len < 0) {