#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
+#include <afs/opr.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#ifdef HAVE_STDINT_H
-# include <stdint.h>
-#endif
-#ifndef AFS_NT40_ENV
-# include <sys/socket.h>
-# include <sys/file.h>
-# include <netdb.h>
-# include <netinet/in.h>
-# include <net/if.h>
-# include <sys/ioctl.h>
-# include <sys/time.h>
-# include <unistd.h>
-#endif
-#include <sys/stat.h>
-#include <rx/rx.h>
-#include <rx/rx_globals.h>
#include <assert.h>
-#include <rx/rx_pthread.h>
-#include <rx/rx_clock.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
+
+static void rxi_SetThreadNum(int threadID);
/* Set rx_pthread_event_rescheduled if event_handler should just try
* again instead of sleeping.
AFS_SIGSET_DECL;
if (pthread_attr_init(&tattr) != 0) {
- dpf(("Unable to Create Rx server thread (pthread_attr_init)\n"));
- assert(0);
+ osi_Panic("Unable to Create Rx server thread (pthread_attr_init)\n");
}
if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) != 0) {
- dpf
- (("Unable to Create Rx server thread (pthread_attr_setdetachstate)\n"));
- assert(0);
+ osi_Panic("Unable to Create Rx server thread (pthread_attr_setdetachstate)\n");
}
/*
*/
AFS_SIGSET_CLEAR();
if (pthread_create(&thread, &tattr, server_entry, (void *)proc) != 0) {
- dpf(("Unable to Create Rx server thread\n"));
- assert(0);
+ osi_Panic("Unable to Create Rx server thread\n");
}
AFS_SIGSET_RESTORE();
}
} else {
if (!(p = rxi_AllocPacket(RX_PACKET_CLASS_RECEIVE))) {
/* Could this happen with multiple socket listeners? */
- dpf(("rxi_Listener: no packets!")); /* Shouldn't happen */
- assert(0);
+ osi_Panic("rxi_Listener: no packets!"); /* Shouldn't happen */
}
}
newcall = NULL;
threadID = -1;
rxi_ListenerProc(sock, &threadID, &newcall);
- /* assert(threadID != -1); */
- /* assert(newcall != NULL); */
+ /* osi_Assert(threadID != -1); */
+ /* osi_Assert(newcall != NULL); */
sock = OSI_NULLSOCKET;
- assert(pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)threadID) == 0);
+ rxi_SetThreadNum(threadID);
rxi_ServerProc(threadID, newcall, &sock);
- /* assert(sock != OSI_NULLSOCKET); */
+ /* osi_Assert(sock != OSI_NULLSOCKET); */
}
/* not reached */
return NULL;
while (1) {
sock = OSI_NULLSOCKET;
- assert(pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)threadID) == 0);
+ rxi_SetThreadNum(threadID);
rxi_ServerProc(threadID, newcall, &sock);
- /* assert(sock != OSI_NULLSOCKET); */
+ /* osi_Assert(sock != OSI_NULLSOCKET); */
newcall = NULL;
rxi_ListenerProc(sock, &threadID, &newcall);
- /* assert(threadID != -1); */
- /* assert(newcall != NULL); */
+ /* osi_Assert(threadID != -1); */
+ /* osi_Assert(newcall != NULL); */
}
/* not reached */
return NULL;
return;
if (pthread_attr_init(&tattr) != 0) {
- dpf
- (("Unable to create Rx event handling thread (pthread_attr_init)\n"));
- assert(0);
+ osi_Panic("Unable to create Rx event handling thread (pthread_attr_init)\n");
}
if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) != 0) {
- dpf
- (("Unable to create Rx event handling thread (pthread_attr_setdetachstate)\n"));
- assert(0);
+ osi_Panic("Unable to create Rx event handling thread (pthread_attr_setdetachstate)\n");
}
AFS_SIGSET_CLEAR();
if (pthread_create(&event_handler_thread, &tattr, event_handler, NULL) !=
0) {
- dpf(("Unable to create Rx event handling thread\n"));
- assert(0);
+ osi_Panic("Unable to create Rx event handling thread\n");
}
rx_NewThreadId();
AFS_SIGSET_RESTORE();
AFS_SIGSET_DECL;
if (pthread_attr_init(&tattr) != 0) {
- dpf
- (("Unable to create socket listener thread (pthread_attr_init)\n"));
- assert(0);
+ osi_Panic("Unable to create socket listener thread (pthread_attr_init)\n");
}
if (pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) != 0) {
- dpf
- (("Unable to create socket listener thread (pthread_attr_setdetachstate)\n"));
- assert(0);
+ osi_Panic("Unable to create socket listener thread (pthread_attr_setdetachstate)\n");
}
AFS_SIGSET_CLEAR();
if (pthread_create(&thread, &tattr, rx_ListenerProc, (void *)(intptr_t)sock) != 0) {
- dpf(("Unable to create socket listener thread\n"));
- assert(0);
+ osi_Panic("Unable to create socket listener thread\n");
}
rx_NewThreadId();
AFS_SIGSET_RESTORE();
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;
}
{
int ret;
ret = sendmsg(socket, msg_p, flags);
-#ifdef AFS_LINUX22_ENV
+
+#ifdef AFS_RXERRQ_ENV
+ if (ret < 0) {
+ while (rxi_HandleSocketError(socket) > 0)
+ ;
+ }
+ return ret;
+
+#else
+# 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) {
-#else
+# else
if (ret == -1) {
-#endif
+# endif
dpf(("rxi_sendmsg failed, error %d\n", errno));
fflush(stdout);
-#ifndef AFS_NT40_ENV
+# ifndef AFS_NT40_ENV
if (errno > 0)
return -errno;
-#else
+# else
if (WSAGetLastError() > 0)
return -WSAGetLastError();
-#endif
+# endif
return -1;
}
return 0;
+#endif /* !AFS_RXERRQ_ENV */
}
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));
- 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));
+ 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);
#ifdef RX_ENABLE_TSFPQ
queue_Init(&rx_ts_info->_FPQ);
#endif /* RX_ENABLE_TSFPQ */
return rx_ts_info;
}
+
+int
+rx_GetThreadNum(void) {
+ return (intptr_t)pthread_getspecific(rx_thread_id_key);
+}
+
+static void
+rxi_SetThreadNum(int threadID) {
+ osi_Assert(pthread_setspecific(rx_thread_id_key,
+ (void *)(intptr_t)threadID) == 0);
+}
+
+int
+rx_SetThreadNum(void) {
+ int threadId;
+
+ threadId = rx_NewThreadId();
+ rxi_SetThreadNum(threadId);
+ return threadId;
+}
+
+#endif