Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Re: Re: Re: Re: using CGI on HTTP::Request from HTTP::Daemon

by tachyon (Chancellor)
on May 26, 2004 at 03:38 UTC ( [id://356448]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: using CGI on HTTP::Request from HTTP::Daemon
in thread using CGI on HTTP::Request from HTTP::Daemon

The problem per se is that there is no eof reaching CGI::Simple. As a result it blocks (hangs) on the read here:

sub _read_data { read ( STDIN, my $buffer, 16 ); # nb changed buf size for testing return $buffer; }

In essence the difference between the way CGI.pm reads data and what I did in this module is that CGI stops when it gets what it expects, thus it is not eof dependent.

It is actually quite interesting what happens. If you increase the buffer size on the read so it can slurp the data in one pass it works fine. It is only if you read bytewise that read (or sysread) fails to recognise the end of the data stream.

cheers

tachyon

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: using CGI on HTTP::Request from HTTP::Daemon
by PodMaster (Abbot) on May 26, 2004 at 03:53 UTC
    So are you going to change the way that is handled in the next release? I suggest you do (you know, keep alive and whatnot).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

      Actually I am not sure I know how to fix it! Have a look at this test code (it hangs). This is a minimal case that simply shows how read() will block on reads from $conn.

      #!/usr/bin/perl -w use strict; use HTTP::Daemon; use HTTP::Status; my $d = HTTP::Daemon->new( Reuse => 1, LocalPort => 80, ) or die "No daemon: $!\n"; warn "Ready to go!\n"; while (my $conn = $d->accept()) { serve_everything( $conn, $conn->get_request( 1 )); } sub serve_everything { my ($conn, $req) = @_; my $length = $req->content_length || 0; local *main::STDIN = $conn; my $data = ''; my $buf; if ( $length ) { print "Expecting $length bytes\n"; while( read( STDIN, $buf, 16 ) ) { print "Got: $buf\n"; $data .= $buf; } } else { $data = "Nothing Posted\n"; } my $HTML = qq!<pre>$data</pre> <hr> <FORM METHOD="POST" ACTION="http://localhost" ENCTYPE="mu +ltipart/form-data"> <INPUT TYPE="file" NAME="upload_file1" SIZE="42"> <INPUT TYPE="submit"> </FORM> !; $conn->send_response( HTTP::Response->new( 200, 'OK', HTTP::Headers->new( Content_Type => "text/html" ) , $HTML ) ); $conn->print( 'nope', $@ ) if $@; }

      cheers

      tachyon

        *boing* Unless I'm missing something, you solve it by adopting the CGI strategy, that is, you read until you've read CONTENT_LENGTH bytes (if its not greater than POST_MAX).

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://356448]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2024-03-28 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found