From d92101d74c0b0db9ee50843e23eab5a8eaf5003a Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Thu, 12 Jan 2017 10:28:48 +0100 Subject: [PATCH] clean up code --- arangod/Scheduler/SocketTask.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/arangod/Scheduler/SocketTask.cpp b/arangod/Scheduler/SocketTask.cpp index cb17ec8768..3008d362a3 100644 --- a/arangod/Scheduler/SocketTask.cpp +++ b/arangod/Scheduler/SocketTask.cpp @@ -163,30 +163,26 @@ void SocketTask::addWriteBuffer(StringBuffer* buffer, boost::system::error_code err; err.clear(); - bool moreWork = true; - while (!err && moreWork){ + while (true){ written = _peer->write(_writeBuffer, err); if(_writeBufferStatistics){ _writeBufferStatistics->_sentBytes += written; } - if (written == total) { - moreWork = completedWriteBuffer(); - if(_writeBuffer){ - total = _writeBuffer->length(); - written = 0; - if(_writeBufferStatistics){ - _writeBufferStatistics->_writeStart = TRI_StatisticsTime(); - } - } - } else { + if (err || written != total) { break; //unable to write everything at once //might be a lot of data //above code does not update the buffer positon } - } - if(!moreWork || _writeBuffer == nullptr){ - return; + if(! completedWriteBuffer()){ + return; + } + + total = _writeBuffer->length(); + written = 0; + if(_writeBufferStatistics){ + _writeBufferStatistics->_writeStart = TRI_StatisticsTime(); + } } // write could have blocked which is the only acceptable error @@ -201,8 +197,6 @@ void SocketTask::addWriteBuffer(StringBuffer* buffer, // so the code could have blocked at this point or not all data // was written in one go - err.clear(); //reset error state - auto self = shared_from_this(); //begin writing at offset (written) _peer->asyncWrite(boost::asio::buffer(_writeBuffer->begin() + written, total - written)