add ERRNO_AGAIN() macro to check the interrupted / no data states correctly

This commit is contained in:
Jaroslav Kysela 2014-07-05 11:15:11 +02:00
parent f0b284065d
commit 0b4bcfaa98
9 changed files with 22 additions and 22 deletions

View file

@ -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));

View file

@ -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);

View file

@ -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;
}

View file

@ -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));

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}