int n = ::write(mFD,
reinterpret_cast<const char*>(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);
}
}
int n = ::read(mFD,
reinterpret_cast<char*>(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