Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.jpl.nasa.gov (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: What am I missing from chat2.pl? Message-ID: <1991Jun10.173227.4630@jpl-devvax.jpl.nasa.gov> Date: 10 Jun 91 17:32:27 GMT References: <1991May27.120442.16645@colorado.edu> <1991May27.160539.8127@iWarp.intel.com> <1991May27.215623.20884@colorado.edu> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 47 In article <1991May27.215623.20884@colorado.edu> frechett@spot.Colorado.EDU (-=Runaway Daemon=-) writes: : Here's the situation.. I have a client (addapted from the in the man pages) : and I want to be able to poll stdin and the socket both.. Was hoping to : find something in chat2.pl but if you haven't written a select then I : suspect that I am am going to have a bit of aproblem.. : : It is a simple matter to listen to the socket and parse what I see and : such.. OR to listen to the users's input but as soon as I start to try to : deal with both.. it stalls on something.. Here is a code fragment... : : S is the socket.. : : sub fhbits { : local(@fhlist) = split(' ',$_[0]); : local($bits); : for (@fhlist) { : vec($bits,fileno($_),1)=1; : } : $bits; : } : $rin = ""; : $rin = &fhbits('stdin S'); : # the problem here is that I don't see ANYTHING in $rin Is it : # unprintable.. and just what the hell is it anyway.. It's a bit vector, 8 bits to the byte, so of course it's not guaranteed to be printable. You get the bits out with vec() just like you put them in. Alternately, use unpack('b*', ...) to turn it into a string of 0's and 1's. : if ($child = fork) { : for (;;) { : # it pauses here fine.. waiting for something to come through.. : ($nfound) = select($rout=$rin, undef,undef,undef); : # but I am totally stuck here... I couldn't see what $rin was and I can't : # see what $rout is.. so I don't know what filedescriptors are ready.. : # not only that but when I put in a line like... : if ($nfound == 1) { read(S,$output,1024); print "$output"; } : # and then sent it only stuff through the socket.. it still wasn't : # trapping it.. It just froze stdin of course.. It just displays what is : # coming throught the socket but the select didn't see it and read didn't see : # it.. What's wrong? read() calls C's fread() function, which is going to try to read 1024 bytes come hell or high water (or both, if too many snowballs melt there). Use sysread() instead--that's one of the reasons it's there. Larry