enhanced read to restart when interrupted, and to read until really done
This commit is contained in:
parent
f2cf32410e
commit
484494b915
19
fdiobuf.cpp
19
fdiobuf.cpp
@ -24,7 +24,24 @@ std::streambuf::int_type sc::io::fdiobuf::underflow() {
|
||||
}
|
||||
|
||||
std::streamsize sc::io::fdiobuf::xsgetn(char* s, std::streamsize n) {
|
||||
return ::read(_fd, s, n);
|
||||
std::streamsize tot_read = 0;
|
||||
std::streamsize next_amount = n;
|
||||
while (next_amount) {
|
||||
ssize_t num_read = ::read(_fd, s, next_amount);
|
||||
if (num_read == -1) {
|
||||
if (errno == EINTR) { // interrupted => restart
|
||||
continue;
|
||||
} else {
|
||||
return -1; // real error
|
||||
}
|
||||
} else if (num_read == 0) { // EOF
|
||||
break;
|
||||
} else {
|
||||
tot_read += num_read;
|
||||
next_amount -= num_read;
|
||||
}
|
||||
}
|
||||
return tot_read;
|
||||
}
|
||||
|
||||
std::streambuf::int_type sc::io::fdiobuf::overflow(std::streambuf::int_type c) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user