Skip to content

Commit

Permalink
Pass the 'host' back in the response event
Browse files Browse the repository at this point in the history
  • Loading branch information
bingos committed Aug 4, 2011
1 parent e39882f commit 215c397
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/POE/Component/Client/NTP.pm
Expand Up @@ -130,7 +130,7 @@ sub get_ntp_response {
my %opts = @_;
$opts{lc $_} = delete $opts{$_} for keys %opts;
croak "$package requires an 'event' argument\n"
unless $opts{event};
unless $opts{event};
my $options = delete $opts{options};
$opts{host} = 'localhost' unless $opts{host};
$opts{port} = 123 unless $opts{port} and $opts{port} =~ /^\d+$/;
Expand Down Expand Up @@ -247,7 +247,7 @@ sub _get_datagram {
sub _dispatch {
my ($kernel,$self) = @_[KERNEL,OBJECT];
my $data = { };
$data->{$_} = $self->{$_} for grep { defined $self->{$_} } qw(response error context);
$data->{$_} = $self->{$_} for grep { defined $self->{$_} } qw(response error context host);
$kernel->post( $self->{sender_id}, $self->{event}, $data );
$kernel->refcount_decrement( $self->{sender_id}, __PACKAGE__ );
return;
Expand Down Expand Up @@ -314,6 +314,7 @@ Takes a number of options, only those marked as C<mandatory> are required:
'host', the name/address of the NTP server to query, default is 'localhost';
'port', the UDP port to send the query to, default is 123;
'timeout', the number of seconds to wait for a response, default is 60 seconds;
'context', any reference data you wish to receive in the response event;
The C<session> parameter is only required if you wish the output event to go to a different session than the calling session,
or if you have spawned the poco outside of a session.
Expand All @@ -325,7 +326,9 @@ or if you have spawned the poco outside of a session.
This is generated by the poco. C<ARG0> will be a hash reference with the following keys:
'response', this will be a HASHREF on success;
'host', the host string that was passed to the constructor;
'error', on failure this will be defined, with an error string;
'context', whatever was passed to the constructor;
The C<response> hashref will contain various parts of the NTP response packet as outlined in RFC1305.
Like L<Net::NTP> some of the data will be normalised/humanised, such as timestamps are in epoch, NOT hexidecimal.
Expand Down

0 comments on commit 215c397

Please sign in to comment.