Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Where's my CGI hook going?

Reply
Thread Tools

Where's my CGI hook going?

 
 
Carsten Broschek
Guest
Posts: n/a
 
      05-10-2006
Hi,

After looking at
http://search.cpan.org/~lgoddard/CGI...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



 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      05-10-2006
Carsten Broschek <(E-Mail Removed)> wrote:
> Hi,
>
> After looking at
> http://search.cpan.org/~lgoddard/CGI...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
 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      05-10-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Carsten Broschek <(E-Mail Removed)> wrote:
> > Hi,
> >
> > After looking at
> > http://search.cpan.org/~lgoddard/CGI...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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
(CGI-Target)Could not connect to CGI-Proxy John Smith Java 0 05-15-2006 09:21 PM
CGI module callback / upload hook Dominik Blystak Python 1 01-20-2006 07:11 AM
Python CGI - Accepting Input, Invoking Another Process, Ending CGI LarsenMTL Python 4 11-04-2004 05:59 PM
Calling cgi from cgi thru 'system' function. Different behaviour on browser v/s cmd line Shailan Perl 2 12-15-2003 04:26 PM
Re: CGI Perl "use CGI" statement fail Jürgen Exner Perl 0 07-31-2003 02:00 PM



Advertisments