Where's my CGI hook going?

Discussion in 'Perl Misc' started by Carsten Broschek, May 10, 2006.

  1. Hi,

    After looking at
    http://search.cpan.org/~lgoddard/CGI-ProgressBar-0.04/ProgressBar.pm
    I tried to show the upload-process from a multipart-request via
    callback: my $cgi = CGI->new(\&bar_hook, $data);

    For me it seems, that the processes does not end, as well a Testing of
    the ProgressBar.pm shows endless processing. Are there know problems
    with the callback-feature or is my code stupid?

    [...]
    my $data;
    my $hook_called;
    my $cgi = CGI->new(\&bar_hook, $data);

    [...]
    sub bar_hook
    {
    my ($filename, $buffer, $bytes, $data) = @_;
    if (not $hook_called)
    {
    print header,
    start_html( -title=>'Simple Upload-hook Example'),
    h1('Uploading'),
    p( "Have to read <var>$filename</var> Size
    <var>$ENV{CONTENT_LENGTH}</var>"),
    hr;
    $hook_called = 1;
    }
    else
    {
    print "Content Length [$ENV{CONTENT_LENGTH}] <br>bytes_read
    [$bytes] sum [$hook_called]...";
    }
    $hook_called += $bytes;
    }

    Response shows:
    Uploading

    Have to read ascotel_01.jpg Size 95127
    Content Length [95127]
    bytes_read [4155] sum [4039]...Content Length [95127]
    bytes_read [4155] sum [8194]...Content Length [95127]
    bytes_read [4155] sum [12349]...Content Length [95127]
    bytes_read [4155] sum [16504]...Content Length [95127]
    bytes_read [4155] sum [20659]...Content Length [95127]
    bytes_read [4155] sum [24814]...Content Length [95127]
    bytes_read [4155] sum [28969]...Content Length [95127]
    bytes_read [4155] sum [33124]...Content Length [95127]
    bytes_read [4155] sum [37279]...Content Length [95127]
    bytes_read [4155] sum [41434]...Content Length [95127]
    [... lot of more lines]

    After some seconds logfile gets:
    [Wed May 10 18:27:53 2006] [error] [client 192.168.1.3] CGI.pm: Server
    closed socket during multipart read (client aborted?)., referer:
    http://192.168.1.3:12080/cgi-bin/hookme.cgi


    Thanks for hints in advance,

    CARSTEN
    Carsten Broschek, May 10, 2006
    #1
    1. Advertising

  2. Carsten Broschek

    Guest

    Carsten Broschek <> wrote:
    > Hi,
    >
    > After looking at
    > http://search.cpan.org/~lgoddard/CGI-ProgressBar-0.04/ProgressBar.pm
    > I tried to show the upload-process from a multipart-request via
    > callback: my $cgi = CGI->new(\&bar_hook, $data);
    >
    > For me it seems, that the processes does not end, as well a Testing of
    > the ProgressBar.pm shows endless processing. Are there know problems
    > with the callback-feature or is my code stupid?


    I'm guessing neither. What happens if you take out the callback?
    Probably you will get the same error at the end, just without all
    the intermediate messages printed out by the callback.

    From CGI.pm:


    # An apparent bug in the Apache server causes the read()
    # to return zero bytes repeatedly without blocking if the
    # remote user aborts during a file transfer. I don't know how
    # they manage this, but the workaround is to abort if we get
    # more than SPIN_LOOP_MAX consecutive zero reads.
    if ($bytesRead == 0) {
    die "CGI.pm: Server closed socket during multipart read (client
    aborted?).\n"
    if ($self->{ZERO_LOOP_COUNTER}++ >= $SPIN_LOOP_MAX);
    } else {
    $self->{ZERO_LOOP_COUNTER}=0;
    }


    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , May 10, 2006
    #2
    1. Advertising

  3. Carsten Broschek

    Guest

    wrote:
    > Carsten Broschek <> wrote:
    > > Hi,
    > >
    > > After looking at
    > > http://search.cpan.org/~lgoddard/CGI-ProgressBar-0.04/ProgressBar.pm
    > > I tried to show the upload-process from a multipart-request via
    > > callback: my $cgi = CGI->new(\&bar_hook, $data);
    > >
    > > For me it seems, that the processes does not end, as well a Testing of
    > > the ProgressBar.pm shows endless processing. Are there know problems
    > > with the callback-feature or is my code stupid?

    >
    > I'm guessing neither. What happens if you take out the callback?
    > Probably you will get the same error at the end, just without all
    > the intermediate messages printed out by the callback.


    OK, I guessed wrong.

    What is happening is that the browser (or the http server on behalf of the
    browser, I'm not sure which) refuses to read the response from the CGI
    until the entire request has been delivered. So once upload_hook has
    printed out one entire buffer worth of information, the print in the hook
    blocks waiting for the server/browser to start reading the response, while
    the server/browser is blocked waiting for the CGI script to finish reading
    the request. Bang, deadlock. This goes until the browser/server times
    out. Once the timeout happens, then the code I posted previously kicks in,
    and you get 2000 messages with the same size before CGI.pm gives up and
    dies.

    The moral of the story is that I don't think you can't do the progress bar
    thing without having more than one http connection open. Sorry for
    misleading you last about that last week.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , May 10, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Pifer via .NET 247

    Hook JScript Client Events to Server Controls

    David Pifer via .NET 247, May 2, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,774
    David Jessee
    May 2, 2004
  2. djc
    Replies:
    7
    Views:
    458
  3. =?Utf-8?B?d2FsdGVy?=

    How to hook httpmodule and page event together?

    =?Utf-8?B?d2FsdGVy?=, Mar 30, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    462
    =?Utf-8?B?d2FsdGVy?=
    Mar 31, 2006
  4. Thomas Weidenfeller

    Re: the hook problem

    Thomas Weidenfeller, Aug 12, 2003, in forum: Java
    Replies:
    2
    Views:
    310
    Roedy Green
    Aug 12, 2003
  5. Dominik Blystak

    CGI module callback / upload hook

    Dominik Blystak, Jan 18, 2006, in forum: Python
    Replies:
    1
    Views:
    709
    Tim Roberts
    Jan 20, 2006
Loading...

Share This Page