Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!maverick.ksu.ksu.edu!rutgers!mcnc!uvaarpa!mmdf From: bjaspan@ATHENA.MIT.EDU (Barr3y Jaspan) Newsgroups: comp.lang.perl Subject: Re: Perl-Users Digest #717 Message-ID: <1991Apr27.181749.8195@uvaarpa.Virginia.EDU> Date: 27 Apr 91 18:17:49 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: bjaspan@ATHENA.MIT.EDU Organization: The Internet Lines: 34 From: okamoto@hpcc01.HP.COM (Jeff Okamoto) Subject: What do you do after you've done select(2)? Date: 24 Apr 91 18:46:37 GMT I have a question about the select(2) emulation in perl. There are plenty of places that explain how to set up for the call to select, using fileno and vec to build the bitmap. What those same examples DON'T provide is a good way to determine which file handle(s) are ready for each operation. Well, here is a small part of a program I wrote that uses select. Basically, I keep track of the highest filedescriptor in the fdset that I pass to select, and then loop through the integers testing to see if each one is in the vector. (This is more memory efficient than an assoc array, probably, and not very time inefficient if you expect most of the descriptors to be set.) (BTW, this code is part of a "fast finger" I wrote that fingers all the machines in @ARGV in parallel, and then plays with select to get each answer as it comes in.) ($nfound, $timeleft) = select($rdout = $rdset, undef, undef, 15); if ($timeleft == 0 || $nfound == 0) { printf "Timeout with $argc requests unanswered.\n"; exit(1); } for ($i=0; $i <= $maxfn && $nfound; $i++) { next unless vec($rdout, $i, 1); Barr3y