use FD_SETSIZE macro

This commit is contained in:
Jeff Hill
1998-02-05 22:01:16 +00:00
parent 79375295b8
commit 5bf27c9d79

View File

@@ -40,21 +40,21 @@
* NOTE: on multithreaded systems this assumes that the
* local implementation of select is reentrant
*/
int cac_select_io(struct timeval *ptimeout, int flags)
int cac_select_io (struct timeval *ptimeout, int flags)
{
/*
* Use auto timeout so there is no chance of
* recursive reuse of ptimeout
*/
struct timeval autoTimeOut = *ptimeout;
long status;
IIU *piiu;
unsigned long freespace;
long status;
IIU *piiu;
unsigned long freespace;
SOCKET maxfd;
caFDInfo *pfdi;
int ioPending;
LOCK;
LOCK;
pfdi = (caFDInfo *) ellGet(&ca_static->fdInfoFreeList);
if (!pfdi) {
@@ -72,57 +72,38 @@ int cac_select_io(struct timeval *ptimeout, int flags)
maxfd = 0;
ioPending = FALSE;
for( piiu = (IIU *) iiuList.node.next;
piiu;
piiu = (IIU *) piiu->node.next) {
for( piiu = (IIU *) iiuList.node.next;
piiu; piiu = (IIU *) piiu->node.next) {
if (piiu->state==iiu_disconnected) {
continue;
}
#ifdef _WIN32
/* Under WIN32, FD_SETSIZE is the number of sockets,
* not the max. file descriptor value that you may select() !
*
* Of course it's not allowed to look into fd_count,
* but what shall we do? -kuk-
*/
if (pfdi->readMask.fd_count >= FD_SETSIZE)
{
ca_printf(
"%s.%d: no room for fd %d in fd_set (FD_SETSIZE=%d)\n",
__FILE__, __LINE__, piiu->sock_chan, FD_SETSIZE);
continue;
}
#else
if (piiu->sock_chan>=FD_SETSIZE)
if (!FD_IN_FDSET(piiu->sock_chan))
{
ca_printf(
"%s.%d: file number %d > FD_SETSIZE=%d ignored\n",
__FILE__, __LINE__, piiu->sock_chan, FD_SETSIZE);
continue;
}
#endif
/*
* Dont bother receiving if we have insufficient
* space for the maximum UDP message, or space
/*
* Dont bother receiving if we have insufficient
* space for the maximum UDP message, or space
* for one TCP byte.
*/
if (flags&CA_DO_RECVS) {
freespace = cacRingBufferWriteSize (&piiu->recv, TRUE);
if (freespace>=piiu->minfreespace) {
*/
if (flags&CA_DO_RECVS) {
freespace = cacRingBufferWriteSize (&piiu->recv, TRUE);
if (freespace>=piiu->minfreespace) {
maxfd = max (maxfd,piiu->sock_chan);
FD_SET (piiu->sock_chan, &pfdi->readMask);
FD_SET (piiu->sock_chan, &pfdi->readMask);
piiu->recvPending = TRUE;
ioPending = TRUE;
}
}
else {
piiu->recvPending = FALSE;
}
}
}
else {
piiu->recvPending = FALSE;
}
@@ -137,8 +118,8 @@ int cac_select_io(struct timeval *ptimeout, int flags)
FD_SET (piiu->sock_chan, &pfdi->writeMask);
ioPending = TRUE;
}
}
}
}
}
UNLOCK;
/*
@@ -160,10 +141,10 @@ int cac_select_io(struct timeval *ptimeout, int flags)
if (status<0) {
int errnoCpy = SOCKERRNO;
if (errnoCpy!=EINTR) {
if (errnoCpy!=SOCK_EINTR) {
ca_printf (
"CAC: unexpected select fail: %s\n",
strerror(SOCKERRNO));
SOCKERRSTR);
}
}
}
@@ -182,30 +163,27 @@ int cac_select_io(struct timeval *ptimeout, int flags)
* if any of the IOCs are in flow control (so that an exit
* flow control msg can be sent to each of them that are)
*/
if (status>0 ||
(ca_static->ca_number_iiu_in_fc>0u&&status>=0) ) {
for ( piiu = (IIU *) iiuList.node.next;
piiu;
piiu = (IIU *) piiu->node.next) {
if (status>0 || (ca_static->ca_number_iiu_in_fc>0u&&status>=0) ) {
for ( piiu = (IIU *) iiuList.node.next;
piiu; piiu = (IIU *) piiu->node.next) {
if (piiu->state==iiu_disconnected) {
continue;
}
if (piiu->state==iiu_disconnected) {
continue;
}
if (FD_ISSET(piiu->sock_chan,&pfdi->readMask)) {
(*piiu->recvBytes)(piiu);
if (FD_ISSET(piiu->sock_chan,&pfdi->readMask)) {
(*piiu->recvBytes)(piiu);
/*
* if we were not blocking and there is a
* message present then start to suspect that
* we are getting behind
*/
if (piiu->sock_proto==IPPROTO_TCP) {
if (ptimeout->tv_sec==0
|| ptimeout->tv_usec==0) {
if (ptimeout->tv_sec==0 || ptimeout->tv_usec==0) {
flow_control_on(piiu);
}
}
}
}
else if (piiu->recvPending) {
/*
* if we are looking for incoming messages
@@ -220,13 +198,13 @@ int cac_select_io(struct timeval *ptimeout, int flags)
if (FD_ISSET(piiu->sock_chan,&pfdi->writeMask)) {
(*piiu->sendBytes)(piiu);
}
}
}
}
}
ellDelete (&ca_static->fdInfoList, &pfdi->node);
ellAdd (&ca_static->fdInfoFreeList, &pfdi->node);
UNLOCK;
return status;
return status;
}