From a3f495b66431773d44a04be14b09d71cb3921d82 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. Reviewed-on: http://gerrit.openafs.org/8110 Reviewed-by: Derrick Brashear Tested-by: BuildBot (cherry picked from commit 347908cd0031c558c266ec412aa49200ae2b3204) Change-Id: Ia0134acb2ae5f9e47fb82f36bd0889987803d897 Reviewed-on: http://gerrit.openafs.org/9496 Tested-by: BuildBot Reviewed-by: Derrick Brashear Reviewed-by: Benjamin Kaduk Reviewed-by: Andrew Deason Tested-by: Benjamin Kaduk Reviewed-by: Stephan Wiesand --- 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 525743edc..929c90fe9 100644 --- a/src/rx/rx_lwp.c +++ b/src/rx/rx_lwp.c @@ -434,6 +434,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 + rx_stats.sendSelects++; if (!sfds) { @@ -449,26 +456,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(socket + 1, 0, sfds, 0, 0)) != 1) { -- 2.39.5