[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
int n = ::write(mFD,
reinterpret_cast<const char*>(bufferPtr) + nTotal,
size - nTotal);
int n = ::write(mFD,
reinterpret_cast<const char*>(bufferPtr) + nTotal,
size - nTotal);
+ if (nTotal == size) {
+ // All data is written, break loop
+ break;
+ }
} else if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
// Neglected errors
} else {
} 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);
int n = ::read(mFD,
reinterpret_cast<char*>(bufferPtr) + nTotal,
size - nTotal);
+ 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)));
}
} 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
}
}
} // namespace config