Emitting a message every 100ms was too much for busy machines.
Throttle it to 1.6s to avoid flooding user terminals by emitting
every 16 sleeps. A power-of-two (16) was chosen for its
optimization potential via bitwise AND. Since perl(1) doesn't
do this optimization, we open code the bitwise AND. I don't
assume an optimizing compiler for Inline::C, either, since I
find working in C far more enjoyable with optimizations off.
return 1 if $!{EINTR};
return unless ($!{ENOMEM} || $!{ENOBUFS} || $!{ETOOMANYREFS});
return if $_[0]-- == 0;
- warn "# sleeping on sendmsg: $! ($_[0] tries left)\n";
+ # n.b. `N & (power-of-two - 1)' is a faster `N % power-of-two'
+ warn "# sleeping on sendmsg: $! ($_[0] tries left)\n" if !($_[0] & 15);
select(undef, undef, undef, 0.1);
1;
}
case EINTR: PERL_ASYNC_CHECK(); return 1;
case ENOBUFS: case ENOMEM: case ETOOMANYREFS:
if (*tries-- == 0) return 0;
- fprintf(stderr, "# sleeping on sendmsg: %s (%ld tries left)\n",
- strerror(err), *tries);
+ if (!(*tries & 15))
+ fprintf(stderr,
+ "# sleeping on sendmsg: %s (%ld tries left)\n",
+ strerror(err), *tries);
nanosleep(&req, NULL);
PERL_ASYNC_CHECK();
return 1;