File: slowread

package info (click to toggle)
libwww-perl 5.36-1.1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 848 kB
  • ctags: 400
  • sloc: perl: 6,366; makefile: 51; sh: 6
file content (31 lines) | stat: -rwxr-xr-x 483 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/local/bin/perl

# You might post large amount of data to this script.  It will read
# it slowly.

{ local($!) = 1; print "Content-Type: text/plain\n\n"; }

$len = $ENV{CONTENT_LENGTH};

unless ($len) {
    system "env";
    exit;
}

$size = 20;  # chunk size

$content = '';
$bytes = 0;

sleep(1);
while ($len > 0) {
    $n = sysread(STDIN, $b, $size);
    last if $n <= 0;
    $len -= $n;
    $bytes += $n;
    $content .= $b;
    sleep(1);
}
print "$bytes bytes read\n";