Skip to content

Commit

Permalink
Add proper EINTR handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SimulPiscator committed Feb 15, 2024
1 parent c62db85 commit e0e0be8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions basic/fdbuf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,15 @@ fdbuf::sync()
const char* p = pbase();
while (n > 0) {
int written = ::write(mFd, p, n);
if (written < 0)
return -1;
n -= written;
p += written;
mTotalWritten += written;
if (written < 0) {
if (errno != EINTR)
return -1;
}
else { // written >= 0
n -= written;
p += written;
mTotalWritten += written;
}
}
return 0;
}
Expand All @@ -88,9 +92,10 @@ fdbuf::underflow()
return traits_type::eof();

int read = ::read(mFd, start, n);
if (read == 0)
if (read == 0 || (read < 0 && errno != EINTR))
return traits_type::eof();
setg(mInbuf, start, start + read);
if (read > 0)
setg(mInbuf, start, start + read);
}
return traits_type::to_int_type(*gptr());
}
Expand Down

0 comments on commit e0e0be8

Please sign in to comment.