vici: Use non-blocking first read when receiving message during client on_read()

As select() and finally the watcher may signal an FD even if it does not
actually have data, we must make a non-block read to avoid hanging in the
read callback.
This commit is contained in:
Martin Willi
2014-05-07 14:13:37 +02:00
parent 7de35b7ff6
commit e00ce378fa
+15 -1
View File
@@ -199,11 +199,25 @@ CALLBACK(on_read, bool,
{
u_int16_t len;
u_int8_t op;
ssize_t hlen;
if (!stream->read_all(stream, &len, sizeof(len)))
hlen = stream->read(stream, &len, sizeof(len), FALSE);
if (hlen <= 0)
{
if (errno == EWOULDBLOCK)
{
return TRUE;
}
return read_error(conn, errno);
}
if (hlen < sizeof(len))
{
if (!stream->read_all(stream, ((void*)&len) + hlen, sizeof(len) - hlen))
{
return read_error(conn, errno);
}
}
len = ntohs(len);
if (len-- < sizeof(op))
{