473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

mod_perl2 sendfile issue.

4
Hi all,
I am having issues with the sendfile command in mod_per2. I am getting the following errors in the error_log:

[Thu Mar 24 11:38:50 2011] [info] [client 10.199.122.122] (32)Broken pipe: core_output_filter: writing data to the network
[Thu Mar 24 11:38:50 2011] [error] [client 10.199.122.122] Apache2::RequestIO::sendfile: (130) Software caused connection abort.


Here is code for my perl module:

Expand|Select|Wrap|Line Numbers
  1. package Ranges;
  2. use strict;
  3. use warnings;
  4.  
  5.  
  6. use Apache2::Const qw(OK NOT_FOUND HTTP_PARTIAL_CONTENT);
  7. use File::Basename;
  8. use Data::Dumper;
  9.  
  10. sub send_pkgitem {
  11.   my ($r) = @_;
  12.  
  13.   my $fh = "/tmp/test.pdf"
  14.  
  15.   my $attach_name = basename($fh);
  16.   my $content_size = -s $fh;
  17.  
  18.   my $start_range = 0;
  19.   my $end_range = $content_size - 1;
  20.   my $range = "$start_range"."-"."$end_range".'/'."$content_size"; 
  21.  
  22.  
  23.   $r->headers_out->set('Accept-Ranges' => 'bytes');  #causes a server 500 response error when set..
  24.   $r->set_content_length(-s $pkgitem->{real_path});
  25.   $r->headers_out->set('Content-Range' => "$range");
  26.   $r->headers_out->set('Content-Disposition' => "inline; filename=\"$attach_name\"");
  27.  
  28.   $r->set_last_modified;
  29.   $r->content_type($pkgitem->{mimetype});
  30.   warn "HEADERS_OUT Dumper:\n";
  31.   warn Dumper($r->headers_out);
  32.  
  33.  
  34.   unless ((my $status = $r->meets_conditions) == OK) {
  35.     return $status;
  36.   }
  37.  
  38.  
  39.   return OK if $r->header_only;
  40.  
  41.   warn "HEADERS_IN dumper:\n";
  42.   warn Dumper($r->headers_in);
  43.  
  44.  
  45.   warn "range request = $range\n";
  46.   warn "content_size = $content_size, end_range = $end_range\n";
  47.  
  48.   my $bytes_total = $end_range;
  49.   my $buff_size = 65536;
  50.   my $buff_len = $buff_size; 
  51.   warn "bytes_total = $bytes_total\n";
  52.  
  53.   if ($content_size < $buff_len)
  54.   { $r->sendfile($fh); }
  55.   else #process range request
  56.   {
  57.     warn "RANGE BLOCK:\n";
  58.     my $offset = 0;
  59.     my $totalbytes_sent = 0;
  60.     while ($totalbytes_sent <= $end_range)
  61.     {
  62.        warn "sendfile -> $fh,$offset,$buff_len\n";
  63.        $r->sendfile($fh,$offset,$buff_len);
  64.        last if ($bytes_total <= 0);
  65.        $bytes_total -= $buff_len;
  66.        $buff_len = $bytes_total,$bytes_total = 0 if $buff_len > $bytes_total;
  67.        $totalbytes_sent += $buff_len;
  68.        if ($bytes_total == 0)
  69.        { $offset += $buff_size; }
  70.        else
  71.        { $offset = $totalbytes_sent; }
  72.        warn "bytes_total = $bytes_total, totalbytes_sent = $totalbytes_sent\n";
  73.     }
  74.   }
  75.  
  76.  
  77.   return OK;
  78. }
  79.  
  80. 1;
  81.  
***** OUTPUT FROM error_log file *****
content_type = application/pdf
HEADERS_OUT Dumper:
$VAR1 = bless( {
'Accept-Ranges' => 'bytes',
'Content-Length' => '751711',
'Content-Range' => '0-751710/751711',
'Content-Disposition' => 'inline; filename="test.pdf"',
'Last-Modified' => 'Sun, 25 Jan 2009 19:56:38 GMT'
}, 'APR::Table' );

HEADERS_IN dumper:
$VAR1 = bless( {
'Host' => '10.199.122.122',
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' => 'en-us,en;q=0.5',
'Accept-Encoding' => 'gzip,deflate',
'Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive' => '115',
'Connection' => 'keep-alive',
'Referer' => ''
}, 'APR::Table' );
range request = 0-751710/751711
content_size = 751711, end_range = 751710
bytes_total = 751710
sendfile -> /tmp/test.pdf,0,65536
bytes_total = 686174, totalbytes_sent = 65536
sendfile -> /tmp/test.pdf,65536,65536
[Thu Mar 24 11:38:50 2011] [info] [client 10.199.122.122] (32)Broken pipe: core_output_filter: writing data to the network
[Thu Mar 24 11:38:50 2011] [error] [client 10.199.122.122] Apache2::RequestIO::sendfile: (130) Software caused connection abort.

