How to tell if download is cancelled

How to tell if download is cancelled

am 26.11.2008 16:05:34 von Mark Knoop

Hi

I have a CGI script running on IIS 6.0 which handles downloads by reading in
the file and printing it to STDOUT.

Part of the reason for doing this was to keep track of the bytes actually
downloaded.

This works fine but I have found that under usual circumstances the CGI
script will continue to send the whole file even if the download is
cancelled.

If I put a 1 second sleep in between prints then it will stop before the
whole file is sent but it still takes quite a while to stop.

Ideally I would like the CGI script to die as soon as the download is
cancelled.

I have tried using an IO::Socket connected to \*STDOUT and checking
peername() but that just hung even when the browser was connected.

It also appears there is some IIS isClientConnected property but I am not
sure how to get at that from Perl without using Server-Side PerlScript and I
know nothing about that.

Any ideas as to the best approach?

Thanks
Mark

Example Code follows:

#########################

use strict;
use bytes;
use CGI qw/:standard/;
use CGI::Carp 'fatalsToBrowser';
use Log::Log4perl;
#use IO::Socket;
$|=1;

Log::Log4perl->init("D:\\conf\\log4perl.conf");
my $log = Log::Log4perl->get_logger("testbyte");

my $testfile = 'D:\path\to\content\Some_Content.3gp';

#my $stdout = IO::Socket->new;
#if ($stdout->fdopen(fileno(STDOUT),"w")) { $log->info("Connected IO::Socket
to STDOUT : " . $stdout->peername() ); }

open(FILE, "< $testfile") or $log->logdie ("Couldn't open file $testfile");
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat(FILE);
my $tmpfile = 'Some_Content.3gp';
print "Content-type: video/3gpp\n";
print "Content-length: $size\n";
print "Content-disposition: attachment;filename=$tmpfile\n\n";
binmode(FILE);
my $bytes_delivered = 0;

while() {
$bytes_delivered += length $_;
$log->info("Bytes delivered = " . $bytes_delivered);
#if ( $stdout->peername() ) { $log->info("Still connected");
$stdout->print($_); } else { $log->info("Not connected");}
print;
#sleep (1);
}

close FILE;

exit;

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: How to tell if download is cancelled

am 26.11.2008 16:32:24 von Angelos Karageorgiou

This is a multi-part message in MIME format.
--------------010200070508070703080602
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Mark Knoop wrote:
> Hi
>
> I have a CGI script running on IIS 6.0 which handles downloads by reading in
> the file and printing it to STDOUT.
>


print is supposed to return an error if it cannot complete, check that!

--------------010200070508070703080602
Content-Type: text/x-vcard; charset=utf-8;
name="angelos.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="angelos.vcf"

begin:vcard
fn:Angelos Karageorgiou
n:Karageorgiou;Angelos
org:Vivodi Telecommunications S.A.
email;internet:angelos@unix.gr
title:Technology Manager
tel;work:+30 211 7503 893
tel;fax:+30 211 7503 701
tel;cell:+30 6949120773
note;quoted-printable: =
=
Linkedin Profile =
=
http://www.linkedin.com/in/unixgr =
=
=
=
Personal Web Site =
http://www.unix.gr =
=
=
Blog Site =
http://angelos-proverbs.blogspot.com
x-mozilla-html:FALSE
url:http://www.linkedin.com/in/unixgr
version:2.1
end:vcard


--------------010200070508070703080602
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--------------010200070508070703080602--

Re: How to tell if download is cancelled

am 26.11.2008 16:54:27 von Mark Knoop

> Mark Knoop wrote:
>> Hi
>>
>> I have a CGI script running on IIS 6.0 which handles downloads by reading
>> in
>> the file and printing it to STDOUT.
>>
>
>
> print is supposed to return an error if it cannot complete, check that!
>

I tried this...

if (print) {} else {$log->info("Print failed"); last;}

but it still carries on printing happily until the file is all sent. Is this
what you meant?

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs