From 6ca55df3d67d28d8d1baec650663387c9d927c29 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Thu, 13 Dec 2012 13:50:32 +1100 Subject: [PATCH] fix UDP code to work with a higher socket fd --- network.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/network.c b/network.c index f250175e..bb5b6131 100644 --- a/network.c +++ b/network.c @@ -188,7 +188,7 @@ mkChannel *NETAccept(mkChannel * self, long timeout) return NULL; /* eof */ } iRet = - uselect((self->sockid + 1), (fd_set *) & lMask, NULL, NULL, &tmo); + uselect((self->sockid + 1), &lMask, NULL, NULL, &tmo); if (iRet <= 0) { /* failure, or no request */ return NULL; @@ -848,7 +848,7 @@ mkChannel *UDPOpen(int iPort) i = 1; setsockopt(pRes->sockid, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(int)); - assert(pRes->sockid < (sizeof(long) * 8)); + assert(pRes->sockid < FD_SETSIZE); /* if this fails the masks for select will be to short. */ @@ -924,7 +924,7 @@ mkChannel *UDPConnect(char *name, int port) /*--------------------------------------------------------------------------*/ long UDPRead(mkChannel * self, char *buffer, long lLen, int timeout) { - long lMask = 0L; + fd_set lMask; struct timeval tmo = { 0, 1 }; long iRet; socklen_t iLang; @@ -938,9 +938,10 @@ long UDPRead(mkChannel * self, char *buffer, long lLen, int timeout) /* setup for select first */ tmo.tv_usec = (timeout % 1000) * 1000; tmo.tv_sec = timeout / 1000; - lMask = (1 << self->sockid); + FD_ZERO(&lMask); + FD_SET(self->sockid, &lMask); iRet = - uselect((self->sockid + 1), (fd_set *) & lMask, NULL, NULL, &tmo); + uselect((self->sockid + 1), &lMask, NULL, NULL, &tmo); if (iRet <= 0) { /* failure, or no data */ return 0;