in reply to Getting sysread to read the full packet

Why are you testing while ($bytes_read == 1024) and not simply while ($bytes_read), which would continue as long as at least one byte has been read...?

For some reason while ($bytes_read) never stops, it will just sit there forever. Everyone else seems to be able to use it fine, but I'm having trouble with it.

And I don't want to use LWP because I won't always necessarily be working with http, it's just what I'm using to test out the script for now

ikegami: The problem is that I don't necessarily know what protocols my server will be interacting with (could be http, ftp, torrents, anything really). What I'm doing is basically coding a socks5 proxy (of sorts). I have no control over whether the remote host is going to tell me how long the message is, or if it ends with a specific character or not

I've been looking at Michael Auerswald's perl socks5 implementation, and the relevant part of the code is this:

if ($client && (vec($eout, fileno($client), 1) || vec($rout, fileno +($client), 1))) { my $result = sysread($client, $tbuffer, 1024); if (!defined($result) || !$result) { return; } } if ($target && (vec($eout, fileno($target), 1) || vec($rout, fil +eno($target), 1))) { my $result = sysread($target, $cbuffer, 1024); if (!defined($result) || !$result) { return; } } while (my $len = length($tbuffer)) { my $res = syswrite($target, $tbuffer, $len); if ($res > 0) { $tbuffer = substr($tbuffer, $res); } else { retur +n; } } while (my $len = length($cbuffer)) { my $res = syswrite($client, $cbuffer, $len); if ($res > 0) { $cbuffer = substr($cbuffer, $res); } else { retur +n; } }
So he basically reads a set amount, sends it off, then goes back and reads again, and the delay which I need would be created by the sending of the new information to the next machine. This will work for what I need, but is it really all that reliable?