]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/DS.pm
ds: clobber $in_loop first at reset
[public-inbox.git] / lib / PublicInbox / DS.pm
1 # This library is free software; you can redistribute it and/or modify
2 # it under the same terms as Perl itself.
3 #
4 # This license differs from the rest of public-inbox
5 #
6 # This is a fork of the unmaintained Danga::Socket (1.61) with
7 # significant changes.  See Documentation/technical/ds.txt in our
8 # source for details.
9 #
10 # Do not expect this to be a stable API like Danga::Socket,
11 # but it will evolve to suite our needs and to take advantage of
12 # newer Linux and *BSD features.
13 # Bugs encountered were reported to bug-Danga-Socket@rt.cpan.org,
14 # fixed in Danga::Socket 1.62 and visible at:
15 # https://rt.cpan.org/Public/Dist/Display.html?Name=Danga-Socket
16 #
17 # fields:
18 # sock: underlying socket
19 # rbuf: scalarref, usually undef
20 # wbuf: arrayref of coderefs or tmpio (autovivified))
21 #        (tmpio = [ GLOB, offset, [ length ] ])
22 package PublicInbox::DS;
23 use strict;
24 use v5.10.1;
25 use parent qw(Exporter);
26 use bytes;
27 use POSIX qw(WNOHANG);
28 use IO::Handle qw();
29 use Fcntl qw(SEEK_SET :DEFAULT O_APPEND);
30 use Time::HiRes qw(clock_gettime CLOCK_MONOTONIC);
31 use Scalar::Util qw(blessed);
32 use PublicInbox::Syscall qw(:epoll);
33 use PublicInbox::Tmpfile;
34 use Errno qw(EAGAIN EINVAL);
35 use Carp qw(confess carp);
36 our @EXPORT_OK = qw(now msg_more dwaitpid);
37
38 my $nextq; # queue for next_tick
39 my $wait_pids; # list of [ pid, callback, callback_arg ]
40 my $later_queue; # list of callbacks to run at some later interval
41 my $EXPMAP; # fd -> idle_time
42 our $EXPTIME = 180; # 3 minutes
43 my ($later_timer, $reap_armed, $exp_timer);
44 my $ToClose; # sockets to close when event loop is done
45 our (
46      %DescriptorMap,             # fd (num) -> PublicInbox::DS object
47      $Epoll,                     # Global epoll fd (or DSKQXS ref)
48      $_io,                       # IO::Handle for Epoll
49
50      $PostLoopCallback,          # subref to call at the end of each loop, if defined (global)
51
52      $LoopTimeout,               # timeout of event loop in milliseconds
53      @Timers,                    # timers
54      $in_loop,
55      );
56
57 Reset();
58
59 #####################################################################
60 ### C L A S S   M E T H O D S
61 #####################################################################
62
63 =head2 C<< CLASS->Reset() >>
64
65 Reset all state
66
67 =cut
68 sub Reset {
69     $in_loop = undef; # first in case DESTROY callbacks use this
70     %DescriptorMap = ();
71     $wait_pids = $later_queue = $reap_armed = undef;
72     $EXPMAP = {};
73     $nextq = $ToClose = $later_timer = $exp_timer = undef;
74     $LoopTimeout = -1;  # no timeout by default
75     @Timers = ();
76
77     $PostLoopCallback = undef;
78
79     $_io = undef; # closes real $Epoll FD
80     $Epoll = undef; # may call DSKQXS::DESTROY
81 }
82
83 =head2 C<< CLASS->SetLoopTimeout( $timeout ) >>
84
85 Set the loop timeout for the event loop to some value in milliseconds.
86
87 A timeout of 0 (zero) means poll forever. A timeout of -1 means poll and return
88 immediately.
89
90 =cut
91 sub SetLoopTimeout { $LoopTimeout = $_[1] + 0 }
92
93 =head2 C<< PublicInbox::DS::add_timer( $seconds, $coderef, $arg) >>
94
95 Add a timer to occur $seconds from now. $seconds may be fractional, but timers
96 are not guaranteed to fire at the exact time you ask for.
97
98 =cut
99 sub add_timer ($$;$) {
100     my ($secs, $coderef, $arg) = @_;
101
102     my $fire_time = now() + $secs;
103
104     my $timer = [$fire_time, $coderef, $arg];
105
106     if (!@Timers || $fire_time >= $Timers[-1][0]) {
107         push @Timers, $timer;
108         return $timer;
109     }
110
111     # Now, where do we insert?  (NOTE: this appears slow, algorithm-wise,
112     # but it was compared against calendar queues, heaps, naive push/sort,
113     # and a bunch of other versions, and found to be fastest with a large
114     # variety of datasets.)
115     for (my $i = 0; $i < @Timers; $i++) {
116         if ($Timers[$i][0] > $fire_time) {
117             splice(@Timers, $i, 0, $timer);
118             return $timer;
119         }
120     }
121
122     die "Shouldn't get here.";
123 }
124
125 # keeping this around in case we support other FD types for now,
126 # epoll_create1(EPOLL_CLOEXEC) requires Linux 2.6.27+...
127 sub set_cloexec ($) {
128     my ($fd) = @_;
129
130     $_io = IO::Handle->new_from_fd($fd, 'r+') or return;
131     defined(my $fl = fcntl($_io, F_GETFD, 0)) or return;
132     fcntl($_io, F_SETFD, $fl | FD_CLOEXEC);
133 }
134
135 # caller sets return value to $Epoll
136 sub _InitPoller
137 {
138     if (PublicInbox::Syscall::epoll_defined())  {
139         my $fd = epoll_create();
140         set_cloexec($fd) if (defined($fd) && $fd >= 0);
141         $fd;
142     } else {
143         my $cls;
144         for (qw(DSKQXS DSPoll)) {
145             $cls = "PublicInbox::$_";
146             last if eval "require $cls";
147         }
148         $cls->import(qw(epoll_ctl epoll_wait));
149         $cls->new;
150     }
151 }
152
153 =head2 C<< CLASS->EventLoop() >>
154
155 Start processing IO events. In most daemon programs this never exits. See
156 C<PostLoopCallback> below for how to exit the loop.
157
158 =cut
159
160 sub now () { clock_gettime(CLOCK_MONOTONIC) }
161
162 sub next_tick () {
163     my $q = $nextq or return;
164     $nextq = undef;
165     for (@$q) {
166         # we avoid "ref" on blessed refs to workaround a Perl 5.16.3 leak:
167         # https://rt.perl.org/Public/Bug/Display.html?id=114340
168         if (blessed($_)) {
169             $_->event_step;
170         } else {
171             $_->();
172         }
173     }
174 }
175
176 # runs timers and returns milliseconds for next one, or next event loop
177 sub RunTimers {
178     next_tick();
179
180     return (($nextq || $ToClose) ? 0 : $LoopTimeout) unless @Timers;
181
182     my $now = now();
183
184     # Run expired timers
185     while (@Timers && $Timers[0][0] <= $now) {
186         my $to_run = shift(@Timers);
187         $to_run->[1]->($to_run->[2]);
188     }
189
190     # timers may enqueue into nextq:
191     return 0 if ($nextq || $ToClose);
192
193     return $LoopTimeout unless @Timers;
194
195     # convert time to an even number of milliseconds, adding 1
196     # extra, otherwise floating point fun can occur and we'll
197     # call RunTimers like 20-30 times, each returning a timeout
198     # of 0.0000212 seconds
199     my $timeout = int(($Timers[0][0] - $now) * 1000) + 1;
200
201     # -1 is an infinite timeout, so prefer a real timeout
202     ($LoopTimeout < 0 || $LoopTimeout >= $timeout) ? $timeout : $LoopTimeout;
203 }
204
205 # We can't use waitpid(-1) safely here since it can hit ``, system(),
206 # and other things.  So we scan the $wait_pids list, which is hopefully
207 # not too big.  We keep $wait_pids small by not calling dwaitpid()
208 # until we've hit EOF when reading the stdout of the child.
209
210 sub reap_pids {
211         $reap_armed = undef;
212         my $tmp = $wait_pids or return;
213         $wait_pids = undef;
214         foreach my $ary (@$tmp) {
215                 my ($pid, $cb, $arg) = @$ary;
216                 my $ret = waitpid($pid, WNOHANG);
217                 if ($ret == 0) {
218                         push @$wait_pids, $ary; # autovivifies @$wait_pids
219                 } elsif ($ret == $pid) {
220                         if ($cb) {
221                                 eval { $cb->($arg, $pid) };
222                                 warn "E: dwaitpid($pid) in_loop: $@" if $@;
223                         }
224                 } else {
225                         warn "waitpid($pid, WNOHANG) = $ret, \$!=$!, \$?=$?";
226                 }
227         }
228         # we may not be done, yet, and could've missed/masked a SIGCHLD:
229         $reap_armed //= requeue(\&reap_pids) if $wait_pids;
230 }
231
232 # reentrant SIGCHLD handler (since reap_pids is not reentrant)
233 sub enqueue_reap () { $reap_armed //= requeue(\&reap_pids) }
234
235 sub in_loop () { $in_loop }
236
237 # Internal function: run the post-event callback, send read events
238 # for pushed-back data, and close pending connections.  returns 1
239 # if event loop should continue, or 0 to shut it all down.
240 sub PostEventLoop () {
241         # now we can close sockets that wanted to close during our event
242         # processing.  (we didn't want to close them during the loop, as we
243         # didn't want fd numbers being reused and confused during the event
244         # loop)
245         if (my $close_now = $ToClose) {
246                 $ToClose = undef; # will be autovivified on push
247                 @$close_now = map { fileno($_) } @$close_now;
248
249                 # order matters, destroy expiry times, first:
250                 delete @$EXPMAP{@$close_now};
251
252                 # ->DESTROY methods may populate ToClose
253                 delete @DescriptorMap{@$close_now};
254         }
255
256         # by default we keep running, unless a postloop callback cancels it
257         $PostLoopCallback ? $PostLoopCallback->(\%DescriptorMap) : 1;
258 }
259
260 sub EventLoop {
261     $Epoll //= _InitPoller();
262     local $in_loop = 1;
263     my @events;
264     do {
265         my $timeout = RunTimers();
266
267         # get up to 1000 events
268         epoll_wait($Epoll, 1000, $timeout, \@events);
269         for my $fd (@events) {
270             # it's possible epoll_wait returned many events, including some at the end
271             # that ones in the front triggered unregister-interest actions.  if we
272             # can't find the %sock entry, it's because we're no longer interested
273             # in that event.
274             $DescriptorMap{$fd}->event_step;
275         }
276     } while (PostEventLoop());
277     _run_later();
278 }
279
280 =head2 C<< CLASS->SetPostLoopCallback( CODEREF ) >>
281
282 Sets post loop callback function.  Pass a subref and it will be
283 called every time the event loop finishes.
284
285 Return 1 (or any true value) from the sub to make the loop continue, 0 or false
286 and it will exit.
287
288 The callback function will be passed two parameters: \%DescriptorMap
289
290 =cut
291 sub SetPostLoopCallback {
292     my ($class, $ref) = @_;
293
294     # global callback
295     $PostLoopCallback = (defined $ref && ref $ref eq 'CODE') ? $ref : undef;
296 }
297
298 #####################################################################
299 ### PublicInbox::DS-the-object code
300 #####################################################################
301
302 =head2 OBJECT METHODS
303
304 =head2 C<< CLASS->new( $socket ) >>
305
306 Create a new PublicInbox::DS subclass object for the given I<socket> which will
307 react to events on it during the C<EventLoop>.
308
309 This is normally (always?) called from your subclass via:
310
311   $class->SUPER::new($socket);
312
313 =cut
314 sub new {
315     my ($self, $sock, $ev) = @_;
316     $self->{sock} = $sock;
317     my $fd = fileno($sock);
318
319     $Epoll //= _InitPoller();
320 retry:
321     if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $ev)) {
322         if ($! == EINVAL && ($ev & EPOLLEXCLUSIVE)) {
323             $ev &= ~EPOLLEXCLUSIVE;
324             goto retry;
325         }
326         die "couldn't add epoll watch for $fd: $!\n";
327     }
328     confess("DescriptorMap{$fd} defined ($DescriptorMap{$fd})")
329         if defined($DescriptorMap{$fd});
330
331     $DescriptorMap{$fd} = $self;
332 }
333
334
335 #####################################################################
336 ### I N S T A N C E   M E T H O D S
337 #####################################################################
338
339 sub requeue ($) { push @$nextq, $_[0] } # autovivifies
340
341 =head2 C<< $obj->close >>
342
343 Close the socket.
344
345 =cut
346 sub close {
347     my ($self) = @_;
348     my $sock = delete $self->{sock} or return;
349
350     # we need to flush our write buffer, as there may
351     # be self-referential closures (sub { $client->close })
352     # preventing the object from being destroyed
353     delete $self->{wbuf};
354
355     # if we're using epoll, we have to remove this from our epoll fd so we stop getting
356     # notifications about it
357     my $fd = fileno($sock);
358     epoll_ctl($Epoll, EPOLL_CTL_DEL, $fd, 0) and
359         confess("EPOLL_CTL_DEL: $!");
360
361     # we explicitly don't delete from DescriptorMap here until we
362     # actually close the socket, as we might be in the middle of
363     # processing an epoll_wait/etc that returned hundreds of fds, one
364     # of which is not yet processed and is what we're closing.  if we
365     # keep it in DescriptorMap, then the event harnesses can just
366     # looked at $pob->{sock} == undef and ignore it.  but if it's an
367     # un-accounted for fd, then it (understandably) freak out a bit
368     # and emit warnings, thinking their state got off.
369
370     # defer closing the actual socket until the event loop is done
371     # processing this round of events.  (otherwise we might reuse fds)
372     push @$ToClose, $sock; # autovivifies $ToClose
373
374     return 0;
375 }
376
377 # portable, non-thread-safe sendfile emulation (no pread, yet)
378 sub send_tmpio ($$) {
379     my ($sock, $tmpio) = @_;
380
381     sysseek($tmpio->[0], $tmpio->[1], SEEK_SET) or return;
382     my $n = $tmpio->[2] // 65536;
383     $n = 65536 if $n > 65536;
384     defined(my $to_write = sysread($tmpio->[0], my $buf, $n)) or return;
385     my $written = 0;
386     while ($to_write > 0) {
387         if (defined(my $w = syswrite($sock, $buf, $to_write, $written))) {
388             $written += $w;
389             $to_write -= $w;
390         } else {
391             return if $written == 0;
392             last;
393         }
394     }
395     $tmpio->[1] += $written; # offset
396     $tmpio->[2] -= $written if defined($tmpio->[2]); # length
397     $written;
398 }
399
400 sub epbit ($$) { # (sock, default)
401         $_[0]->can('stop_SSL') ? PublicInbox::TLS::epollbit() : $_[1];
402 }
403
404 # returns 1 if done, 0 if incomplete
405 sub flush_write ($) {
406     my ($self) = @_;
407     my $sock = $self->{sock} or return;
408     my $wbuf = $self->{wbuf} or return 1;
409
410 next_buf:
411     while (my $bref = $wbuf->[0]) {
412         if (ref($bref) ne 'CODE') {
413             while ($sock) {
414                 my $w = send_tmpio($sock, $bref); # bref is tmpio
415                 if (defined $w) {
416                     if ($w == 0) {
417                         shift @$wbuf;
418                         goto next_buf;
419                     }
420                 } elsif ($! == EAGAIN) {
421                     my $ev = epbit($sock, EPOLLOUT) or return $self->close;
422                     epwait($sock, $ev | EPOLLONESHOT);
423                     return 0;
424                 } else {
425                     return $self->close;
426                 }
427             }
428         } else { #(ref($bref) eq 'CODE') {
429             shift @$wbuf;
430             my $before = scalar(@$wbuf);
431             $bref->($self);
432
433             # bref may be enqueueing more CODE to call (see accept_tls_step)
434             return 0 if (scalar(@$wbuf) > $before);
435         }
436     } # while @$wbuf
437
438     delete $self->{wbuf};
439     1; # all done
440 }
441
442 sub rbuf_idle ($$) {
443     my ($self, $rbuf) = @_;
444     if ($$rbuf eq '') { # who knows how long till we can read again
445         delete $self->{rbuf};
446     } else {
447         $self->{rbuf} = $rbuf;
448     }
449 }
450
451 sub do_read ($$$;$) {
452     my ($self, $rbuf, $len, $off) = @_;
453     my $r = sysread(my $sock = $self->{sock}, $$rbuf, $len, $off // 0);
454     return ($r == 0 ? $self->close : $r) if defined $r;
455     # common for clients to break connections without warning,
456     # would be too noisy to log here:
457     if ($! == EAGAIN) {
458         my $ev = epbit($sock, EPOLLIN) or return $self->close;
459         epwait($sock, $ev | EPOLLONESHOT);
460         rbuf_idle($self, $rbuf);
461         0;
462     } else {
463         $self->close;
464     }
465 }
466
467 # drop the socket if we hit unrecoverable errors on our system which
468 # require BOFH attention: ENOSPC, EFBIG, EIO, EMFILE, ENFILE...
469 sub drop {
470     my $self = shift;
471     carp(@_);
472     $self->close;
473 }
474
475 # n.b.: use ->write/->read for this buffer to allow compatibility with
476 # PerlIO::mmap or PerlIO::scalar if needed
477 sub tmpio ($$$) {
478     my ($self, $bref, $off) = @_;
479     my $fh = tmpfile('wbuf', $self->{sock}, O_APPEND) or
480         return drop($self, "tmpfile $!");
481     $fh->autoflush(1);
482     my $len = bytes::length($$bref) - $off;
483     $fh->write($$bref, $len, $off) or return drop($self, "write ($len): $!");
484     [ $fh, 0 ] # [1] = offset, [2] = length, not set by us
485 }
486
487 =head2 C<< $obj->write( $data ) >>
488
489 Write the specified data to the underlying handle.  I<data> may be scalar,
490 scalar ref, code ref (to run when there).
491 Returns 1 if writes all went through, or 0 if there are writes in queue. If
492 it returns 1, caller should stop waiting for 'writable' events)
493
494 =cut
495 sub write {
496     my ($self, $data) = @_;
497
498     # nobody should be writing to closed sockets, but caller code can
499     # do two writes within an event, have the first fail and
500     # disconnect the other side (whose destructor then closes the
501     # calling object, but it's still in a method), and then the
502     # now-dead object does its second write.  that is this case.  we
503     # just lie and say it worked.  it'll be dead soon and won't be
504     # hurt by this lie.
505     my $sock = $self->{sock} or return 1;
506     my $ref = ref $data;
507     my $bref = $ref ? $data : \$data;
508     my $wbuf = $self->{wbuf};
509     if ($wbuf && scalar(@$wbuf)) { # already buffering, can't write more...
510         if ($ref eq 'CODE') {
511             push @$wbuf, $bref;
512         } else {
513             my $tmpio = $wbuf->[-1];
514             if ($tmpio && !defined($tmpio->[2])) { # append to tmp file buffer
515                 $tmpio->[0]->print($$bref) or return drop($self, "print: $!");
516             } else {
517                 my $tmpio = tmpio($self, $bref, 0) or return 0;
518                 push @$wbuf, $tmpio;
519             }
520         }
521         return 0;
522     } elsif ($ref eq 'CODE') {
523         $bref->($self);
524         return 1;
525     } else {
526         my $to_write = bytes::length($$bref);
527         my $written = syswrite($sock, $$bref, $to_write);
528
529         if (defined $written) {
530             return 1 if $written == $to_write;
531             requeue($self); # runs: event_step -> flush_write
532         } elsif ($! == EAGAIN) {
533             my $ev = epbit($sock, EPOLLOUT) or return $self->close;
534             epwait($sock, $ev | EPOLLONESHOT);
535             $written = 0;
536         } else {
537             return $self->close;
538         }
539
540         # deal with EAGAIN or partial write:
541         my $tmpio = tmpio($self, $bref, $written) or return 0;
542
543         # wbuf may be an empty array if we're being called inside
544         # ->flush_write via CODE bref:
545         push @{$self->{wbuf}}, $tmpio; # autovivifies
546         return 0;
547     }
548 }
549
550 use constant MSG_MORE => ($^O eq 'linux') ? 0x8000 : 0;
551
552 sub msg_more ($$) {
553     my $self = $_[0];
554     my $sock = $self->{sock} or return 1;
555     my $wbuf = $self->{wbuf};
556
557     if (MSG_MORE && (!defined($wbuf) || !scalar(@$wbuf)) &&
558                 !$sock->can('stop_SSL')) {
559         my $n = send($sock, $_[1], MSG_MORE);
560         if (defined $n) {
561             my $nlen = bytes::length($_[1]) - $n;
562             return 1 if $nlen == 0; # all done!
563             # queue up the unwritten substring:
564             my $tmpio = tmpio($self, \($_[1]), $n) or return 0;
565             push @{$self->{wbuf}}, $tmpio; # autovivifies
566             epwait($sock, EPOLLOUT|EPOLLONESHOT);
567             return 0;
568         }
569     }
570
571     # don't redispatch into NNTPdeflate::write
572     PublicInbox::DS::write($self, \($_[1]));
573 }
574
575 sub epwait ($$) {
576     my ($sock, $ev) = @_;
577     epoll_ctl($Epoll, EPOLL_CTL_MOD, fileno($sock), $ev) and
578         confess("EPOLL_CTL_MOD $!");
579 }
580
581 # return true if complete, false if incomplete (or failure)
582 sub accept_tls_step ($) {
583     my ($self) = @_;
584     my $sock = $self->{sock} or return;
585     return 1 if $sock->accept_SSL;
586     return $self->close if $! != EAGAIN;
587     my $ev = PublicInbox::TLS::epollbit() or return $self->close;
588     epwait($sock, $ev | EPOLLONESHOT);
589     unshift(@{$self->{wbuf}}, \&accept_tls_step); # autovivifies
590     0;
591 }
592
593 # return true if complete, false if incomplete (or failure)
594 sub shutdn_tls_step ($) {
595     my ($self) = @_;
596     my $sock = $self->{sock} or return;
597     return $self->close if $sock->stop_SSL(SSL_fast_shutdown => 1);
598     return $self->close if $! != EAGAIN;
599     my $ev = PublicInbox::TLS::epollbit() or return $self->close;
600     epwait($sock, $ev | EPOLLONESHOT);
601     unshift(@{$self->{wbuf}}, \&shutdn_tls_step); # autovivifies
602     0;
603 }
604
605 # don't bother with shutdown($sock, 2), we don't fork+exec w/o CLOEXEC
606 # or fork w/o exec, so no inadvertent socket sharing
607 sub shutdn ($) {
608     my ($self) = @_;
609     my $sock = $self->{sock} or return;
610     if ($sock->can('stop_SSL')) {
611         shutdn_tls_step($self);
612     } else {
613         $self->close;
614     }
615 }
616
617 sub dwaitpid ($;$$) {
618         my ($pid, $cb, $arg) = @_;
619         if ($in_loop) {
620                 push @$wait_pids, [ $pid, $cb, $arg ];
621                 # We could've just missed our SIGCHLD, cover it, here:
622                 enqueue_reap();
623         } else {
624                 my $ret = waitpid($pid, 0);
625                 if ($ret == $pid) {
626                         if ($cb) {
627                                 eval { $cb->($arg, $pid) };
628                                 carp "E: dwaitpid($pid) !in_loop: $@" if $@;
629                         }
630                 } else {
631                         carp "waitpid($pid, 0) = $ret, \$!=$!, \$?=$?";
632                 }
633         }
634 }
635
636 sub _run_later () {
637         my $run = $later_queue or return;
638         $later_timer = $later_queue = undef;
639         $_->() for @$run;
640 }
641
642 sub later ($) {
643         push @$later_queue, $_[0]; # autovivifies @$later_queue
644         $later_timer //= add_timer(60, \&_run_later);
645 }
646
647 sub expire_old () {
648         my $now = now();
649         my $exp = $EXPTIME;
650         my $old = $now - $exp;
651         my %new;
652         while (my ($fd, $idle_at) = each %$EXPMAP) {
653                 if ($idle_at < $old) {
654                         my $ds_obj = $DescriptorMap{$fd};
655                         $new{$fd} = $idle_at if !$ds_obj->shutdn;
656                 } else {
657                         $new{$fd} = $idle_at;
658                 }
659         }
660         $EXPMAP = \%new;
661         $exp_timer = scalar(keys %new) ? later(\&expire_old) : undef;
662 }
663
664 sub update_idle_time {
665         my ($self) = @_;
666         my $sock = $self->{sock} or return;
667         $EXPMAP->{fileno($sock)} = now();
668         $exp_timer //= later(\&expire_old);
669 }
670
671 sub not_idle_long {
672         my ($self, $now) = @_;
673         my $sock = $self->{sock} or return;
674         my $idle_at = $EXPMAP->{fileno($sock)} or return;
675         ($idle_at + $EXPTIME) > $now;
676 }
677
678 1;
679
680 =head1 AUTHORS (Danga::Socket)
681
682 Brad Fitzpatrick <brad@danga.com> - author
683
684 Michael Granger <ged@danga.com> - docs, testing
685
686 Mark Smith <junior@danga.com> - contributor, heavy user, testing
687
688 Matt Sergeant <matt@sergeant.org> - kqueue support, docs, timers, other bits