Subject: | Incomplete implementation of spawn(Socket => $socket) |
PoCo::Client::Ping
When spawn() is called with a Socket parameter (so that the program doesn't need root privileges), there are a few bugs:
1) $kernel->select_read() needs root as well, else the pings don't work.
2) The pinger session destroys the socket after the first ping, so subsequent pings do not work. This is fine if you don't mind running the program as root, but it should be fixed.
Both bugs are fixed in my attached patch.
--- POE-Component-Client-Ping-0.97/Ping.pm 2002-08-27 07:23:17.000000000 -0500
+++ PoCo-Client-Ping-new/Ping.pm 2002-10-09 16:48:22.000000000 -0500
@@ -102,7 +102,13 @@
$heap->{onereply} = $onereply;
$heap->{ping_by_seq} = { }; # keyed on sequence number
$heap->{addr_to_seq} = { }; # keyed on request address, then sender
- $heap->{socket_handle} = $socket if defined $socket;
+ if( defined $socket ) {
+ # root is needed for this step too
+ $kernel->select_read($heap->{socket_handle} = $socket, 'got_pong');
+ $heap->{keep_socket} = 1;
+ } else {
+ $heap->{keep_socket} = 0;
+ }
$kernel->alias_set($alias);
}
@@ -270,7 +276,7 @@
}
# No more pings waiting. Close the socket.
- unless (scalar keys %{$heap->{ping_by_seq}}) {
+ unless (scalar(keys %{$heap->{ping_by_seq}}) || $heap->{keep_socket}) {
DEBUG_SOCKET and warn "closing the raw icmp socket";
$kernel->select_read( delete $heap->{socket_handle} );
}
@@ -367,7 +373,7 @@
unless scalar(keys %{$heap->{addr_to_seq}->{$ping_info->[PBS_SESSION]}});
# Close the socket if there are no sessions waiting for responses.
- unless (scalar keys %{$heap->{ping_by_seq}}) {
+ unless (scalar(keys %{$heap->{ping_by_seq}}) || $heap->{keep_socket}) {
DEBUG_SOCKET and warn "closing the raw icmp socket";
$kernel->select_read( delete $heap->{socket_handle} );
}