fix UDP code to work with a higher socket fd
This commit is contained in:
11
network.c
11
network.c
@ -188,7 +188,7 @@ mkChannel *NETAccept(mkChannel * self, long timeout)
|
|||||||
return NULL; /* eof */
|
return NULL; /* eof */
|
||||||
}
|
}
|
||||||
iRet =
|
iRet =
|
||||||
uselect((self->sockid + 1), (fd_set *) & lMask, NULL, NULL, &tmo);
|
uselect((self->sockid + 1), &lMask, NULL, NULL, &tmo);
|
||||||
if (iRet <= 0) {
|
if (iRet <= 0) {
|
||||||
/* failure, or no request */
|
/* failure, or no request */
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -848,7 +848,7 @@ mkChannel *UDPOpen(int iPort)
|
|||||||
i = 1;
|
i = 1;
|
||||||
setsockopt(pRes->sockid, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(int));
|
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
|
/* if this fails the masks for select will be to
|
||||||
short.
|
short.
|
||||||
*/
|
*/
|
||||||
@ -924,7 +924,7 @@ mkChannel *UDPConnect(char *name, int port)
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
long UDPRead(mkChannel * self, char *buffer, long lLen, int timeout)
|
long UDPRead(mkChannel * self, char *buffer, long lLen, int timeout)
|
||||||
{
|
{
|
||||||
long lMask = 0L;
|
fd_set lMask;
|
||||||
struct timeval tmo = { 0, 1 };
|
struct timeval tmo = { 0, 1 };
|
||||||
long iRet;
|
long iRet;
|
||||||
socklen_t iLang;
|
socklen_t iLang;
|
||||||
@ -938,9 +938,10 @@ long UDPRead(mkChannel * self, char *buffer, long lLen, int timeout)
|
|||||||
/* setup for select first */
|
/* setup for select first */
|
||||||
tmo.tv_usec = (timeout % 1000) * 1000;
|
tmo.tv_usec = (timeout % 1000) * 1000;
|
||||||
tmo.tv_sec = timeout / 1000;
|
tmo.tv_sec = timeout / 1000;
|
||||||
lMask = (1 << self->sockid);
|
FD_ZERO(&lMask);
|
||||||
|
FD_SET(self->sockid, &lMask);
|
||||||
iRet =
|
iRet =
|
||||||
uselect((self->sockid + 1), (fd_set *) & lMask, NULL, NULL, &tmo);
|
uselect((self->sockid + 1), &lMask, NULL, NULL, &tmo);
|
||||||
if (iRet <= 0) {
|
if (iRet <= 0) {
|
||||||
/* failure, or no data */
|
/* failure, or no data */
|
||||||
return 0;
|
return 0;
|
||||||
|
Reference in New Issue
Block a user