1 eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
2 & eval 'exec perl -w -S $0 $argv:q'
5 # ******************************************************************
6 # Author: Chris Cleeland
8 # ******************************************************************
17 use POSIX
qw(strtoul);
22 my($num, $unparsed) = strtoul
($str);
23 if (($str eq '') || ($unparsed != 0) || $!) {
30 my $corba_server_addr = "127.0.0.1";
31 my $corba_server_port = 12345;
32 my $progress_interval = 10;
34 my $interactive = undef;
35 my $datastreamfile = 'datastream.dat';
36 my $dataxmitlayoutfile = undef;
39 my %options = ('host|h=s' => \
$corba_server_addr,
40 'port|p=s' => \
$corba_server_port,
41 'interval|i=i' => \
$progress_interval,
42 'verbose|verbosity|v+' => \
$verbosity,
43 'interactive' => \
$interactive,
44 'stream|s=s' => \
$datastreamfile,
45 'layout|l=s' => \
$dataxmitlayoutfile,
46 'delay|d=f' => \
$delay,
48 my $result = GetOptions
(%options);
51 my($str) = 'Usage: ' . basename
($0);
52 my($initial) = length($str);
53 my($length) = $initial;
58 foreach my $key (sort keys %options) {
59 my($opt, $type) = split(/[|=]/, $key);
60 my($str) = " [--$opt" . (defined $type ?
" <$opt>" : "") . "]";
61 my($len) = length($str);
62 if ($length + $len > $maxLine) {
63 print "\n" . (" " x
$initial);
73 croak
"Must supply a data file using --stream and a layout file using --layout"
74 unless defined $datastreamfile && defined $dataxmitlayoutfile;
76 my $sock = IO
::Socket
::INET
->new(PeerAddr
=> $corba_server_addr,
77 PeerPort
=> $corba_server_port,
79 or croak
"Unable to establish connection to $corba_server_addr:$corba_server_port: $!\n";
82 # Infer a name for the layout file
84 if (! defined $dataxmitlayoutfile) {
85 $dataxmitlayoutfile = $datastreamfile;
86 $dataxmitlayoutfile =~ s/\.dat$/\.layout/;
89 # Now we just start reading from <> and writing to the socket We
90 # currently assume all are oneways, so we don't worry about reading
93 my $stream = new IO
::File
$datastreamfile, "r"
94 or croak
"Unable to open $datastreamfile for reading: $!";
95 my $layout = new IO
::File
$dataxmitlayoutfile, "r"
96 or croak
"Unable to open $dataxmitlayoutfile for reading: $!";
99 print "Sending...(1 dot every $progress_interval hunks)\n";
100 print "Hit <RETURN> key to send a packet\n" if defined $interactive;
105 # Determine the size of the hunk we have to read/send
107 $_ = $layout->getline;
110 next if ($_ =~ /^\s*$/);
112 my $requested_hunksize = getnum
($_);
113 my $l = $layout->input_line_number;
118 # Read in the hunk size we want
120 $numread = $stream->sysread($hunk, $requested_hunksize);
121 if (! defined $numread) {
122 carp
"\nHunk $l: Error reading from stream: $!";
125 elsif ($numread != $requested_hunksize) {
126 carp
"\nHunk $l: short read (expected $requested_hunksize, got $numread); going on.";
129 print "Hunk $l: length ", length($hunk), "\n" if ($verbosity >= 1);
130 if (defined $interactive) {
134 select(undef, undef, undef, $delay);
137 my $ret = $sock->send($hunk, 0);
138 if ($ret != length($hunk)) {
139 carp
"\nHunk $l: problem sending hunk $.: $!\n";
143 print "." if ($. % $progress_interval == 0);
144 } until $numread == 0 || $layout->eof;
147 ## Sleep 1 second to allow the socket on Windows to get flushed
148 ## before it's destroyed and this process exits.