mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
connection::thread_loop(): Detect read errors and end of file reliably
This commit is contained in:
parent
f161c02210
commit
56979634bf
1 changed files with 10 additions and 6 deletions
|
@ -186,16 +186,20 @@ connection::thread_loop(void)
|
||||||
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 0; tv.tv_usec = 0;
|
tv.tv_sec = 0; tv.tv_usec = 0;
|
||||||
fd_set rfds;
|
fd_set rfds; FD_ZERO(&rfds); FD_SET(fd, &rfds);
|
||||||
FD_ZERO(&rfds);
|
fd_set efds; FD_ZERO(&efds); FD_SET(fd, &efds);
|
||||||
FD_SET(fd, &rfds);
|
while (select(fd + 1, &rfds, NULL, &efds, &tv)) {
|
||||||
while (select(fd + 1, &rfds, NULL, &rfds, &tv)) {
|
if (FD_ISSET(fd, &efds)) {
|
||||||
|
error = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
char cbuf[1024];
|
char cbuf[1024];
|
||||||
len = read(fd, cbuf, sizeof(cbuf));
|
len = read(fd, cbuf, sizeof(cbuf));
|
||||||
if (len < 0) {
|
if (len <= 0) {
|
||||||
error = true;
|
error = true;
|
||||||
} else if (len == 0) {
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
bool want_moar = false;
|
bool want_moar = false;
|
||||||
pthread_mutex_lock(&buf_lock);
|
pthread_mutex_lock(&buf_lock);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue