in reply to chargen program is too slow / IO::Select socket handle outputting timing issue

This is not an answer to your question, but an improvement for your code. You are polling using select, while select's purpose is to eliminate polling. Replace the two calls to select (can_read and can_write) with a single call by replacing
@ready = $sel->can_read(0.0001); foreach my $socket (@ready) { ... } my @wready = $sel->can_write(0.0001); my $wsocket; foreach $wsocket (@wready) { ... }
with
my ($rready, $wready) = IO::Select->select($sel, $sel); foreach my $rsocket (@$rready) { ... } foreach my $wsocket (@$wready) { ... }

Replies are listed 'Best First'.
Re^2: chargen program is too slow / IO::Select socket handle outputting timing issue
by Jenda (Abbot) on Jul 14, 2006 at 13:58 UTC

    I think part of the problem is the slightly awkward syntax of the IO::Select->select($sel, $sel); and the fact that there is no example of this call in IO::Select's docs.

    I think it would make a lot of sense to have a method like this:

    my ($rready, $wready) = $sel->can([TIMEOUT]);
    or maybe even better
    my ($rready, $wready) = $sel->select([TIMEOUT]);
    Looking at the code in IO::Select.pm it seems to me the only change necessary would be on lines 181-184:
    - shift - if defined $_[0] && !ref($_[0]); - - my($r,$w,$e,$t) = @_; + my($r,$w,$e,$t); + if (defined $_[0] && !ref($_[0])) { # called as a static method + shift; + ($r,$w,$e,$t) = @_; + } elsif (@_ == 1 || @_ == 2 && !ref($_[1])) { # called as $sel->sele +ct() or $sel->select($timeout) + $r=$w=$e=$_[0]; + $t=$_[1]; + } else { # called as IO::Select::select(...) + ($r,$w,$e,$t) = @_; + }
    the question is whether anyone would notice that $sel->select() not longer means IO::Select->select($sel) but rather IO::Select->select($sel,$sel,$sel)

      The first two arguments of IO::Select->select are rarely the same, so I'm not sure that's a useful patch. In fact, the first two arguments should be different in your code. (Why are you waiting to write to the listen socket?) It should look more like:

      my $rsel = IO::Select->new(); my $wsel = IO::Select->new(); ... for (;;) { my ($rready, $wready) = IO::Select->select($rsel, $wsel); foreach my $rsocket (@$rready) { ... } foreach my $wsocket (@$wready) { ... } }