.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "POE::Component::Client::Ping 3pm" .TH POE::Component::Client::Ping 3pm "2021-02-15" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" POE::Component::Client::Ping \- a non\-blocking ICMP ping client .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use POE qw(Component::Client::Ping); \& \& POE::Component::Client::Ping\->spawn( \& Alias => "pingthing", # defaults to "pinger" \& Timeout => 10, # defaults to 1 second \& Retry => 3, # defaults to 1 attempt \& OneReply => 1, # defaults to disabled \& Parallelism => 64, # defaults to autodetect \& BufferSize => 65536, # defaults to undef \& AlwaysDecodeAddress => 1, # defaults to 0 \& ); \& \& sub some_event_handler { \& $kernel\->post( \& "pingthing", # Post the request to the "pingthing" component. \& "ping", # Ask it to "ping" an address. \& "pong", # Have it post an answer as a "pong" event. \& $address, # This is the address we want to ping. \& $timeout, # Optional timeout. It overrides the default. \& $retry, # Optional retries. It overrides the default. \& ); \& } \& \& # This is the sub which is called when the session receives a "pong" \& # event. It handles responses from the Ping component. \& sub got_pong { \& my ($request, $response) = @_[ARG0, ARG1]; \& \& my ($req_address, $req_timeout, $req_time) = @$request; \& my ($resp_address, $roundtrip_time, $resp_time, $resp_ttl) = @$response; \& \& # The response address is defined if this is a response. \& if (defined $resp_address) { \& printf( \& "ping to %\-15.15s at %10d. pong from %\-15.15s in %6.3f s\en", \& $req_address, $req_time, \& $resp_address, $roundtrip_time, \& ); \& return; \& } \& \& # Otherwise the timeout period has ended. \& printf( \& "ping to %\-15.15s is done.\en", $req_address, \& ); \& } \& \& or \& \& use POE::Component::Client::Ping ":const"; \& \& # Post an array ref as the callback to get data back to you \& $kernel\->post("pinger", "ping", [ "pong", $user_data ]); \& \& # use the REQ_USER_ARGS constant to get to your data \& sub got_pong { \& my ($request, $response) = @_[ARG0, ARG1]; \& my $user_data = $request\->[REQ_USER_ARGS]; \& ...; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" POE::Component::Client::Ping is non-blocking \s-1ICMP\s0 ping client. It lets several other sessions ping through it in parallel, and it lets them continue doing other things while they wait for responses. .PP Ping client components are not proper objects. Instead of being created, as most objects are, they are \*(L"spawned\*(R" as separate sessions. To avoid confusion (and hopefully not cause other confusion), they must be spawned with a \f(CW\*(C`spawn\*(C'\fR method, not created anew with a \f(CW\*(C`new\*(C'\fR one. .PP PoCo::Client::Ping's \f(CW\*(C`spawn\*(C'\fR method takes a few named parameters: .ie n .IP "Alias => $session_alias" 2 .el .IP "Alias => \f(CW$session_alias\fR" 2 .IX Item "Alias => $session_alias" \&\f(CW\*(C`Alias\*(C'\fR sets the component's alias. It is the target of \fBpost()\fR calls. See the synopsis. The alias defaults to \*(L"pinger\*(R". .ie n .IP "Socket => $raw_socket" 2 .el .IP "Socket => \f(CW$raw_socket\fR" 2 .IX Item "Socket => $raw_socket" \&\f(CW\*(C`Socket\*(C'\fR allows developers to open an existing raw socket rather than letting the component attempt opening one itself. If omitted, the component will create its own raw socket. .Sp This is useful for people who would rather not perform a security audit on \s-1POE,\s0 since it allows them to create a raw socket in their own code and then run \s-1POE\s0 at reduced privileges. .ie n .IP "Timeout => $ping_timeout" 2 .el .IP "Timeout => \f(CW$ping_timeout\fR" 2 .IX Item "Timeout => $ping_timeout" \&\f(CW\*(C`Timeout\*(C'\fR sets the default amount of time (in seconds) a Ping component will wait for a single \s-1ICMP\s0 echo reply before retrying. It is 1 by default. It is possible and meaningful to set the timeout to a fractional number of seconds. .Sp This default timeout is only used for ping requests that don't include their own timeouts. .ie n .IP "Retry => $ping_attempts" 2 .el .IP "Retry => \f(CW$ping_attempts\fR" 2 .IX Item "Retry => $ping_attempts" \&\f(CW\*(C`Retry\*(C'\fR sets the default number of attempts a ping will be sent before it should be considered failed. It is 1 by default. .IP "OneReply => 0|1" 2 .IX Item "OneReply => 0|1" Set \f(CW\*(C`OneReply\*(C'\fR to prevent the Ping component from waiting the full timeout period for replies. Normally the \s-1ICMP\s0 protocol allows for multiple replies to a single request, so it's proper to wait for late responses. This option disables the wait, ending the ping transaction at the first response. Any subsequent responses will be silently ignored. .Sp \&\f(CW\*(C`OneReply\*(C'\fR is disabled by default, and a single successful request will generate at least two responses. The first response is a successful \s-1ICMP ECHO REPLY\s0 event. The second is an undefined response event, signifying that the timeout period has ended. .Sp A ping request will generate exactly one reply when \f(CW\*(C`OneReply\*(C'\fR is enabled. This reply will represent either the first \s-1ICMP ECHO REPLY\s0 to arrive or that the timeout period has ended. .ie n .IP "Parallelism => $limit" 2 .el .IP "Parallelism => \f(CW$limit\fR" 2 .IX Item "Parallelism => $limit" Parallelism sets POE::Component::Client::Ping's maximum number of simultaneous \s-1ICMP\s0 requests. Higher numbers speed up the processing of large host lists, up to the point where the operating system or network becomes oversaturated and begin to drop packets. .Sp The difference can be dramatic. A tuned Parallelism can enable responses down to 1ms, depending on the network, although it will take longer to get through the hosts list. .Sp .Vb 5 \& Pinging 762 hosts at Parallelism=64 \& Starting to ping hosts. \& Pinged 10.0.0.25 \- Response from 10.0.0.25 in 0.002s \& Pinged 10.0.0.200 \- Response from 10.0.0.200 in 0.003s \& Pinged 10.0.0.201 \- Response from 10.0.0.201 in 0.001s \& \& real 1m1.923s \& user 0m2.584s \& sys 0m0.207s .Ve .Sp Responses will take significantly longer with an untuned Parallelism, but the total run time will be quicker. .Sp .Vb 5 \& Pinging 762 hosts at Parallelism=500 \& Starting to ping hosts. \& Pinged 10.0.0.25 \- Response from 10.0.0.25 in 3.375s \& Pinged 10.0.0.200 \- Response from 10.0.0.200 in 1.258s \& Pinged 10.0.0.201 \- Response from 10.0.0.201 in 2.040s \& \& real 0m13.410s \& user 0m6.390s \& sys 0m0.290s .Ve .Sp Excessively high parallelism values may saturate the \s-1OS\s0 or network, resulting in few or no responses. .Sp .Vb 2 \& Pinging 762 hosts at Parallelism=1000 \& Starting to ping hosts. \& \& real 0m20.520s \& user 0m7.896s \& sys 0m0.297s .Ve .Sp By default, POE::Component::Client::Ping will guess at an optimal Parallelism value based on the raw socket receive buffer size and the operating system's nominal \s-1ICMP\s0 packet size. The latter figure is 3000 octets for Linux and 100 octets for other systems. \s-1ICMP\s0 packets are generally under 90 bytes, but operating systems may use alternative numbers when calculating buffer capacities. The component tries to mimic calculations observed in the wild. .Sp When in doubt, experiment with different Parallelism values and use the one that works best. .ie n .IP "BufferSize => $bytes" 2 .el .IP "BufferSize => \f(CW$bytes\fR" 2 .IX Item "BufferSize => $bytes" If set, then the size of the receive buffer of the raw socket will be modified to the given value. The default size of the receive buffer is operating system dependent. If the buffer cannot be set to the given value, a warning will be generated but the system will continue working. Note that if the buffer is set too small and too many ping replies arrive at the same time, then the operating system may discard the ping replies and mistakenly cause this component to believe the ping to have timed out. In this case, you will typically see discards being noted in the counters displayed by 'netstat \-s'. .Sp Increased BufferSize values can expand the practical limit for Parallelism. .IP "AlwaysDecodeAddress => 0|1" 2 .IX Item "AlwaysDecodeAddress => 0|1" If set, then any input addresses will always be looked up, even if the hostname happens to be only 4 characters in size. Ideally, you should be passing addresses in to the system to avoid slow hostname lookups, but if you must use hostnames and there is a possibility that you might have short hostnames, then you should set this. .ie n .IP "Payload => $bytes" 2 .el .IP "Payload => \f(CW$bytes\fR" 2 .IX Item "Payload => $bytes" Sets the \s-1ICMP\s0 payload (data bytes). Otherwise the component generates 56 data bytes internally. Note that some firewalls will discard \s-1ICMP\s0 packets with nonstandard payload sizes. .PP Sessions communicate asynchronously with the Client::Ping component. They post ping requests to it, and they receive pong events back. .PP Requests are posted to the component's \*(L"ping\*(R" handler. They include the name of an event to post back, an address to ping, and an optional amount of time to wait for responses. The address may be a numeric dotted quad, a packed inet_aton address, or a host name. Host names are not recommended: they must be looked up for every ping request, and \s-1DNS\s0 lookups can be very slow. The optional timeout overrides the one set when \f(CW\*(C`spawn\*(C'\fR is called. .PP Ping responses come with two array references: .PP .Vb 1 \& my ($request, $response) = @_[ARG0, ARG1]; .Ve .PP \&\f(CW$request\fR contains information about the original request: .PP .Vb 3 \& my ( \& $req_address, $req_timeout, $req_time, $req_user_args, \& ) = @$request; .Ve .ie n .IP "$req_address" 2 .el .IP "\f(CW$req_address\fR" 2 .IX Item "$req_address" This is the original request address. It matches the address posted along with the original \*(L"ping\*(R" request. .Sp It is useful along with \f(CW$req_user_args\fR for pairing requests with their corresponding responses. .ie n .IP "$req_timeout" 2 .el .IP "\f(CW$req_timeout\fR" 2 .IX Item "$req_timeout" This is the original request timeout. It's either the one passed with the \*(L"ping\*(R" request or the default timeout set with \f(CW\*(C`spawn\*(C'\fR. .ie n .IP "$req_time" 2 .el .IP "\f(CW$req_time\fR" 2 .IX Item "$req_time" This is the time that the \*(L"ping\*(R" event was received by the Ping component. It is a real number based on the current system's \fBtime()\fR epoch. .ie n .IP "$req_user_args" 2 .el .IP "\f(CW$req_user_args\fR" 2 .IX Item "$req_user_args" This is a scalar containing arbitrary data that can be sent along with a request. It's often used to provide continuity between requests and their responses. \f(CW$req_user_args\fR may contain a reference to some larger data structure. .Sp To use it, replace the response event with an array reference in the original request. The array reference should contain two items: the actual response event and a scalar with the context data the program needs back. See the \s-1SYNOPSIS\s0 for an example. .PP \&\f(CW$response\fR contains information about the \s-1ICMP\s0 ping response. There may be multiple responses for a single request. .PP .Vb 2 \& my ($response_address, $roundtrip_time, $reply_time, $reply_ttl) = \& @$response; .Ve .ie n .IP "$response_address" 2 .el .IP "\f(CW$response_address\fR" 2 .IX Item "$response_address" This is the address that responded to the \s-1ICMP\s0 echo request. It may be different than \f(CW$request_address\fR, especially if the request was sent to a broadcast address. .Sp \&\f(CW$response_address\fR will be undefined if \f(CW$request_timeout\fR seconds have elapsed. This marks the end of responses for a given request. Programs can assume that no more responses will be sent for the request address. They may use this marker to initiate another ping request. .ie n .IP "$roundtrip_time" 2 .el .IP "\f(CW$roundtrip_time\fR" 2 .IX Item "$roundtrip_time" This is the number of seconds that elapsed between the \s-1ICMP\s0 echo request's transmission and its corresponding response's receipt. It's a real number. This is purely the trip time and does *not* include any time spent queueing if the system's parallelism limit caused the ping transmission to be delayed. .ie n .IP "$reply_time" 2 .el .IP "\f(CW$reply_time\fR" 2 .IX Item "$reply_time" This is the time when the \s-1ICMP\s0 echo response was received. It is a real number based on the current system's \fBtime()\fR epoch. .ie n .IP "$reply_ttl" 2 .el .IP "\f(CW$reply_ttl\fR" 2 .IX Item "$reply_ttl" This is the ttl for the echo response packet we received. .PP If the \*(L":const\*(R" tagset is imported the following constants will be exported: .PP \&\s-1REQ_ADDRESS, REQ_TIMEOUT, REQ_TIME REQ_USER_ARGS, RES_ADDRESS, RES_ROUNDTRIP, RES_TIME, RES_TTL\s0 .SH "SEE ALSO" .IX Header "SEE ALSO" This component's \s-1ICMP\s0 ping code was lifted from Net::Ping, which is an excellent module when you only need to ping one host at a time. .PP See \s-1POE,\s0 of course, which includes a lot of documentation about how \&\s-1POE\s0 works. .PP Also see the test program, t/01_ping.t, in the component's distribution. .SH "BUG TRACKER" .IX Header "BUG TRACKER" https://rt.cpan.org/Dist/Display.html?Queue=POE\-Component\-Client\-Ping .SH "REPOSITORY" .IX Header "REPOSITORY" http://github.com/rcaputo/poe\-component\-client\-ping/ .SH "OTHER RESOURCES" .IX Header "OTHER RESOURCES" http://search.cpan.org/dist/POE\-Component\-Client\-Ping/ .SH "AUTHOR & COPYRIGHTS" .IX Header "AUTHOR & COPYRIGHTS" POE::Component::Client::Ping is Copyright 1999\-2020 by Rocco Caputo. All rights are reserved. POE::Component::Client::Ping is free software; you may redistribute it and/or modify it under the same terms as Perl itself. .PP You can learn more about \s-1POE\s0 at http://poe.perl.org/