Newsgroups: comp.lang.perl Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!boulder!spot.Colorado.EDU!frechett From: frechett@spot.Colorado.EDU (-=Runaway Daemon=-) Subject: Re: What am I missing from chat2.pl? Message-ID: <1991May27.215623.20884@colorado.edu> Sender: news@colorado.edu (The Daily Planet) Nntp-Posting-Host: spot.colorado.edu Organization: University of Colorado, Boulder References: <1991May27.120442.16645@colorado.edu> <1991May27.160539.8127@iWarp.intel.com> Date: Mon, 27 May 1991 21:56:23 GMT Lines: 69 In article <1991May27.160539.8127@iWarp.intel.com> merlyn@iWarp.intel.com (Randal L. Schwartz) writes: >(I'm working on "select" right now, by the way. Ugh. :-) Uh oh.. this doesn't sound good.. as I picked up chat2 hoping to be able to do what I was trying to do with select.. 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.. 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? if ($output =~ /^\/die|^\/quit/) { do dokill(); exit(0);} [...] } sleep 3; do dokill(); } # now on the other hand.. if I just poll the Socket and ignore stdin # it reads the socket fine.. else { while () { if (/Temperature/ ) { print "Damn damn damn\n$_"; } # we have a machine with a temperapture reading on some port.. print; } } exit(0); I am confused.. and from what I can tell.. select(2) is not easy to deal with at all... Everyone I talk to either says.. "I don't know what to tell you" or the classic "Well it's been a long time and I did it in C but this should work.... " And it never does.. Any help would be appreciated.. ian -=Runaway Daemon=-