home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5634 < prev    next >
Encoding:
Text File  |  1992-08-31  |  2.9 KB  |  89 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!wupost!darwin.sura.net!uvaarpa!mmdf
  3. From: Dov Grobgeld <dov@menora.weizmann.ac.il>
  4. Subject: select misses pending data on socket
  5. Message-ID: <1992Aug31.201931.14111@uvaarpa.Virginia.EDU>
  6. Sender: mmdf@uvaarpa.Virginia.EDU (Mail System)
  7. Reply-To: dov@menora.weizmann.ac.il
  8. Organization: The Internet
  9. Date: Mon, 31 Aug 1992 20:19:31 GMT
  10. Lines: 77
  11.  
  12. Fellow other Perl hackers,
  13.  
  14. I tried rewriting the client program of the Camel book to use select (with
  15. four arguments) instead of the fork. What I did was to replace the lines
  16.  
  17.     # Avoid deadlock by forking.
  18.  
  19.     if($child = fork) {
  20.         while (<STDIN>) {
  21.         print S;
  22.         }
  23.         sleep 3;
  24.         do dokill();
  25.     }
  26.     else {
  27.         while(<S>) {
  28.         print;
  29.         }
  30.     }
  31.  
  32. with the lines
  33.  
  34.     # This version uses the select call to find out if there is data pending
  35.  
  36.     $rin = $win = $ein = "\000";
  37.     vec($rin,fileno(S),1) = 1;
  38.     vec($ttyin,fileno(STDIN),1) = 1;
  39.     $rin |= $ttyin;
  40.  
  41.     print "fileno(S)=", fileno(S), "\n";
  42.     print "fileno(STDIN)=", fileno(STDIN), "\n";
  43.     print "rin=",unpack("b*", $rin),"\n";
  44.     $timeout=1;
  45.  
  46.     while (1) {
  47.         $nfound = select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
  48.         print "rout=",unpack("b*", $rout),"\n";
  49.  
  50.         if (vec($rout,fileno(S),1)) {
  51.             $_=<S>;
  52.             print;
  53.         }
  54.         if (vec($rout,fileno(STDIN),1)) {
  55.             $_=<STDIN>;
  56.             print S;
  57.         }
  58.     }
  59.  
  60. and the rest of the client (i.e. the opening socket part) being the same.
  61.  
  62. As a trial server I use my lokal SMTP deamon. I connect without any
  63. problems and I get the SMTP greeting message. I type "HELO" on STDIN
  64. and I get a line in return. So far so good. The problem arises when I
  65. enter a command which gives a multi-line answer in return. I type
  66. "help" and I get only the first two lines of the help message in return.
  67. Only when I give an additional carriage-return from stdin do I get
  68. the remaining 4 lines of the "help" return message. The error is not
  69. reproducible, sometimes I get three or four lines before it gets stuck,
  70. and sometimes it only gets stuck the 2nd time I write "help".
  71.  
  72. The print line of $rout shows that select reports that there is no data
  73. to be read on the socket. How can that be?
  74.  
  75. The original client program shows no such behaviour. I immediately get
  76. the whole return message.
  77.  
  78. My system is Perl 4.035 running on AIX 3.1.5 . I tried the script on
  79. an HP9000/820, HPUX 8.05 with Perl 4.019 and got the same behaviour.
  80.  
  81. --
  82.                                                         ___   ___
  83.                                                       /  o  \   o \
  84. Dov Grobgeld                                         ( o  o  ) o   |
  85. The Weizmann Institute of Science, Israel             \  o  /o  o /
  86. "Where the tree of wisdom carries oranges"              | |   | |
  87.                                                        _| |_ _| |_
  88.                                        
  89.