stream: read huge data in blocks on POSIX
read() blocks when there is no more data to read. However, we do need to loop when read is divided into blocks. Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
fc852c77c7
commit
f1e894aefd
@ -2260,17 +2260,19 @@ namespace stdex
|
||||
reinterpret_cast<uint8_t*&>(data) += num_read;
|
||||
}
|
||||
#else
|
||||
auto num_read = ::read(m_h, data, length);
|
||||
for (size_t to_read = length;;) {
|
||||
auto num_read = ::read(m_h, data, std::min<size_t>(to_read, SSIZE_MAX));
|
||||
if (num_read < 0) _Unlikely_ {
|
||||
m_state = state_t::fail;
|
||||
return 0;
|
||||
m_state = to_read < length ? state_t::ok : state_t::fail;
|
||||
return length - to_read;
|
||||
}
|
||||
if (!num_read) _Unlikely_ {
|
||||
m_state = !length ? state_t::ok : state_t::eof;
|
||||
return 0;
|
||||
to_read -= static_cast<size_t>(num_read);
|
||||
if (num_read < SSIZE_MAX) {
|
||||
m_state = to_read < length || !length ? state_t::ok : state_t::eof;
|
||||
return length - to_read;
|
||||
}
|
||||
reinterpret_cast<uint8_t*&>(data) += num_read;
|
||||
}
|
||||
m_state = state_t::ok;
|
||||
return num_read;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user