Robert Klemme
10/8/2007 7:13:00 AM
2007/10/6, kazaam <kazaam@oleco.net>:
> Well I'm trying to "translate" a perl program to ruby and everything worked fine until the near end where I'm now. There we have this perl code:
>
> my $slct = IO::Select->new($server);
> while($slct->can_read()) {
> my $nbytes = read $server, $response, 2**16;
> last if !$nbytes;
> $client->send($response);
> }
>
> $server is a socket-handle exactly as $client. But now I'm stuck. Is there any equivalent to perls can_read ? Than this line here:
> my $nbytes = read $server, $response, 2**16;
> last if !$nbytes;
>
> Means something like read from server 2^16 bytes save to nbytes and append to response or?
As long as you are only copying between one pair of descriptors, you
do not need #select. You can simply do
while ( buffer = io_in.read(2**16) )
io_out.write(buffer)
end
If you just have few pairs, the code is easier with the above piece
put in a thread per pair.
Only if you are doing heavy copying (say, more than 10 pairs or so)
you should consider using #select. My 0.02EUR...
Kind regards
robert