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