|< 1 2 >| | 16 Einträge, 2 Seiten |
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use strict;
use warnings;
use Storable;
package Parent;
sub run {
my $pipe = shift;
# der zu sendende String
my $string = 'Hello World!';
$string = Storable::nfreeze(\$string);
my $length = length($string);
# maximale Bytes die geschrieben werden sollen
my $maxbyt = 8;
my $offset = 0;
my $rest = $length;
my $sdsz = $length < $maxbyt ? $length : $maxbyt;
open my $fh, '>>', $pipe or die $!;
while (my $chunk = substr($string, $offset, $sdsz)) {
syswrite($fh, $chunk, $sdsz) == $sdsz or die;
$rest -= $maxbyt;
last unless $rest;
$offset += $maxbyt;
$sdsz = $rest if $rest < $maxbyt;
}
close $fh;
}
package Child;
sub run {
my $pipe = shift;
my $rdsz = 8;
my $string = ();
open my $fh, '<', $pipe or die $!;
while (my $byt = read($fh, my $chunk, $rdsz)) {
die unless $byt == $rdsz;
$string .= $chunk;
}
close $fh;
$string = Storable::thaw($string);
print "\n<$$string>\n";
}
package main;
use POSIX qw/mkfifo/;
my $pipe = int(rand(999999));
mkfifo($pipe, 0600) or die;
if (fork) {
Parent::run($pipe);
} else {
Child::run($pipe);
unlink($pipe);
}
QuoteMan kann nicht unendlich viel von einem Filehandle mittels sysread() oder syswrite() lesen bzw schreiben. Die empfohlene Größe kann mittels stat($fh)[11] herausbekommen werden, oder aber man setzt die Größe fix auf 16384 Bytes
Quote@morizt: unpack() oder pack() kann an dieser Stelle nicht gebraucht werden. Der 3 Parameter von syswrite() ist das, was ich brauche (OFFSET).
my @chunks = unpack '(a8)*', $string;
1
2
3
4
5
6
7
8
9
use IO::Socket::INET;
my $ipc = IO::Socket::INET->new(
LocalAddr => 'localhost',
Listen => 1,
Proto => 'tcp',
);
print "SIZE: ", (stat($ipc))[11], "\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/usr/bin/perl use strict; use warnings; use Data::Dumper qw(Dumper); my $vector = '123456789'; my $bits = unpack 'b*', $vector; my @bits = split //, $bits; my @bytes; while (@bits) { #my $byte = pack 'b8', join '', splice(@bits, 0, 8); # 1-byte (ascii) #my $byte = join '', splice(@bits, 0, 8); # 8-bit (bits) #my $byte = join '', splice(@bits, 0, 64); # 64-bit (bits) push @bytes, $byte; } print Dumper \@bytes;
1
2
3
4
5
6
7
8
9
10
11
$VAR1 = [
'10001100',
'01001100',
'11001100',
'00101100',
'10101100',
'01101100',
'11101100',
'00011100',
'10011100'
];
1
2
3
4
$VAR1 = [
'1000110001001100110011000010110010101100011011001110110000011100',
'10011100'
];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
my $buffer = 'x' x 100000000;
my $length = length($buffer);
my $offset = 0;
my $i = 0;
my $client = $ipc->accept();
warn "connect from: ", $client->peerhost, "\n";
warn "print $length bytes to client\n";
while ($length) {
# syswrite() schreibt immer nur 16k bei IO::Socket::SSL
my $written = syswrite($client, $buffer, $length, $offset);
die "System write error: $!\n" unless defined $written;
$length -= $written;
$offset += $written;
$i++;
}
warn "Iterations: $i\n";
|< 1 2 >| | 16 Einträge, 2 Seiten |