home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!wupost!darwin.sura.net!uvaarpa!mmdf
- From: Dov Grobgeld <dov@menora.weizmann.ac.il>
- Subject: select misses pending data on socket
- Message-ID: <1992Aug31.201931.14111@uvaarpa.Virginia.EDU>
- Sender: mmdf@uvaarpa.Virginia.EDU (Mail System)
- Reply-To: dov@menora.weizmann.ac.il
- Organization: The Internet
- Date: Mon, 31 Aug 1992 20:19:31 GMT
- Lines: 77
-
- Fellow other Perl hackers,
-
- I tried rewriting the client program of the Camel book to use select (with
- four arguments) instead of the fork. What I did was to replace the lines
-
- # Avoid deadlock by forking.
-
- if($child = fork) {
- while (<STDIN>) {
- print S;
- }
- sleep 3;
- do dokill();
- }
- else {
- while(<S>) {
- print;
- }
- }
-
- with the lines
-
- # This version uses the select call to find out if there is data pending
-
- $rin = $win = $ein = "\000";
- vec($rin,fileno(S),1) = 1;
- vec($ttyin,fileno(STDIN),1) = 1;
- $rin |= $ttyin;
-
- print "fileno(S)=", fileno(S), "\n";
- print "fileno(STDIN)=", fileno(STDIN), "\n";
- print "rin=",unpack("b*", $rin),"\n";
- $timeout=1;
-
- while (1) {
- $nfound = select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
- print "rout=",unpack("b*", $rout),"\n";
-
- if (vec($rout,fileno(S),1)) {
- $_=<S>;
- print;
- }
- if (vec($rout,fileno(STDIN),1)) {
- $_=<STDIN>;
- print S;
- }
- }
-
- and the rest of the client (i.e. the opening socket part) being the same.
-
- As a trial server I use my lokal SMTP deamon. I connect without any
- problems and I get the SMTP greeting message. I type "HELO" on STDIN
- and I get a line in return. So far so good. The problem arises when I
- enter a command which gives a multi-line answer in return. I type
- "help" and I get only the first two lines of the help message in return.
- Only when I give an additional carriage-return from stdin do I get
- the remaining 4 lines of the "help" return message. The error is not
- reproducible, sometimes I get three or four lines before it gets stuck,
- and sometimes it only gets stuck the 2nd time I write "help".
-
- The print line of $rout shows that select reports that there is no data
- to be read on the socket. How can that be?
-
- The original client program shows no such behaviour. I immediately get
- the whole return message.
-
- My system is Perl 4.035 running on AIX 3.1.5 . I tried the script on
- an HP9000/820, HPUX 8.05 with Perl 4.019 and got the same behaviour.
-
- --
- ___ ___
- / o \ o \
- Dov Grobgeld ( o o ) o |
- The Weizmann Institute of Science, Israel \ o /o o /
- "Where the tree of wisdom carries oranges" | | | |
- _| |_ _| |_
-
-