From 33edeaf4b0d3b27fe0830a3e14b5e42fc68bb63e Mon Sep 17 00:00:00 2001 From: Patrick LeBlanc Date: Wed, 30 Jan 2019 13:27:19 -0600 Subject: [PATCH] Fixed read/write/append responses. --- src/AppendTask.cpp | 21 ++++++++++++++++----- src/ReadTask.cpp | 3 ++- src/WriteTask.cpp | 25 ++++++++++++++++++------- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/AppendTask.cpp b/src/AppendTask.cpp index 1522cf276..dad7194a2 100644 --- a/src/AppendTask.cpp +++ b/src/AppendTask.cpp @@ -62,11 +62,22 @@ void AppendTask::run() if (readCount != writeCount) break; } - uint32_t *buf32 = (uint32_t *) cmdbuf; - buf32[0] = SM_MSG_START; - buf32[1] = 4; - buf32[2] = writeCount; - write(cmdbuf, 12); + + uint32_t response[4]; + response[0] = SM_MSG_START; + if (cmd->count != 0 && writeCount == 0) + { + response[1] = 8; + response[2] = -1; + response[3] = errno; + write((uint8_t *) response, 16); + } + else + { + response[1] = 4; + response[2] = writeCount; + write((uint8_t *) response, 12); + } } } diff --git a/src/ReadTask.cpp b/src/ReadTask.cpp index 0c4021e04..7d9fe044c 100644 --- a/src/ReadTask.cpp +++ b/src/ReadTask.cpp @@ -58,10 +58,11 @@ void ReadTask::run() if (count > 0) outbuf32[1] = count; else { + int l_errno = errno; outbuf.resize(16); outbuf32[1] = 8; outbuf32[2] = err; - outbuf32[3] = errno; + outbuf32[3] = l_errno; } break; } diff --git a/src/WriteTask.cpp b/src/WriteTask.cpp index 5d61dfb15..5b66a42b7 100644 --- a/src/WriteTask.cpp +++ b/src/WriteTask.cpp @@ -39,12 +39,12 @@ void WriteTask::run() success = read(&cmdbuf[sizeof(*cmd)], min(cmd->filename_len, 1024 - sizeof(*cmd) - 1)); check_error("WriteTask read"); - + size_t readCount = 0, writeCount = 0; vector databuf; uint bufsize = 1 << 20; // 1 MB databuf.resize(bufsize); // 1 MB - + while (readCount < cmd->count) { uint toRead = min(cmd->count - readCount, bufsize); // 1 MB @@ -61,11 +61,22 @@ void WriteTask::run() if (writeCount != readCount) break; } - uint32_t *buf32 = (uint32_t *) cmdbuf; - buf32[0] = SM_MSG_START; - buf32[1] = 4; - buf32[2] = writeCount; - write(cmdbuf, 12); + + uint32_t response[4]; + response[0] = SM_MSG_START; + if (cmd->count != 0 && writeCount == 0) + { + response[1] = 8; + response[2] = -1; + response[3] = errno; + write((uint8_t *) response, 16); + } + else + { + response[1] = 4; + response[2] = writeCount; + write((uint8_t *) response, 12); + } } }