+ if (timeout >= 0) {
+ fd_set read_set;
+ fd_set error_set;
+ FD_ZERO(&read_set);
+ FD_ZERO(&error_set);
+ FD_SET(fd_out[0], &read_set);
+ FD_SET(fd_out[0], &error_set);
+ timeval timer;
+ timer.tv_sec = timeout / 1000;
+ timer.tv_usec = (timeout % 1000) * 1000;
+ if (select(fd_out[0] + 1, &read_set, nullptr, &error_set, &timer) == -1) {
+ throw SysError("error waiting on child process' output stream");
+ }
+ if (FD_ISSET(fd_out[0], &error_set)) {
+ throw runtime_error("error condition on child process' output stream");
+ }
+ if (!FD_ISSET(fd_out[0], &read_set)) {
+ throw runtime_error("timeout while waiting on child process' output stream");
+ }
+ }