From 6c5439b80934cd6e3f0539a07874c3bda18d676d Mon Sep 17 00:00:00 2001 From: Jeffrey Hutzelman Date: Wed, 31 Jul 2002 23:35:09 +0000 Subject: [PATCH] deal-with-linux-EAGAIN-returns-when-receiving-20020731 sometimes you get EAGAIN from recvfrom, apparently if a packet comes in with a bad checksum for instance. we should deal better. --- src/kauth/krb_udp.c | 14 ++++++++++++++ src/rx/rx_lwp.c | 4 +++- src/rx/rx_pthread.c | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/kauth/krb_udp.c b/src/kauth/krb_udp.c index 4f5d9ca268..4154fe1fcb 100644 --- a/src/kauth/krb_udp.c +++ b/src/kauth/krb_udp.c @@ -778,6 +778,8 @@ static SocketListener () code = recvfrom(sock_kerb, packet.data, sizeof(packet.data), 0, (struct sockaddr *) &packet.from, &fromLen); if (code < 0) { + if (errno == EAGAIN || errno == ECONNREFUSED) + goto try_kerb5; perror ("calling recvfrom"); break; } @@ -792,10 +794,13 @@ static SocketListener () packet.time = 0; process_udp_request (sock_kerb, &packet); } +try_kerb5: if ((sock_kerb5 >= 0) && FD_ISSET(sock_kerb5, &rfds)) { code = recvfrom(sock_kerb5, packet.data, sizeof(packet.data), 0, (struct sockaddr *) &packet.from, &fromLen); if (code < 0) { + if (errno == EAGAIN || errno == ECONNREFUSED) + continue; perror ("calling recvfrom"); break; } @@ -811,6 +816,15 @@ static SocketListener () process_udp_request (sock_kerb5, &packet); } } + if (sock_kerb >= 0) { + close(sock_kerb); + sock_kerb = -1; + } + if (sock_kerb5 >= 0) { + close(sock_kerb5); + sock_kerb5 = -1; + } + printf("UDP SocketListener exiting due to error\n"); } #if MAIN diff --git a/src/rx/rx_lwp.c b/src/rx/rx_lwp.c index 2daed73527..0e6ffb557b 100644 --- a/src/rx/rx_lwp.c +++ b/src/rx/rx_lwp.c @@ -431,7 +431,9 @@ int rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags) #elif defined(AFS_LINUX22_ENV) /* linux unfortunately returns ECONNREFUSED if the target port * is no longer in use */ - if (errno != EWOULDBLOCK && errno != ENOBUFS && errno != ECONNREFUSED) + /* and EAGAIN if a UDP checksum is incorrect */ + if (errno != EWOULDBLOCK && errno != ENOBUFS && + errno != ECONNREFUSED && errno != EAGAIN) #else if (errno != EWOULDBLOCK && errno != ENOBUFS) #endif diff --git a/src/rx/rx_pthread.c b/src/rx/rx_pthread.c index a2b7297c99..295913f24d 100644 --- a/src/rx/rx_pthread.c +++ b/src/rx/rx_pthread.c @@ -403,7 +403,8 @@ rxi_Sendmsg(socket, msg_p, flags) #ifdef AFS_LINUX22_ENV /* linux unfortunately returns ECONNREFUSED if the target port * is no longer in use */ - if (ret == -1 && errno != ECONNREFUSED) { + /* and EAGAIN if a UDP checksum is incorrect */ + if (ret == -1 && errno != ECONNREFUSED && errno != EAGAIN) { #else if (ret == -1) { #endif