Fix incorrect reading logic and EAGAIN handling

This is one of the issues raised by #4410
This commit is contained in:
Maxime Coste 2021-10-29 22:34:16 +11:00
parent be4659097c
commit d2e2caaae6

View File

@ -176,9 +176,12 @@ FDWatcher make_reader(int fd, String& contents, OnClose&& on_close)
char buffer[1024]; char buffer[1024];
while (fd_readable(fd)) while (fd_readable(fd))
{ {
size_t size = ::read(fd, buffer, sizeof(buffer)); ssize_t size = ::read(fd, buffer, sizeof(buffer));
if (size <= 0) if (size <= 0)
{ {
if (size < 0 and errno == EAGAIN)
continue; // try again
watcher.disable(); watcher.disable();
on_close(); on_close();
return; return;