diff --git a/src/httpc.c b/src/httpc.c index c4938c6f..728f120e 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -240,7 +240,7 @@ http_client_ssl_read_update( http_client_t *hc ) return -1; } if (r < 0) { - if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) { + if (ERRNO_AGAIN(errno)) { http_client_poll_dir(hc, 1, 0); errno = EAGAIN; return r; @@ -274,7 +274,7 @@ http_client_ssl_write_update( http_client_t *hc ) memmove(ssl->wbio_buf, ssl->wbio_buf + r, ssl->wbio_pos - r); ssl->wbio_pos -= r; } else if (r < 0) { - if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) { + if (ERRNO_AGAIN(errno)) { http_client_poll_dir(hc, 0, 1); errno = EAGAIN; return r; @@ -297,7 +297,7 @@ http_client_ssl_write_update( http_client_t *hc ) ssl->wbio_pos += len; } if (r2 < 0) { - if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) { + if (ERRNO_AGAIN(errno)) { http_client_poll_dir(hc, 0, 1); errno = EAGAIN; return r2; @@ -383,7 +383,7 @@ write: while (1) { r2 = http_client_ssl_write_update(hc); if (r2 < 0) { - if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) + if (ERRNO_AGAIN(errno)) break; return r2; } @@ -489,8 +489,7 @@ http_client_send_partial( http_client_t *hc ) wcmd->wsize - wcmd->wpos, MSG_DONTWAIT); skip: if (r < 0) { - if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK || - errno == EINPROGRESS) { + if (ERRNO_AGAIN(errno) || errno == EINPROGRESS) { http_client_direction(hc, 1); return HTTP_CON_SENDING; } @@ -838,7 +837,7 @@ http_client_run( http_client_t *hc ) r = http_client_ssl_shutdown(hc); if (r < 0) { if (errno != EIO) { - if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) + if (ERRNO_AGAIN(errno)) return HTTP_CON_SENDING; return r; } @@ -874,7 +873,7 @@ retry: if (r < 0) { if (errno == EIO && hc->hc_in_data && !hc->hc_keepalive) return http_client_finish(hc); - if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) + if (ERRNO_AGAIN(errno)) return HTTP_CON_RECEIVING; return http_client_flush(hc, -errno); } @@ -1140,8 +1139,7 @@ http_client_thread ( void *p ) while (http_running) { n = tvhpoll_wait(http_poll, &ev, 1, -1); if (n < 0) { - if (http_running && - errno != EAGAIN && errno != EINTR && errno != EWOULDBLOCK) + if (http_running && !ERRNO_AGAIN(errno)) tvherror("httpc", "tvhpoll_wait() error"); } else if (n > 0) { if (&http_pipe == ev.data.ptr) { @@ -1742,7 +1740,7 @@ http_client_testsuite_run( void ) fprintf(stderr, "HTTPCTS: Enter Poll\n"); r = tvhpoll_wait(efd, &ev, 1, -1); fprintf(stderr, "HTTPCTS: Leave Poll: %i (%s)\n", r, r < 0 ? val2str(-r, ERRNO_tab) : "OK"); - if (r < 0 && (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK)) + if (r < 0 && ERRNO_AGAIN(errno)) continue; if (r < 0) { fprintf(stderr, "HTTPCTS: Poll result: %s\n", strerror(-r)); diff --git a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c index 6f161aac..b3e3b1ca 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_frontend.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_frontend.c @@ -667,7 +667,7 @@ linuxdvb_frontend_input_thread ( void *aux ) /* Read */ if (sbuf_read(&sb, dvr) < 0) { - if ((errno == EAGAIN) || (errno == EINTR)) + if (ERRNO_AGAIN(errno)) continue; if (errno == EOVERFLOW) { tvhlog(LOG_WARNING, "linuxdvb", "%s - read() EOVERFLOW", buf); diff --git a/src/input/mpegts/satip/satip_frontend.c b/src/input/mpegts/satip/satip_frontend.c index 687f4935..8ad6fc7a 100644 --- a/src/input/mpegts/satip/satip_frontend.c +++ b/src/input/mpegts/satip/satip_frontend.c @@ -1109,7 +1109,7 @@ satip_frontend_input_thread ( void *aux ) tc = udp_multirecv_read(&um, lfe->sf_rtp->fd, RTP_PKTS, &iovec); if (tc < 0) { - if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) + if (ERRNO_AGAIN(errno)) continue; if (errno == EOVERFLOW) { tvhlog(LOG_WARNING, "satip", "%s - recvmsg() EOVERFLOW", buf); @@ -1183,7 +1183,7 @@ satip_frontend_input_thread ( void *aux ) break; nfds = tvhpoll_wait(efd, ev, 1, -1); if (nfds <= 0) { - if (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK) + if (ERRNO_AGAIN(errno)) continue; break; } diff --git a/src/input/mpegts/tsfile/tsfile_input.c b/src/input/mpegts/tsfile/tsfile_input.c index b20adbed..fa799748 100644 --- a/src/input/mpegts/tsfile/tsfile_input.c +++ b/src/input/mpegts/tsfile/tsfile_input.c @@ -111,7 +111,7 @@ tsfile_input_thread ( void *aux ) /* Read */ c = sbuf_read(&buf, fd); if (c < 0) { - if (errno == EAGAIN || errno == EINTR) + if (ERRNO_AGAIN(errno)) continue; tvhlog(LOG_ERR, "tsfile", "read() error %d (%s)", errno, strerror(errno)); diff --git a/src/tcp.c b/src/tcp.c index fe65042f..1440281d 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -135,7 +135,7 @@ tcp_connect(const char *hostname, int port, const char *bindaddr, return -1; } - if (errno != EINTR && errno != EWOULDBLOCK && errno != EAGAIN) { + if (!ERRNO_AGAIN(errno)) { snprintf(errbuf, errbufsize, "poll() error: %s", strerror(errno)); tvhpoll_destroy(efd); close(fd); @@ -321,15 +321,15 @@ tcp_read_timeout(int fd, void *buf, size_t len, int timeout) if(x == 0) return ETIMEDOUT; if(x == -1) { - if (errno == EAGAIN) + if (ERRNO_AGAIN(errno)) continue; return errno; } x = recv(fd, buf + tot, len - tot, MSG_DONTWAIT); if(x == -1) { - if(errno == EAGAIN) - continue; + if(ERRNO_AGAIN(errno)) + continue; return errno; } diff --git a/src/timeshift/timeshift_writer.c b/src/timeshift/timeshift_writer.c index e3ecc22c..d3da9c03 100644 --- a/src/timeshift/timeshift_writer.c +++ b/src/timeshift/timeshift_writer.c @@ -44,7 +44,7 @@ static ssize_t _write while ( n < count ) { r = write(fd, buf+n, count-n); if (r == -1) { - if (errno == EAGAIN) + if (ERRNO_AGAIN(errno)) continue; else return -1; diff --git a/src/tvheadend.h b/src/tvheadend.h index 3a9dbb4f..614fabbb 100644 --- a/src/tvheadend.h +++ b/src/tvheadend.h @@ -44,6 +44,8 @@ #include "redblack.h" +#define ERRNO_AGAIN(e) ((e) == EAGAIN || (e) == EINTR || (e) == EWOULDBLOCK) + typedef struct { const char *name; const uint32_t *enabled; diff --git a/src/udp.c b/src/udp.c index 239c444f..1ed31cc8 100644 --- a/src/udp.c +++ b/src/udp.c @@ -424,7 +424,7 @@ udp_write( udp_connection_t *uc, const void *buf, size_t len, storage->ss_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)); if (r < 0) { - if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { + if (ERRNO_AGAIN(errno)) { usleep(100); continue; } diff --git a/src/wrappers.c b/src/wrappers.c index 3edb86cc..23826cd2 100644 --- a/src/wrappers.c +++ b/src/wrappers.c @@ -77,7 +77,7 @@ tvh_write(int fd, const void *buf, size_t len) while (len) { c = write(fd, buf, len); if (c < 0) { - if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { + if (ERRNO_AGAIN(errno)) { usleep(100); continue; }