in reply to A Game Using TCP Sockets
Ahem, I took another look at the game, just ignore my previous rambling.
Discovered the following though:
This pattern can never match since the line is chomped?} elsif ($get =~ /MESSAGE ([^ ]+) (.*)\n$/) {
Why is Tk::repeat necessary, what happens if it's omitted?
Update: ah, I see it now. Why don't you modify get_line to return all lines available if wantarray?
Process could then do ... for my $get (get_line($server)) {} ...
Update. TCP.pm in the git, does it not read as follows:
sub get_line { my ($fh) = @_; warn "Getting from $fh\n"; my $line = read_from_buffer($fh); return $line if defined $line; if (sysread $fh, my $read, BUFF_SIZE) { warn "sysread $read"; $buff{$fh} .= $read; } $line = read_from_buffer($fh); warn "Got $line\n"; warn do { use Data::Dumper; Dumper $buff{$fh} }; return $line; }
I would simply write (untested):
sub get_line { my ($fh) = @_; warn "Getting from $fh\n"; my $line = read_from_buffer($fh); return $line if defined $line; sysread($fh, $_, BUFF_SIZE, length) for $buff{$fh}; return get_line($fh); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A Game Using TCP Sockets
by choroba (Cardinal) on Oct 14, 2013 at 20:09 UTC |