select misses pending data on socket 
Author Message
 select misses pending data on socket

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"              | |   | |
                                                       _| |_ _| |_



Sat, 18 Feb 1995 04:19:31 GMT  
 select misses pending data on socket
: The print line of $rout shows that select reports that there is no data
: to be read on the socket. How can that be?

Because there isn't any data to be read on the socket.  It's already been
read into the stdio buffers.

Don't use select with <>.  Use sysread() or recv() instead.

I suppose I really ought to make select work with stdio, but that can
get gory...

Larry



Sun, 19 Feb 1995 05:31:09 GMT  
 select misses pending data on socket

: : The print line of $rout shows that select reports that there is no data
: : to be read on the socket. How can that be?
:
: Because there isn't any data to be read on the socket.  It's already been
: read into the stdio buffers.
:
: Don't use select with <>.  Use sysread() or recv() instead.
:
: I suppose I really ought to make select work with stdio, but that can
: get gory...
:
: Larry

So many strange functions (select(), recv(), sysread(), fileno(), vec() )
to do the conceptually simple task of:

   "Check if there are apples under the tree, and if so, pick them,
    but don't hang around waiting for them to fall."

I'm used to it being very simple to implement well defined problems
like this in Perl (yes, I'm spoiled ;-), but this seems to be an exception.

It seems like the socket related functions, as opposed to the rest of
Perl, are just directly copied versions of the underlying Unix functions.
If socket support was provided in a different operating system, it
wouldn't map very well to these function names I believe.

Anyhow, I seem to have gotten to grips with these calls now and have
rewritten the client program from the Camel book without any forks.
Perhaps such a program should be included in the next version (generation)
of the (family of) Camel(s).

Just one more question about the sockets. How do I detect if the server
I'm connected to has closed down the connection?



--
                                                        ___   ___
                                                      /  o  \   o \
Dov Grobgeld                                         ( o  o  ) o   |
The Weizmann Institute of Science, Israel             \  o  /o  o /
"Where the tree of wisdom carries oranges"              | |   | |
                                                       _| |_ _| |_



Sun, 19 Feb 1995 20:29:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Checking STDIN and Sockets for pending data

2. Pre-pending data to a database or file.

3. Pre-pending data to a database or file.

4. "data rlimit exceeded" and missing returns

5. newbie "Data Missing" in netscape

6. missing socket.pm

7. Win32::EventLog - Message data missing ??

8. when writing to data file, last letter is missing

9. Data missing, rogue proccess.

10. missing value after unpack from socket

11. slow sub, array missing data

12. Error Msg 'Data Missing'

 

 
Powered by phpBB® Forum Software