diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-06-29 04:18:35 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-06-29 04:18:35 -0500 |
commit | f5cd1801bb1f1b0fb493df4452c541b94c6f253f (patch) | |
tree | b560252dc3d870dc7d73ef5f46668b5cd9f37aca | |
parent | 8d1d2cb4748adb7f18ffdadfe1f86395c2835746 (diff) | |
download | io-socket-telnet-halfduplex-f5cd1801bb1f1b0fb493df4452c541b94c6f253f.tar.gz io-socket-telnet-halfduplex-f5cd1801bb1f1b0fb493df4452c541b94c6f253f.zip |
add comments and clean up the test a bit
-rw-r--r-- | t/001-ping.t | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/t/001-ping.t b/t/001-ping.t index b9e2db6..de4db7d 100644 --- a/t/001-ping.t +++ b/t/001-ping.t @@ -5,6 +5,12 @@ use Test::More tests => 4; use IO::Socket::Telnet::HalfDuplex; +# this simulates ideal conditions - the server doesn't respond with a pong +# until all data it wanted to respond to the actual request with has been +# sent. real situations aren't always this nice, since typically the telnet +# layer is separate from the layer that's deciding how to respond to the +# received data, but this is a decent approximation. + pipe my $read, my $write; my $IAC = chr(255); @@ -26,6 +32,7 @@ unless ($pid = fork) { my $buf; my $tested = 0; while (defined $connection->recv($buf, 4096)) { + # read of 0 bytes means that the socket is closed last unless defined $buf && length $buf; my $gotpong = ($buf =~ s/$IAC$DO$PONG//); if (!$tested) { @@ -42,6 +49,7 @@ unless ($pid = fork) { close $write; exit; } +# give the server time to set up sleep 1; my $pong = 0; my $client = IO::Socket::Telnet::HalfDuplex->new( @@ -50,7 +58,7 @@ my $client = IO::Socket::Telnet::HalfDuplex->new( ); $client->telnet_simple_callback(sub { my $self = shift; - my $msg = shift; + my ($msg) = @_; $pong++ if $msg =~ /99$/; return ''; }); |