Skip to content

Commit 485d971

Browse files
smarschingtrabucayre
authored andcommitted
Send command and parameters in single operation.
This significantly improves the performance because it reduces the number of round trips needed.
1 parent 3ae5e5e commit 485d971

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

src/xvc_client.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,16 @@ ssize_t XVC_client::xfer_pkt(const string &instr,
267267
uint8_t *rx, uint32_t rx_size)
268268
{
269269
ssize_t len = tx_size;
270+
vector<uint8_t> buffer(instr.size() + (tx) ? tx_size : 0);
271+
memcpy(buffer.data(), instr.c_str(), instr.size());
272+
if (tx)
273+
memcpy(buffer.data() + instr.size(), tx, tx_size);
270274

271-
/* 1. instruction */
272-
if (sendall(_sock, instr.c_str(), instr.size(), 0) == -1) {
273-
printError("Send instruction failed");
275+
if (sendall(_sock, buffer.data(), buffer.size(), 0) == -1) {
276+
printError("Send failed");
274277
return -1;
275278
}
276279

277-
if (tx) {
278-
if (sendall(_sock, tx, tx_size, 0) == -1) {
279-
printError("Send error");
280-
return -1;
281-
}
282-
}
283-
284280
if (rx) {
285281
len = recv(_sock, rx, rx_size, 0);
286282
if (len < 0) {

0 commit comments

Comments
 (0)