From bd3e61970c6ef3b85b49eb44a9ac653d1e4c86de Mon Sep 17 00:00:00 2001 From: Gabor Adam Toth Date: Fri, 29 Apr 2011 16:03:17 +0200 Subject: [PATCH] splittest --- test/Makefile | 3 +++ test/splittest.pl | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 test/splittest.pl diff --git a/test/Makefile b/test/Makefile index abb7d0a..b1b58e3 100644 --- a/test/Makefile +++ b/test/Makefile @@ -24,6 +24,9 @@ nettest: nettesterr: for f in packets/error-*; do echo ">> $$f"; cat $$f | nc localhost $(PORT); done +splittest: + for f in packets/full-*; do echo ">> $$f"; ./splittest.pl $$f $(PORT) | diff -u $$f -; done + nettestp1: (for f in packets/part-1-p*; do cat $$f; done) | nc localhost $(PORT) | diff -u packets/full-1 - diff --git a/test/splittest.pl b/test/splittest.pl new file mode 100755 index 0000000..9794390 --- /dev/null +++ b/test/splittest.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use IO::Socket; +$| = 1; + +print "Usage: splittest.pl [ [ [-v]]]\n" and exit unless @ARGV; +my $port = $ARGV[1] || 4440; +my $length = int($ARGV[2] || 1); $length = 1 if $length < 1; +my $verbose = $ARGV[3]; + +open FILE, '<', $ARGV[0] or die "$ARGV[0]: $!\n"; +my $file = ''; $file .= $_ while ; +close FILE; + +my $s = IO::Socket::INET->new(Proto => "tcp", PeerAddr => "localhost", PeerPort => $port) or die "localhost:$port: $!\n"; +$s->autoflush(1); + +my $c = 0; +while ($c < length $file) { + my $chunk = substr $file, $c, $length; + print "[$chunk]" if $verbose; + print $s $chunk; + $c += $length; +} + +print while <$s>; +close $s;