The way the script works as written now, and how I'd like to keep it, is it
always has 20 pings out. It pings 20 hosts and as each host responds, it
sends the next host ping out.  I don't want to just exit after I send the
last pings as there's potential to miss a bunch of the responses.  I want to
exit after either all responses or timeouts are complete.


"Dan McCormick" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Howdy,
>
> I'm not sure I understand what you're trying to accomplish.  Do you want
> to ping 20 clients, wait for all the responses, and then ping 20 more?
>
> In that case, I'd keep the for (1..20) loop and still populate an array
> or hash (say, %pinging) every time you ping something, and then pop it
> off or delete it when you get a response.  Then in client_got_pong, when
> %pinging is empty, yield back to client_start (you might rename it since
> you'll be calling it more than just at the start) and have it do 20
> more.
>
> Then, also in client_got_pong, you could exit if both @addresses and
> %pinging are empty.
>
> Dan
>
> On Fri, 2003-08-29 at 09:14, [EMAIL PROTECTED] wrote:
> > Hi,
> >
> > The problem with doing it in client_start is I can only do a few at a
time,
> > so by shifting the array in got_pong means I will never go beyond my
"limit"
> > of 20 at a time. Any ideas on how to accomplish this? Thanks...
> >
> >
> >
> > "Dan McCormick" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> > > Hi,
> > >
> > > You just need to call exit() at some point.  This will stop your
script
> > > and close your file.
> > >
> > > How and when to do that is another matter -- you may want to push the
> > > addresses you ping onto an array, and then pop them off in
> > > client_got_pong().  When the array is empty, exit.  Or do the same
thing
> > > with a hash -- add a key when pinging, delete it when you get the
> > > response.
> > >
> > > I think you may need to tweak the current logic you use with
> > > @addresses.  It looks like you shift the entire array in
client_start()
> > > but then try again in client_got_pong() -- by that time, however,
> > > @addresses is empty.
> > >
> > > You can also, ya know, just do this in client_start:
> > >
> > > foreach my $address (@addresses) {
> > > ...
> > > }
> > >
> > > and avoid the shift'ing and 'last unless defined' check altogether.
> > >
> > > Dan
> > >
> > > On Thu, 2003-08-28 at 15:28, [EMAIL PROTECTED] wrote:
> > > > I'm having a problem with the script below. It runs through all my
> > addresses
> > > > fine but when it gets to the last one in the array, the program just
> > hangs
> > > > there. My output file is empty so it hasn't been closed yet but if I
hit
> > > > CTRL-C, the file is closed and the script stops.  I assume I need to
> > somehow
> > > > say my array of addresses is done but how would I do that below?
Any
> > help
> > > > would be greatly appreciated.
> > > >
> > > > #!/usr/bin/perl -w
> > > >
> > > > BEGIN {
> > > >   die "POE::Component::Client::Ping requires root privilege\n"
> > > >   if $> and ( $^O ne 'VMS' );
> > > > }
> > > >
> > > > use POE;
> > > > use POE::Component::Client::Ping;
> > > >
> > > > # How many seconds to wait for ping responses.
> > > > sub PING_TIMEOUT () { 5 }
> > > >
> > > > my $outfile = "/logs/tpaping3.log";
> > > >
> > > > my @addresses = qw(1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4);
> > > >
> > > > POE::Component::Client::Ping->spawn
> > > >  ( Alias => 'pinger',
> > > >    Timeout => PING_TIMEOUT,
> > > >   OneReply => 1
> > > >  );
> > > >
> > > > POE::Session->create
> > > >  ( inline_states =>
> > > >    { _start => \&client_start,
> > > >      pong => \&client_got_pong,
> > > >    }
> > > >  );
> > > >
> > > > open (OUT_FH, "> $outfile");
> > > > print OUT_FH "Started ".scalar(localtime)."\n";
> > > > $poe_kernel->run();
> > > > close (OUT_FH);
> > > > exit;
> > > >
> > > > sub client_start {
> > > >   my ( $kernel, $session ) = @_[ KERNEL, SESSION ];
> > > >   print "Starting to ping hosts.\n";
> > > >   for (1..20) {
> > > >   my $address = shift @addresses;
> > > >   last unless defined $address;
> > > >     print "Pinging $address at ", scalar(localtime), "\n";
> > > >     $kernel->post( pinger => ping => pong => $address );
> > > >   }
> > > > }
> > > >
> > > > sub client_got_pong {
> > > >   my ( $kernel, $session ) = @_[ KERNEL, SESSION ];
> > > >   my $request_packet = $_[ARG0];
> > > >   my ( $request_address, $request_timeout, $request_time ) =
> > > > @{$request_packet};
> > > >   my $response_packet = $_[ARG1];
> > > >   my ( $response_address, $roundtrip_time, $reply_time ) =
> > > > @{$response_packet};
> > > >   if (! defined $response_address ) {
> > > >     print OUT_FH "Timed out waiting for responses from
> > $request_address.\n";
> > > >   }
> > > >  my $address = shift @addresses;
> > > >  if (defined $address) {
> > > >     print "Pinging $address at ".scalar(localtime)."\n";
> > > >    $kernel->post( pinger => ping => pong => $address );
> > > >  }
> > > > }
> > > >
> > > >
> > >
> >
> >
>


Reply via email to