Reorder error logging before Terminate()

Calling `Terminate()` issues additional syscalls that may clobber the `errno`
value. Reordering the log statements ensures we actually log the initial error
in `read()`/`write()`.

PiperOrigin-RevId: 387576942
Change-Id: I0f9c8c6001e6dc4ca098abe02cd251029f92a737
This commit is contained in:
Christian Blichmann 2021-07-29 07:11:32 -07:00 committed by Copybara-Service
parent f14aeee0ad
commit fd20eb0b4d

View File

@ -499,7 +499,7 @@ bool Comms::Send(const void* data, size_t len) {
};
while (total_sent < len) {
ssize_t s;
s = op(connection_fd_);
s = op(connection_fd_);
if (s == -1 && errno == EPIPE) {
Terminate();
// We do not expect the other end to disappear.
@ -507,10 +507,10 @@ bool Comms::Send(const void* data, size_t len) {
return false;
}
if (s == -1) {
SAPI_RAW_PLOG(ERROR, "write");
if (IsFatalError(errno)) {
Terminate();
}
SAPI_RAW_PLOG(ERROR, "write");
return false;
}
if (s == 0) {
@ -533,12 +533,12 @@ bool Comms::Recv(void* data, size_t len) {
};
while (total_recv < len) {
ssize_t s;
s = op(connection_fd_);
s = op(connection_fd_);
if (s == -1) {
SAPI_RAW_PLOG(ERROR, "read");
if (IsFatalError(errno)) {
Terminate();
}
SAPI_RAW_PLOG(ERROR, "read");
return false;
}
if (s == 0) {