From f5cd1801bb1f1b0fb493df4452c541b94c6f253f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 29 Jun 2009 04:18:35 -0500 Subject: add comments and clean up the test a bit --- t/001-ping.t | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 ''; }); -- cgit v1.2.3-54-g00ecf