From 347908cd0031c558c266ec412aa49200ae2b3204 Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Tue, 11 Sep 2012 18:46:42 -0500 Subject: [PATCH] rx: Save errno in LWP rxi_Sendmsg Much of this code examines errno or WSAGetLastError to determine what to do. However, some other operations between the actual sendmsg call and code that examines errno may modify errno. So, save the value of errno to ensure errno reflects the actual error we got from sendmsg; this also slightly simplifies some of the logic. Change-Id: I5a8643fce5d2e29131069743b14805bbc2428805 Reviewed-on: http://gerrit.openafs.org/8110 Reviewed-by: Derrick Brashear Tested-by: BuildBot --- src/rx/rx_lwp.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/rx/rx_lwp.c b/src/rx/rx_lwp.c index e6ae068e1..fe9bdceef 100644 --- a/src/rx/rx_lwp.c +++ b/src/rx/rx_lwp.c @@ -429,6 +429,13 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags) fd_set *sfds = (fd_set *) 0; while (sendmsg(socket, msg_p, flags) == -1) { int err; + +#ifdef AFS_NT40_ENV + err = WSAGetLastError(); +#else + err = errno; +#endif + if (rx_stats_active) rx_atomic_inc(&rx_stats.sendSelects); @@ -445,26 +452,21 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags) ; #endif #ifdef AFS_NT40_ENV - if (WSAGetLastError()) + if (err) #elif defined(AFS_LINUX22_ENV) /* linux unfortunately returns ECONNREFUSED if the target port * is no longer in use */ /* and EAGAIN if a UDP checksum is incorrect */ - if (errno != EWOULDBLOCK && errno != ENOBUFS && errno != ECONNREFUSED - && errno != EAGAIN) + if (err != EWOULDBLOCK && err != ENOBUFS && err != ECONNREFUSED + && err != EAGAIN) #else - if (errno != EWOULDBLOCK && errno != ENOBUFS) + if (err != EWOULDBLOCK && err != ENOBUFS) #endif { (osi_Msg "rx failed to send packet: "); perror("rx_sendmsg"); -#ifndef AFS_NT40_ENV - if (errno > 0) - return -errno; -#else - if (WSAGetLastError() > 0) - return -WSAGetLastError(); -#endif + if (err > 0) + return -err; return -1; } while ((err = select( -- 2.39.5