From: Mateusz Malicki Date: Wed, 15 Apr 2015 09:26:09 +0000 (+0200) Subject: Support for reading and writing 0 bytes to fdstore X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen;p=archive%2Fplatform%2Fcore%2Fsystem%2FlibConfig.git Support for reading and writing 0 bytes to fdstore [Bug/Feature] Zero bytes can't be read and write (it's needed by fdstore-visitor) [Cause] N/A [Solution] N/A [Verification] N/A Change-Id: Ic9d3ed84a09797fc09a795a799b22fa66facd843 --- diff --git a/src/config/fdstore.cpp b/src/config/fdstore.cpp index 7934893..c1cedfe 100644 --- a/src/config/fdstore.cpp +++ b/src/config/fdstore.cpp @@ -101,20 +101,19 @@ void FDStore::write(const void* bufferPtr, const size_t size, const unsigned int int n = ::write(mFD, reinterpret_cast(bufferPtr) + nTotal, size - nTotal); - if (n > 0) { + if (n >= 0) { nTotal += n; + if (nTotal == size) { + // All data is written, break loop + break; + } } else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { // Neglected errors } else { - throw ConfigException("Error during reading: " + std::string(strerror(errno))); + throw ConfigException("Error during writing: " + std::string(strerror(errno))); } - if (nTotal >= size) { - // All data is written, break loop - break; - } else { - waitForEvent(mFD, POLLOUT, deadline); - } + waitForEvent(mFD, POLLOUT, deadline); } } @@ -128,20 +127,22 @@ void FDStore::read(void* bufferPtr, const size_t size, const unsigned int timeou int n = ::read(mFD, reinterpret_cast(bufferPtr) + nTotal, size - nTotal); - if (n > 0) { + if (n >= 0) { nTotal += n; + if (nTotal == size) { + // All data is read, break loop + break; + } + if (n == 0) { + throw ConfigException("Peer disconnected"); + } } else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) { // Neglected errors } else { throw ConfigException("Error during reading: " + std::string(strerror(errno))); } - if (nTotal >= size) { - // All data is read, break loop - break; - } else { - waitForEvent(mFD, POLLIN, deadline); - } + waitForEvent(mFD, POLLIN, deadline); } } } // namespace config