nmux: rearranged read() code for fixing EAGAINs

This commit is contained in:
ha7ilm 2017-01-12 18:57:23 +01:00
parent 8b4323237f
commit 795a77e7ee

View file

@ -232,12 +232,15 @@ int main(int argc, char* argv[])
// client->wait_condition).
index_in_current_write_buffer = 0;
}
for(;;)
{
if(NMUX_DEBUG) fprintf(stderr, "mainfor: reading...\n");
int retval = read(input_fd, current_write_buffer + index_in_current_write_buffer, bufsize - index_in_current_write_buffer);
if(NMUX_DEBUG) fprintf(stderr, "read %d\n", retval);
if(retval>0)
{
index_in_current_write_buffer += retval;
break;
}
else if(retval==0)
{
@ -246,10 +249,11 @@ int main(int argc, char* argv[])
}
else if(retval==-1)
{
if(errno == EAGAIN) { if(NMUX_DEBUG) fprintf(stderr, "mainfor: read %d\n", retval); }
if(errno == EAGAIN) { if(NMUX_DEBUG) fprintf(stderr, "mainfor: read EAGAIN\n"); /* seems like select would block forever, so we just read again */ break; }
else error_exit(MSG_START "(main thread/for) error in read(), exiting.\n");
}
}
}
}
void client_erase(client_t* client)