Make pipes non-blocking, assert that read never blocks
@@ -361,8 +361,10 @@ static int from_pipe_read(h2o_sendvec_t *vec, void *dst, size_t len)
ssize_t ret;
while ((ret = read(self->pipe_reader.fds[0], dst, len)) == -1 && errno == EINTR)
;
- if (ret <= 0)
+ if (ret <= 0) {
+ assert(errno != EAGAIN);
return 0;
+ }
dst += ret;
len -= ret;
vec->len -= ret;
@@ -644,7 +646,7 @@ static h2o_httpclient_body_cb on_head(h2o_httpclient_t *client, const char *errs
/* switch to using pipe reader, if the opportunity is provided */
if (args->pipe_reader != NULL) {
- if (pipe(self->pipe_reader.fds) != 0) {
+ if (pipe2(self->pipe_reader.fds, O_NONBLOCK | O_CLOEXEC) != 0) {
char errbuf[256];
h2o_fatal("pipe(2) failed:%s", h2o_strerror_r(errno, errbuf, sizeof(errbuf)));
}
