select() call does not return after timeout

select() call does not return after timeout

Post by Arjan van Vugh » Tue, 20 Feb 2001 23:39:45



Hi,
See code fragment below. Everything goes ok if the remote host is
sending back data. However, when the remote host does not response, the
select() call does not retrun after a non-zero time out. The environment
is Windows NT with SP6a. Any idea what is going wrong?. Thanks, Arjan

   TimeVal.tv_sec  = (long)secTimeOut;
   TimeVal.tv_usec = (long)usecTimeOut;

   FD_ZERO(&ReadMask);
   FD_SET(s, &ReadMask);

   rc = select(s + 1, &ReadMask, (fd_set *)0, (fd_set *)0, (secTimeOut *
usecTimeOut) == 0 ? NULL : &TimeVal);

   FD_CLR(s, &ReadMask);

   if (rc < 0)
      return WSAGetLastError() == WSAEINTR ? UDP_CANCELLED : UDP_ERROR;

   if (rc == 0)
      return UDP_TIMEOUT;

   recvfrom(s, buf, len, flags, from, fromlen);

 
 
 

select() call does not return after timeout

Post by Alun Jon » Wed, 21 Feb 2001 06:30:01




> Hi,
> See code fragment below. Everything goes ok if the remote host is
> sending back data. However, when the remote host does not response, the
> select() call does not retrun after a non-zero time out. The environment
> is Windows NT with SP6a. Any idea what is going wrong?. Thanks, Arjan

>    TimeVal.tv_sec  = (long)secTimeOut;
>    TimeVal.tv_usec = (long)usecTimeOut;

>    FD_ZERO(&ReadMask);
>    FD_SET(s, &ReadMask);

>    rc = select(s + 1, &ReadMask, (fd_set *)0, (fd_set *)0, (secTimeOut *
> usecTimeOut) == 0 ? NULL : &TimeVal);

Did you really mean to disable the timeout if _either_ the secTimeOut or
usecTimeOut is zero?  Generally, one or other of these is likely to be zero.

I suspect what you meant to say is:

if ((secTimeOut==0) && (usecTimeOut==0))
        pTime=NULL;
else
        pTime=&TimeVal;

rc = select( s+1, &ReadMask, NULL, NULL, pTime);

Alun.
~~~~

Alun.
~~~~

[Note that answers to questions in newsgroups are not generally
invitations to contact me personally for help in the future.]
--
Texas Imperial Software   | Try WFTPD, the Windows FTP Server. Find us at

Cedar Park TX 78613-1419  | VISA/MC accepted.  NT-based sites, be sure to
Fax/Voice +1(512)378-3246 | read details of WFTPD Pro for NT.

 
 
 

1. select timeout does not work

Greetings,

I am trying to do a select loop that has a timeout so I can check if a
die event has been set.  The problem seems to be that the select always
returns right away.  No wait.  Thus, my cpu utilization is sky high.
Any clues ???

I have read that you should stay away from selects, any suggestions ???
( from online help, SDK/Win32/NetworkServices/Windows Socket Services
for Windows NT/ Additional Items/Notes on Performance )

This code fragment is in a thread that sits and waits for connects, does
some work, and waits again.  I am trying to find a graceful to shutdown
while waiting for an accept.  Also, I do not have access to the actual
accept;  it is packages away in a communication library we are using.
It does not has its own timeout.

//--init the fd_set and add our descriptor to it
iSystemFd = iListenFd  ;

memset( &fdRead, '\0', sizeof( struct fd_set ));
FD_ZERO( &fdRead );
FD_SET( iSystemFd, &fdRead ) ;

do
{                                                      
   theTimeVal.tv_sec = 1 ;
   theTimeVal.tv_usec = 500 ;

   iStatus = select( iSystemFd, &fdRead, NULL, NULL, &theTimeVal ) ;

   if ( WAIT_OBJECT_0 == WaitForSingleObject( g_hEndServerThreadEvent, 0
))
   {
      //--get the signal to die, break out of this loop
      TRACE( "serverThread : got signal to shutdown in select loop.\n ")
;
      break;
   }
while ( 0 == iStatus ) ; //-- 0 means a timeout occured

ANI_Accept( ...)

2. Do I need IPX/SPX and NetBEUI?

3. WQL will not let me select individual properties - only select * works

4. Palmtop Processor Performance table

5. Timeout value for SELECT() (to listen to sockets) - how accurat?

6. choosing personal firewall ?

7. timeout for select

8. Need info on BOOT MANAGER

9. select() timeout question

10. non-blocking connect select timeout

11. Winsock select() Timeout Problem

12. IADsUser.Groups returns nothing when calling it in a normal user context (not domain admin)

13. Not return for several seconds from a TDI_OPEN_ADDRESS call?