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?
ThanksIn reply to write/syswrite return value differences by FreakyGreenLeaky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |