Improve error handling around file descriptors in wserv

This commit is contained in:
Kevin Easton
2017-11-17 22:55:06 +11:00
parent abfe84eb5c
commit 149b3206e0

View File

@@ -88,19 +88,25 @@ int main (int argc, char **argv)
FD_SET(0, &reads);
FD_SET(s, &reads);
if (select(s + 1, &reads, NULL, NULL, NULL) <= 0)
{
if (errno == EINTR)
continue;
else
break;
}
if (FD_ISSET(0, &reads))
{
if ((nread = read(0, buffer, sizeof(buffer))))
nread = read(0, buffer, sizeof buffer);
if (nread > 0)
write(s, buffer, nread);
else
my_exit(3);
}
if (FD_ISSET(s, &reads))
{
if ((nread = read(s, buffer, sizeof(buffer))))
nread = read(s, buffer, sizeof buffer);
if (nread > 0)
write(1, buffer, nread);
else
my_exit(4);