FreakyGreenLeaky has asked for the wisdom of the Perl Monks concerning the following question:
Hopefully someone can shed some candle light on the following.
$sock->syswrite() returns number of bytes sent. $sock->write() always returns 1, not number of bytes sent. This seems at odds with the C write() function which it ostensibly is mirroring. The following bit of code demonstrates that:# Server: use IO::Socket; my $sock = new IO::Socket::INET( LocalPort => '10000', Proto => 'tcp', Listen => 1, Reuse => 1, ) or die; while (1) { my $new_sock = $sock->accept(); while (<$new_sock>) { print $_; } } close $sock; # client: use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => '10.0.0.1', PeerPort => '10000', Proto => 'tcp', ) or die; #my $ret = $sock->write("$ARGV[0]\n", length("$ARGV[0]\n")); my $ret = $sock->syswrite("$ARGV[0]\n", length("$ARGV[0]\n")); print "wrote $ret bytes\n"; close $sock;
I've got some code which depends on the return value of syswrite(), but we need to use write() because of chunking, which does not return the number of bytes.
Any idea why on earth write() isn't returning the number of bytes written?
Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: write/syswrite return value differences
by dave_the_m (Monsignor) on Nov 24, 2011 at 10:15 UTC | |
|
Re: write/syswrite return value differences
by ikegami (Patriarch) on Nov 24, 2011 at 17:50 UTC | |
by Eliya (Vicar) on Nov 24, 2011 at 18:07 UTC | |
by ikegami (Patriarch) on Nov 24, 2011 at 18:29 UTC | |
by FreakyGreenLeaky (Sexton) on Nov 29, 2011 at 13:39 UTC | |
by ikegami (Patriarch) on Nov 29, 2011 at 14:33 UTC |