content_type = application/pdf
HEADERS_OUT Dumper:
$VAR1 = bless( {
'Accept-Ranges' => 'bytes',
'Content-Length' => '751711',
'Content-Range' => '0-751710/751711',
'Content-Disposition' => 'inline; filename="test.pdf"',
'Last-Modified' => 'Sun, 25 Jan 2009 19:56:38 GMT'
}, 'APR::Table' );
HEADERS_IN dumper:
$VAR1 = bless( {
'Host' => '10.199.122.122',
'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.14) Gecko/20110218 Firefox/3.6.14',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' => 'en-us,en;q=0.5',
'Accept-Encoding' => 'gzip,deflate',
'Accept-Charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive' => '115',
'Connection' => 'keep-alive',
'Range' => 'bytes=1-1,750984-751710'
}, 'APR::Table' );
range request = 0-751710/751711
content_size = 751711, end_range = 751710
bytes_total = 751710
sendfile -> /tmp/test.pdf,0,65536
bytes_total = 686174, totalbytes_sent = 65536
sendfile -> /tmp/test.pdf,65536,65536
bytes_total = 620638, totalbytes_sent = 131072
sendfile -> /tmp/test.pdf,131072,65536
bytes_total = 555102, totalbytes_sent = 196608
sendfile -> /tmp/test.pdf,196608,65536
bytes_total = 489566, totalbytes_sent = 262144
sendfile -> /tmp/test.pdf,262144,65536
bytes_total = 424030, totalbytes_sent = 327680
sendfile -> /tmp/test.pdf,327680,65536
bytes_total = 358494, totalbytes_sent = 393216
sendfile -> /tmp/test.pdf,393216,65536
bytes_total = 292958, totalbytes_sent = 458752
sendfile -> /tmp/test.pdf,458752,65536
bytes_total = 227422, totalbytes_sent = 524288
sendfile -> /tmp/test.pdf,524288,65536
bytes_total = 161886, totalbytes_sent = 589824
sendfile -> /tmp/test.pdf,589824,65536
bytes_total = 96350, totalbytes_sent = 655360
sendfile -> /tmp/test.pdf,655360,65536
bytes_total = 0, totalbytes_sent = 686174
sendfile -> /tmp/test.pdf,720896,30814



In the access_log, the 1st attempt returned a 500 response then the next response was a 200 response.
I am able to view the PDF file just fine but I have to wait until it's fully downloaded before I can view it. My objective is to return a
206 response rather than a 200 response. I am not sure whether it's a mistake in the headers or the way I am calling sendfile.

Thanks for any replies!!
Mar 25 '11 #1
1 2323
numberwhun
3,509 Expert Mod 2GB
Thank you for posting, @gcwg. Sorry it is taking so long to get you an answer, but hopefully one of our Experts who is knowledgeable in your issue will provide help shortly.

Regards,

Jeff
Mar 31 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dennis Gavrilov | last post by:
Hi, All! I have two questions: strategic and technical. Technical one first: I need to share an array of objects (implemented as hashes, having references to other objects and hashes, sharing...
7
by: George Hester | last post by:
Please take a look at this google artcle: http://groups.google.com/groups?hl=en&lr=&frame=right&th=55d6f4b50f5f9382&seekm=411f370d%241%40olaf.komtel.net#link9 The op was having trouble with...
2
by: Anthony Cuttitta Jr. | last post by:
We have an application that outputs several different graphs from data downloaded from our AS400. The application has worked without (this) issue for several months now, but just recently, the...
1
by: djc | last post by:
the system.net.sockets.socket class has the 'sendfile' method. What do you do on the other end to 'receive' the file? I know the regular socket.receive will receive the data into a buffer (a byte...
0
by: Simon Says | last post by:
Hi all, Can anyone advice on how to use the SendFile function? If I have a connection-oriented socket, I'll do a sck.SendFile("C:\test.txt") to send out the file, but what should I do on...
1
by: Aerodyne | last post by:
Hi all, I'm using .NET 2.0 but unfortunately there's a windows service that needs to be implemented in .NET 1.1 ... so I need to send a file to a server, what's the similar method of doing so...
0
by: iwdu15 | last post by:
hi, using sockets, how can i receive a file? i see a SendFile method, but no receivefile? ive done simple text sending and bytes, but that requires knowing an array size...so how can i receive a...
0
by: iwdu15 | last post by:
hi, ive done work with sockets and such before, so its nothing new. thought id try the Socket.SendFile() method instead of the manual way. however, there is no Socket.ReceiveFile() method. How do...
0
by: Matt | last post by:
Hi all, Probably a silly mistake, but I seem to be losing 24 bytes every time I attempt to send a file using Socket.SendFile(). Here is my code: Here is the server method: void...
13
by: SAL | last post by:
Hello, I'm trying to include a popup in the ItemTemplate of a gridview row. The ItemTemplate for the field contains a textbox and when the user clicks in the textbox I want a popup panel to show...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.