rx: Save errno in pthread rxi_Sendmsg
[openafs.git] / src / rx / rx_pthread.c
index 97f058c..3e61245 100644 (file)
 
 #include <assert.h>
 
+#ifdef AFS_PTHREAD_ENV
+
 #include "rx.h"
 #include "rx_globals.h"
 #include "rx_pthread.h"
 #include "rx_clock.h"
 #include "rx_atomic.h"
+#include "rx_internal.h"
+#include "rx_pthread.h"
 #ifdef AFS_NT40_ENV
 #include "rx_xmit_nt.h"
 #endif
@@ -178,7 +182,7 @@ event_handler(void *argp)
 #endif
        rx_pthread_event_rescheduled = 0;
     }
-    return NULL;
+    AFS_UNREACHED(return(NULL));
 }
 
 
@@ -204,6 +208,12 @@ rxi_ListenerProc(osi_socket sock, int *tnop, struct rx_call **newcallp)
     u_short port;
     struct rx_packet *p = (struct rx_packet *)0;
 
+    if (!(rx_enable_hot_thread && newcallp)) {
+       /* Don't do this for hot threads, since we might stop being the
+        * listener. */
+       opr_threadname_set("rx_Listener");
+    }
+
     MUTEX_ENTER(&listener_mutex);
     while (!listeners_started) {
        CV_WAIT(&rx_listener_cond, &listener_mutex);
@@ -260,8 +270,7 @@ rx_ListenerProc(void *argp)
        rxi_ServerProc(threadID, newcall, &sock);
        /* osi_Assert(sock != OSI_NULLSOCKET); */
     }
-    /* not reached */
-    return NULL;
+    AFS_UNREACHED(return(NULL));
 }
 
 /* This is the server process request loop. The server process loop
@@ -308,8 +317,7 @@ rx_ServerProc(void * dummy)
        /* osi_Assert(threadID != -1); */
        /* osi_Assert(newcall != NULL); */
     }
-    /* not reached */
-    return NULL;
+    AFS_UNREACHED(return(NULL));
 }
 
 /*
@@ -389,11 +397,15 @@ int
 rxi_Recvmsg(osi_socket socket, struct msghdr *msg_p, int flags)
 {
     int ret;
-#if defined(HAVE_LINUX_ERRQUEUE_H) && defined(ADAPT_PMTU)
-    while((rxi_HandleSocketError(socket)) > 0)
-      ;
-#endif
     ret = recvmsg(socket, msg_p, flags);
+
+#ifdef AFS_RXERRQ_ENV
+    if (ret < 0) {
+       while (rxi_HandleSocketError(socket) > 0)
+           ;
+    }
+#endif
+
     return ret;
 }
 
@@ -403,37 +415,45 @@ rxi_Recvmsg(osi_socket socket, struct msghdr *msg_p, int flags)
 int
 rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags)
 {
-    int ret;
-    ret = sendmsg(socket, msg_p, flags);
-#ifdef 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 (ret == -1 && errno != ECONNREFUSED && errno != EAGAIN) {
+    int err;
+    if (sendmsg(socket, msg_p, flags) >= 0) {
+       return 0;
+    }
+
+#ifdef AFS_NT40_ENV
+    err = WSAGetLastError();
 #else
-    if (ret == -1) {
+    err = errno;
 #endif
-       dpf(("rxi_sendmsg failed, error %d\n", errno));
-       fflush(stdout);
-#ifndef AFS_NT40_ENV
-        if (errno > 0)
-          return -errno;
+
+#ifdef AFS_RXERRQ_ENV
+    while (rxi_HandleSocketError(socket) > 0)
+       ;
 #else
-            if (WSAGetLastError() > 0)
-              return -WSAGetLastError();
-#endif
-       return -1;
+# ifdef 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 (err == ECONNREFUSED || err == EAGAIN) {
+       return 0;
     }
-    return 0;
+# endif
+    dpf(("rxi_sendmsg failed, error %d\n", errno));
+    fflush(stdout);
+#endif /* !AFS_RXERRQ_ENV */
+
+    if (err > 0) {
+       return -err;
+    }
+    return -1;
 }
 
 struct rx_ts_info_t * rx_ts_info_init(void) {
     struct rx_ts_info_t * rx_ts_info;
-    rx_ts_info = (rx_ts_info_t *) malloc(sizeof(rx_ts_info_t));
+    rx_ts_info = calloc(1, sizeof(rx_ts_info_t));
     osi_Assert(rx_ts_info != NULL && pthread_setspecific(rx_ts_info_key, rx_ts_info) == 0);
-    memset(rx_ts_info, 0, sizeof(rx_ts_info_t));
 #ifdef RX_ENABLE_TSFPQ
-    queue_Init(&rx_ts_info->_FPQ);
+    opr_queue_Init(&rx_ts_info->_FPQ.queue);
 
     MUTEX_ENTER(&rx_packets_mutex);
     rx_TSFPQMaxProcs++;
@@ -463,3 +483,4 @@ rx_SetThreadNum(void) {
     return threadId;
 }
 
+#endif