Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.development.apps > #266

Re: Select System hangs

From Tauno Voipio <tauno.voipio@notused.fi.invalid>
Newsgroups comp.os.linux.development.apps
Subject Re: Select System hangs
Date 2011-09-12 16:59 +0300
Organization A noiseless patient Spider
Message-ID <j4l38j$ke$1@dont-email.me> (permalink)
References <35d1911c-4fde-441b-ad3a-c5adcd9f2874@x32g2000prf.googlegroups.com>

Show all headers | View raw


On 12.9.11 3:30 , khan wrote:
> Hi,
> I had code where select waits on only one File-descriptor, in while
> loop. If FD_SET and FD_ZERO is done outside while loop thread hangs in
> select system call , when moved FD_ZERO and FD_SET inside while-loop
> it is working for more than a week testing.
> I didn't understand this behavior.
> Here is code snippet : FD_SET and FD_ZERO outside loop
> /*FD_ZERO and FD_SET*/
> FD_ZERO(&rfds);
> FD_SET(chipset_p->fd,&rfds);
>
> while(1) {
> /*FD_ZERO and FD_SET*/
> FD_ZERO(&rfds);
> FD_SET(chipset_p->fd,&rfds);
> select((chipset_p->fd + 1),&rfds, NULL, NULL,NULL);
> if (FD_ISSET(chipset_p->fd,&rfds)) {
>   /*Calle handler*/
> }
> }
> In above code thread hangs in select system call.
>
> Code snippet: FD_ZERO and FD_SET in while-loop
> while(1) {
> select((chipset_p->fd + 1),&rfds, NULL, NULL,NULL);
> if (FD_ISSET(chipset_p->fd,&rfds)) {
>   /*Calle handler*/
> }
> }
>
> But i didn't understand why select() didn't work if we just do
> FD_ZER() and FD_SET() once and pass the same readfds to select()?
>
> Thanks,
> Mushtaq Khan


----

 From man select:

Three  independent  sets of file descriptors are watched.  Those listed
in readfds will be watched to see if characters  become  available  for
reading  (more  precisely, to see if a read will not block; in particu‐
lar, a file descriptor is also ready on end-of-file), those in writefds
will  be  watched  to  see  if  a  write  will  not block, and those in 
exceptfds will be watched for exceptions.  On exit, the sets are  modi‐
fied  in place to indicate which file descriptors actually changed sta‐
tus.  Each of the three file descriptor sets may be specified  as  NULL
if no file descriptors are to be watched for the corresponding class of
events.

---

Please note that the system call will modify the descriptor sets.

-- 

Tauno Voipio

Back to comp.os.linux.development.apps | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Select System hangs khan <mushtaqk921@gmail.com> - 2011-09-12 05:30 -0700
  Re: Select System hangs Tauno Voipio <tauno.voipio@notused.fi.invalid> - 2011-09-12 16:59 +0300
  Re: Select System hangs David Schwartz <davids@webmaster.com> - 2011-09-17 05:05 -0700
    Re: Select System hangs Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-09-18 20:44 +0100

csiph-web