[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] sysread over socket



I need to read from a TCP-socket on a character per character basis. Using
sysread for this is very slow under MacPerl, taking minutes for one read.
Reading line by line using <$sock> works OK.

Is this a known issue with sysread?
Is there some workaround?

Some test code, adapted from the MacPerl book, follows.

----

#!perl -w

use IO::Socket;

my($sock, $line, $cr, $lf, $crlf);

$cr = "\015";
$lf = "\012";
$/ = $crlf = "$cr$lf";

$sock = IO::Socket::INET->new(
    PeerAddr => 'www',
    PeerPort => 'http(80)',
    Proto=> 'tcp'
) or die($@); 

print $sock "GET / HTTP/1.0$crlf$crlf";

if (0) {
    # this works OK
    while (defined($line = <$sock>)) {
        $line =~ s/$cr?$lf/$cr/g;
        print $line;
    }
} else {
    # this is very slow
    $line = "\n";
    while (defined($line)) {
        sysread($sock,$line,80);
        $line =~ s/$cr?$lf/$cr/g;
        print $line;
    }
}

__END__

---
Rene' Laterveer
laterveer@mac.com

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org