From cecc20a3077408718ce7806bd5f0253f335dac2a Mon Sep 17 00:00:00 2001 From: Richard Cochran Date: Tue, 13 Dec 2011 05:28:54 +0100 Subject: [PATCH] udp: wait longer for transmit time stamps Some hardware is a bit pokey. We now wait forever on EINTR and just a little bit on EAGAIN. Signed-off-by: Richard Cochran --- udp.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/udp.c b/udp.c index 6ce3636..8a9aeeb 100644 --- a/udp.c +++ b/udp.c @@ -230,7 +230,7 @@ static int receive(int fd, void *buf, int buflen, struct hw_timestamp *hwts, int flags) { char control[256]; - int cnt, level, type; + int cnt, level, try_again, type; struct cmsghdr *cm; struct iovec iov = { buf, buflen }; struct msghdr msg; @@ -241,11 +241,21 @@ static int receive(int fd, void *buf, int buflen, msg.msg_iovlen = 1; msg.msg_control = control; msg.msg_controllen = sizeof(control); -again: - cnt = recvmsg(fd, &msg, flags); - if (cnt < 0) { - if (EINTR == errno) - goto again; + + try_again = flags == MSG_ERRQUEUE ? 2 : 1; + + for ( ; try_again; try_again--) { + cnt = recvmsg(fd, &msg, flags); + if (cnt >= 0) { + break; + } + if (errno == EINTR) { + try_again++; + } else if (errno == EAGAIN) { + usleep(1); + } else { + break; + } } for (cm = CMSG_FIRSTHDR(&msg); cm != NULL; cm = CMSG_NXTHDR(&msg, cm)) { @@ -298,8 +308,10 @@ int udp_send(struct fdarray *fda, int event, addr.sin_port = htons(event ? EVENT_PORT : GENERAL_PORT); cnt = sendto(fd, buf, len, 0, (struct sockaddr *)&addr, sizeof(addr)); - if (cnt < 1) + if (cnt < 1) { + perror("sendto"); return cnt; + } /* * Get the time stamp right away. */