--- AnyEvent-FastPing/FastPing.xs 2014/10/08 21:12:28 1.14 +++ AnyEvent-FastPing/FastPing.xs 2016/11/12 01:20:46 1.15 @@ -638,13 +638,8 @@ #endif static void -boot () +boot_protocols (void) { - if (pipe (thr_res) < 0) - croak ("AnyEvent::FastPing: unable to create receive pipe"); - - sv_setiv (get_sv ("AnyEvent::FastPing::THR_RES_FD", 1), thr_res [0]); - icmp4_fd = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); fcntl (icmp4_fd, F_SETFL, O_NONBLOCK); #ifdef ICMP_FILTER @@ -667,6 +662,17 @@ } # endif #endif +} + +static void +boot (void) +{ + if (pipe (thr_res) < 0) + croak ("AnyEvent::FastPing: unable to create receive pipe"); + + sv_setiv (get_sv ("AnyEvent::FastPing::THR_RES_FD", 1), thr_res [0]); + + boot_protocols (); sv_setiv (get_sv ("AnyEvent::FastPing::ICMP4_FD", 1), icmp4_fd); sv_setiv (get_sv ("AnyEvent::FastPing::ICMP6_FD", 1), icmp6_fd); @@ -674,27 +680,35 @@ #define NOT_RUNNING \ if (self->running) \ - croak ("AnyEvent::FastPing object has been started - you have to sotp t first before calling this method, caught"); + croak ("AnyEvent::FastPing object has been started - you have to stop it first before calling this method, caught"); MODULE = AnyEvent::FastPing PACKAGE = AnyEvent::FastPing PREFIX = pinger_ +PROTOTYPES: DISABLE + BOOT: { - HV *stash = gv_stashpv ("AnyEvent::FastPing", 1); - - if (sizeof (PKT) & 3) - croak ("size of PKT structure is not a multiple of 4"); - - boot (); - - newCONSTSUB (stash, "ipv4_supported", newSViv (icmp4_fd >= 0)); - newCONSTSUB (stash, "ipv6_supported", newSViv (icmp6_fd >= 0)); - - newCONSTSUB (stash, "icmp4_pktsize", newSViv (HDR_SIZE_IP4 + sizeof (PKT))); - newCONSTSUB (stash, "icmp6_pktsize", newSViv (HDR_SIZE_IP6 + sizeof (PKT))); + HV *stash = gv_stashpv ("AnyEvent::FastPing", 1); + + if (sizeof (PKT) & 3) + croak ("size of PKT structure is not a multiple of 4"); + + newCONSTSUB (stash, "icmp4_pktsize", newSViv (HDR_SIZE_IP4 + sizeof (PKT))); + newCONSTSUB (stash, "icmp6_pktsize", newSViv (HDR_SIZE_IP6 + sizeof (PKT))); + + boot_protocols (); + + newCONSTSUB (stash, "ipv4_supported", newSViv (icmp4_fd >= 0)); + newCONSTSUB (stash, "ipv6_supported", newSViv (icmp6_fd >= 0)); + + close (icmp4_fd); + close (icmp6_fd); } -PROTOTYPES: DISABLE +void +_boot () + CODE: + boot (); void _recv_icmp4 (...)