1 # This library is free software; you can redistribute it and/or modify
2 # it under the same terms as Perl itself.
4 # This license differs from the rest of public-inbox
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.
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;
22 use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
26 use PublicInbox::Syscall qw(:epoll);
28 use fields ('sock', # underlying socket
29 'fd', # numeric file descriptor
30 'write_buf', # arrayref of scalars, scalarrefs, or coderefs to write
31 'write_buf_offset', # offset into first array of write_buf to start writing at
32 'write_buf_size', # total length of data in all write_buf items
33 'closed', # bool: socket is closed
34 'event_watch', # bitmask of events the client is interested in (POLLIN,OUT,etc.)
37 use Errno qw(EINPROGRESS EWOULDBLOCK EISCONN ENOTSOCK
38 EPIPE EAGAIN EBADF ECONNRESET ENOPROTOOPT);
39 use Carp qw(croak confess);
41 use constant DebugLevel => 0;
43 use constant POLLIN => 1;
44 use constant POLLOUT => 4;
45 use constant POLLERR => 8;
46 use constant POLLHUP => 16;
47 use constant POLLNVAL => 32;
49 our $HAVE_KQUEUE = eval { require IO::KQueue; 1 };
52 $HaveEpoll, # Flag -- is epoll available? initially undefined.
54 %DescriptorMap, # fd (num) -> PublicInbox::DS object
55 $Epoll, # Global epoll fd (for epoll mode only)
56 $KQueue, # Global kqueue fd ref (for kqueue mode only)
57 $_io, # IO::Handle for Epoll
58 @ToClose, # sockets to close when event loop is done
60 $PostLoopCallback, # subref to call at the end of each loop, if defined (global)
61 %PLCMap, # fd (num) -> PostLoopCallback (per-object)
63 $LoopTimeout, # timeout of event loop in milliseconds
64 $DoneInit, # if we've done the one-time module init yet
68 # this may be set to zero with old kernels
69 our $EPOLLEXCLUSIVE = EPOLLEXCLUSIVE;
72 #####################################################################
73 ### C L A S S M E T H O D S
74 #####################################################################
76 =head2 C<< CLASS->Reset() >>
84 $LoopTimeout = -1; # no timeout by default
87 $PostLoopCallback = undef;
91 # NOTE kqueue is close-on-fork, and we don't account for it, yet
92 # OTOH, we (public-inbox) don't need this sub outside of tests...
93 POSIX::close($$KQueue) if !$_io && $KQueue && $$KQueue >= 0;
96 $_io = undef; # close $Epoll
99 *EventLoop = *FirstTimeEventLoop;
102 =head2 C<< CLASS->SetLoopTimeout( $timeout ) >>
104 Set the loop timeout for the event loop to some value in milliseconds.
106 A timeout of 0 (zero) means poll forever. A timeout of -1 means poll and return
111 return $LoopTimeout = $_[1] + 0;
114 =head2 C<< CLASS->DebugMsg( $format, @args ) >>
116 Print the debugging message specified by the C<sprintf>-style I<format> and
121 my ( $class, $fmt, @args ) = @_;
123 printf STDERR ">>> $fmt\n", @args;
126 =head2 C<< CLASS->AddTimer( $seconds, $coderef ) >>
128 Add a timer to occur $seconds from now. $seconds may be fractional, but timers
129 are not guaranteed to fire at the exact time you ask for.
131 Returns a timer object which you can call C<< $timer->cancel >> on if you need to.
136 my ($secs, $coderef) = @_;
138 my $fire_time = Time::HiRes::time() + $secs;
140 my $timer = bless [$fire_time, $coderef], "PublicInbox::DS::Timer";
142 if (!@Timers || $fire_time >= $Timers[-1][0]) {
143 push @Timers, $timer;
147 # Now, where do we insert? (NOTE: this appears slow, algorithm-wise,
148 # but it was compared against calendar queues, heaps, naive push/sort,
149 # and a bunch of other versions, and found to be fastest with a large
150 # variety of datasets.)
151 for (my $i = 0; $i < @Timers; $i++) {
152 if ($Timers[$i][0] > $fire_time) {
153 splice(@Timers, $i, 0, $timer);
158 die "Shouldn't get here.";
161 # keeping this around in case we support other FD types for now,
162 # epoll_create1(EPOLL_CLOEXEC) requires Linux 2.6.27+...
163 sub set_cloexec ($) {
166 $_io = IO::Handle->new_from_fd($fd, 'r+') or return;
167 defined(my $fl = fcntl($_io, F_GETFD, 0)) or return;
168 fcntl($_io, F_SETFD, $fl | FD_CLOEXEC);
177 $KQueue = IO::KQueue->new();
178 $HaveKQueue = defined $KQueue;
180 *EventLoop = *KQueueEventLoop;
183 elsif (PublicInbox::Syscall::epoll_defined()) {
184 $Epoll = eval { epoll_create(1024); };
185 $HaveEpoll = defined $Epoll && $Epoll >= 0;
188 *EventLoop = *EpollEventLoop;
192 if (!$HaveEpoll && !$HaveKQueue) {
194 *EventLoop = *PollEventLoop;
198 =head2 C<< CLASS->EventLoop() >>
200 Start processing IO events. In most daemon programs this never exits. See
201 C<PostLoopCallback> below for how to exit the loop.
204 sub FirstTimeEventLoop {
210 EpollEventLoop($class);
211 } elsif ($HaveKQueue) {
212 KQueueEventLoop($class);
214 PollEventLoop($class);
218 # runs timers and returns milliseconds for next one, or next event loop
220 return $LoopTimeout unless @Timers;
222 my $now = Time::HiRes::time();
225 while (@Timers && $Timers[0][0] <= $now) {
226 my $to_run = shift(@Timers);
227 $to_run->[1]->($now) if $to_run->[1];
230 return $LoopTimeout unless @Timers;
232 # convert time to an even number of milliseconds, adding 1
233 # extra, otherwise floating point fun can occur and we'll
234 # call RunTimers like 20-30 times, each returning a timeout
235 # of 0.0000212 seconds
236 my $timeout = int(($Timers[0][0] - $now) * 1000) + 1;
238 # -1 is an infinite timeout, so prefer a real timeout
239 return $timeout if $LoopTimeout == -1;
241 # otherwise pick the lower of our regular timeout and time until
243 return $LoopTimeout if $LoopTimeout < $timeout;
247 ### The epoll-based event loop. Gets installed as EventLoop if IO::Epoll loads
255 my $timeout = RunTimers();
257 # get up to 1000 events
258 my $evcount = epoll_wait($Epoll, 1000, $timeout, \@events);
259 for ($i=0; $i<$evcount; $i++) {
260 my $ev = $events[$i];
262 # it's possible epoll_wait returned many events, including some at the end
263 # that ones in the front triggered unregister-interest actions. if we
264 # can't find the %sock entry, it's because we're no longer interested
266 my PublicInbox::DS $pob = $DescriptorMap{$ev->[0]};
268 my $state = $ev->[1];
270 DebugLevel >= 1 && $class->DebugMsg("Event: fd=%d (%s), state=%d \@ %s\n",
271 $ev->[0], ref($pob), $ev->[1], time);
273 # standard non-profiling codepat
274 $pob->event_read if $state & EPOLLIN && ! $pob->{closed};
275 $pob->event_write if $state & EPOLLOUT && ! $pob->{closed};
276 if ($state & (EPOLLERR|EPOLLHUP)) {
277 $pob->event_err if $state & EPOLLERR && ! $pob->{closed};
278 $pob->event_hup if $state & EPOLLHUP && ! $pob->{closed};
281 return unless PostEventLoop();
286 ### The fallback IO::Poll-based event loop. Gets installed as EventLoop if
287 ### IO::Epoll fails to load.
291 my PublicInbox::DS $pob;
294 my $timeout = RunTimers();
296 # the following sets up @poll as a series of ($poll,$event_mask)
297 # items, then uses IO::Poll::_poll, implemented in XS, which
298 # modifies the array in place with the even elements being
299 # replaced with the event masks that occured.
301 while ( my ($fd, $sock) = each %DescriptorMap ) {
302 push @poll, $fd, $sock->{event_watch};
305 # if nothing to poll, either end immediately (if no timeout)
306 # or just keep calling the callback
308 select undef, undef, undef, ($timeout / 1000);
309 return unless PostEventLoop();
313 my $count = IO::Poll::_poll($timeout, @poll);
314 unless ($count >= 0) {
315 return unless PostEventLoop();
319 # Fetch handles with read events
321 my ($fd, $state) = splice(@poll, 0, 2);
324 $pob = $DescriptorMap{$fd};
326 $pob->event_read if $state & POLLIN && ! $pob->{closed};
327 $pob->event_write if $state & POLLOUT && ! $pob->{closed};
328 $pob->event_err if $state & POLLERR && ! $pob->{closed};
329 $pob->event_hup if $state & POLLHUP && ! $pob->{closed};
332 return unless PostEventLoop();
338 ### The kqueue-based event loop. Gets installed as EventLoop if IO::KQueue works
340 sub KQueueEventLoop {
344 my $timeout = RunTimers();
345 my @ret = eval { $KQueue->kevent($timeout) };
347 # workaround https://rt.cpan.org/Ticket/Display.html?id=116615
348 if ($err =~ /Interrupted system call/) {
355 foreach my $kev (@ret) {
356 my ($fd, $filter, $flags, $fflags) = @$kev;
357 my PublicInbox::DS $pob = $DescriptorMap{$fd};
359 DebugLevel >= 1 && $class->DebugMsg("Event: fd=%d (%s), flags=%d \@ %s\n",
360 $fd, ref($pob), $flags, time);
362 $pob->event_read if $filter == IO::KQueue::EVFILT_READ() && !$pob->{closed};
363 $pob->event_write if $filter == IO::KQueue::EVFILT_WRITE() && !$pob->{closed};
364 if ($flags == IO::KQueue::EV_EOF() && !$pob->{closed}) {
372 return unless PostEventLoop();
378 =head2 C<< CLASS->SetPostLoopCallback( CODEREF ) >>
380 Sets post loop callback function. Pass a subref and it will be
381 called every time the event loop finishes.
383 Return 1 (or any true value) from the sub to make the loop continue, 0 or false
386 The callback function will be passed two parameters: \%DescriptorMap
389 sub SetPostLoopCallback {
390 my ($class, $ref) = @_;
393 # per-object callback
394 my PublicInbox::DS $self = $class;
395 if (defined $ref && ref $ref eq 'CODE') {
396 $PLCMap{$self->{fd}} = $ref;
398 delete $PLCMap{$self->{fd}};
402 $PostLoopCallback = (defined $ref && ref $ref eq 'CODE') ? $ref : undef;
406 # Internal function: run the post-event callback, send read events
407 # for pushed-back data, and close pending connections. returns 1
408 # if event loop should continue, or 0 to shut it all down.
410 # now we can close sockets that wanted to close during our event processing.
411 # (we didn't want to close them during the loop, as we didn't want fd numbers
412 # being reused and confused during the event loop)
413 while (my $sock = shift @ToClose) {
414 my $fd = fileno($sock);
416 # close the socket. (not a PublicInbox::DS close)
419 # and now we can finally remove the fd from the map. see
420 # comment above in _cleanup.
421 delete $DescriptorMap{$fd};
425 # by default we keep running, unless a postloop callback (either per-object
426 # or global) cancels it
427 my $keep_running = 1;
429 # per-object post-loop-callbacks
430 for my $plc (values %PLCMap) {
431 $keep_running &&= $plc->(\%DescriptorMap);
434 # now we're at the very end, call callback if defined
435 if (defined $PostLoopCallback) {
436 $keep_running &&= $PostLoopCallback->(\%DescriptorMap);
439 return $keep_running;
442 #####################################################################
443 ### PublicInbox::DS-the-object code
444 #####################################################################
446 =head2 OBJECT METHODS
448 =head2 C<< CLASS->new( $socket ) >>
450 Create a new PublicInbox::DS subclass object for the given I<socket> which will
451 react to events on it during the C<EventLoop>.
453 This is normally (always?) called from your subclass via:
455 $class->SUPER::new($socket);
459 my ($self, $sock, $exclusive) = @_;
460 $self = fields::new($self) unless ref $self;
462 $self->{sock} = $sock;
463 my $fd = fileno($sock);
465 Carp::cluck("undef sock and/or fd in PublicInbox::DS->new. sock=" . ($sock || "") . ", fd=" . ($fd || ""))
469 $self->{write_buf} = [];
470 $self->{write_buf_offset} = 0;
471 $self->{write_buf_size} = 0;
474 my $ev = $self->{event_watch} = POLLERR|POLLHUP|POLLNVAL;
480 $ev = $self->{event_watch} = EPOLLIN|EPOLLERR|EPOLLHUP|$EPOLLEXCLUSIVE;
483 if (epoll_ctl($Epoll, EPOLL_CTL_ADD, $fd, $ev)) {
484 if ($!{EINVAL} && ($ev & $EPOLLEXCLUSIVE)) {
485 $EPOLLEXCLUSIVE = 0; # old kernel
486 $ev = $self->{event_watch} = EPOLLIN|EPOLLERR|EPOLLHUP;
489 die "couldn't add epoll watch for $fd: $!\n";
492 elsif ($HaveKQueue) {
493 # Add them to the queue but disabled for now
494 $KQueue->EV_SET($fd, IO::KQueue::EVFILT_READ(),
495 IO::KQueue::EV_ADD() | IO::KQueue::EV_DISABLE());
496 $KQueue->EV_SET($fd, IO::KQueue::EVFILT_WRITE(),
497 IO::KQueue::EV_ADD() | IO::KQueue::EV_DISABLE());
500 Carp::cluck("PublicInbox::DS::new blowing away existing descriptor map for fd=$fd ($DescriptorMap{$fd})")
501 if $DescriptorMap{$fd};
503 $DescriptorMap{$fd} = $self;
508 #####################################################################
509 ### I N S T A N C E M E T H O D S
510 #####################################################################
512 =head2 C<< $obj->steal_socket() >>
514 Basically returns our socket and makes it so that we don't try to close it,
515 but we do remove it from epoll handlers. THIS CLOSES $self. It is the same
516 thing as calling close, except it gives you the socket to use.
520 my PublicInbox::DS $self = $_[0];
521 return if $self->{closed};
523 # cleanup does most of the work of closing this socket
526 # now undef our internal sock and fd structures so we don't use them
527 my $sock = $self->{sock};
528 $self->{sock} = undef;
532 =head2 C<< $obj->close( [$reason] ) >>
534 Close the socket. The I<reason> argument will be used in debugging messages.
538 my PublicInbox::DS $self = $_[0];
539 return if $self->{closed};
541 # print out debugging info for this close
543 my ($pkg, $filename, $line) = caller;
544 my $reason = $_[1] || "";
545 warn "Closing \#$self->{fd} due to $pkg/$filename/$line ($reason)\n";
548 # this does most of the work of closing us
551 # defer closing the actual socket until the event loop is done
552 # processing this round of events. (otherwise we might reuse fds)
554 push @ToClose, $self->{sock};
555 $self->{sock} = undef;
561 ### METHOD: _cleanup()
562 ### Called by our closers so we can clean internal data structures.
564 my PublicInbox::DS $self = $_[0];
566 # we're effectively closed; we have no fd and sock when we leave here
569 # we need to flush our write buffer, as there may
570 # be self-referential closures (sub { $client->close })
571 # preventing the object from being destroyed
572 $self->{write_buf} = [];
574 # if we're using epoll, we have to remove this from our epoll fd so we stop getting
575 # notifications about it
576 if ($HaveEpoll && $self->{fd}) {
577 if (epoll_ctl($Epoll, EPOLL_CTL_DEL, $self->{fd}, $self->{event_watch}) != 0) {
578 # dump_error prints a backtrace so we can try to figure out why this happened
579 $self->dump_error("epoll_ctl(): failure deleting fd=$self->{fd} during _cleanup(); $! (" . ($!+0) . ")");
583 # now delete from mappings. this fd no longer belongs to us, so we don't want
584 # to get alerts for it if it becomes writable/readable/etc.
585 delete $PLCMap{$self->{fd}};
587 # we explicitly don't delete from DescriptorMap here until we
588 # actually close the socket, as we might be in the middle of
589 # processing an epoll_wait/etc that returned hundreds of fds, one
590 # of which is not yet processed and is what we're closing. if we
591 # keep it in DescriptorMap, then the event harnesses can just
592 # looked at $pob->{closed} and ignore it. but if it's an
593 # un-accounted for fd, then it (understandably) freak out a bit
594 # and emit warnings, thinking their state got off.
596 # and finally get rid of our fd so we can't use it anywhere else
600 =head2 C<< $obj->sock() >>
602 Returns the underlying IO::Handle for the object.
606 my PublicInbox::DS $self = shift;
607 return $self->{sock};
610 =head2 C<< $obj->write( $data ) >>
612 Write the specified data to the underlying handle. I<data> may be scalar,
613 scalar ref, code ref (to run when there), or undef just to kick-start.
614 Returns 1 if writes all went through, or 0 if there are writes in queue. If
615 it returns 1, caller should stop waiting for 'writable' events)
619 my PublicInbox::DS $self;
623 # nobody should be writing to closed sockets, but caller code can
624 # do two writes within an event, have the first fail and
625 # disconnect the other side (whose destructor then closes the
626 # calling object, but it's still in a method), and then the
627 # now-dead object does its second write. that is this case. we
628 # just lie and say it worked. it'll be dead soon and won't be
630 return 1 if $self->{closed};
634 # just queue data if there's already a wait
638 $bref = ref $data ? $data : \$data;
639 if ($self->{write_buf_size}) {
640 push @{$self->{write_buf}}, $bref;
641 $self->{write_buf_size} += ref $bref eq "SCALAR" ? length($$bref) : 1;
645 # this flag says we're bypassing the queue system, knowing we're the
646 # only outstanding write, and hoping we don't ever need to use it.
647 # if so later, though, we'll need to queue
653 return 1 unless $bref ||= $self->{write_buf}[0];
657 $len = length($$bref); # this will die if $bref is a code ref, caught below
660 if (UNIVERSAL::isa($bref, "CODE")) {
661 unless ($need_queue) {
662 $self->{write_buf_size}--; # code refs are worth 1
663 shift @{$self->{write_buf}};
667 # code refs are just run and never get reenqueued
668 # (they're one-shot), so turn off the flag indicating the
669 # outstanding data needs queueing.
675 die "Write error: $@ <$bref>";
678 my $to_write = $len - $self->{write_buf_offset};
679 my $written = syswrite($self->{sock}, $$bref, $to_write,
680 $self->{write_buf_offset});
682 if (! defined $written) {
684 return $self->close("EPIPE");
685 } elsif ($! == EAGAIN) {
686 # since connection has stuff to write, it should now be
687 # interested in pending writes:
689 push @{$self->{write_buf}}, $bref;
690 $self->{write_buf_size} += $len;
692 $self->watch_write(1);
694 } elsif ($! == ECONNRESET) {
695 return $self->close("ECONNRESET");
698 DebugLevel >= 1 && $self->debugmsg("Closing connection ($self) due to write error: $!\n");
700 return $self->close("write_error");
701 } elsif ($written != $to_write) {
702 DebugLevel >= 2 && $self->debugmsg("Wrote PARTIAL %d bytes to %d",
703 $written, $self->{fd});
705 push @{$self->{write_buf}}, $bref;
706 $self->{write_buf_size} += $len;
708 # since connection has stuff to write, it should now be
709 # interested in pending writes:
710 $self->{write_buf_offset} += $written;
711 $self->{write_buf_size} -= $written;
712 $self->on_incomplete_write;
714 } elsif ($written == $to_write) {
715 DebugLevel >= 2 && $self->debugmsg("Wrote ALL %d bytes to %d (nq=%d)",
716 $written, $self->{fd}, $need_queue);
717 $self->{write_buf_offset} = 0;
718 $self->watch_write(0);
720 # this was our only write, so we can return immediately
721 # since we avoided incrementing the buffer size or
722 # putting it in the buffer. we also know there
723 # can't be anything else to write.
724 return 1 if $need_queue;
726 $self->{write_buf_size} -= $written;
727 shift @{$self->{write_buf}};
734 sub on_incomplete_write {
735 my PublicInbox::DS $self = shift;
736 $self->watch_write(1);
739 =head2 C<< $obj->read( $bytecount ) >>
741 Read at most I<bytecount> bytes from the underlying handle; returns scalar
742 ref on read, or undef on connection closed.
746 my PublicInbox::DS $self = shift;
747 return if $self->{closed};
750 my $sock = $self->{sock};
752 # if this is too high, perl quits(!!). reports on mailing lists
753 # don't seem to point to a universal answer. 5MB worked for some,
754 # crashed for others. 1MB works for more people. let's go with 1MB
756 my $req_bytes = $bytes > 1048576 ? 1048576 : $bytes;
758 my $res = sysread($sock, $buf, $req_bytes, 0);
759 DebugLevel >= 2 && $self->debugmsg("sysread = %d; \$! = %d", $res, $!);
761 if (! $res && $! != EWOULDBLOCK) {
762 # catches 0=conn closed or undef=error
763 DebugLevel >= 2 && $self->debugmsg("Fd \#%d read hit the end of the road.", $self->{fd});
770 =head2 (VIRTUAL) C<< $obj->event_read() >>
772 Readable event handler. Concrete deriviatives of PublicInbox::DS should
773 provide an implementation of this. The default implementation will die if
777 sub event_read { die "Base class event_read called for $_[0]\n"; }
779 =head2 (VIRTUAL) C<< $obj->event_err() >>
781 Error event handler. Concrete deriviatives of PublicInbox::DS should
782 provide an implementation of this. The default implementation will die if
786 sub event_err { die "Base class event_err called for $_[0]\n"; }
788 =head2 (VIRTUAL) C<< $obj->event_hup() >>
790 'Hangup' event handler. Concrete deriviatives of PublicInbox::DS should
791 provide an implementation of this. The default implementation will die if
795 sub event_hup { die "Base class event_hup called for $_[0]\n"; }
797 =head2 C<< $obj->event_write() >>
799 Writable event handler. Concrete deriviatives of PublicInbox::DS may wish to
800 provide an implementation of this. The default implementation calls
801 C<write()> with an C<undef>.
809 =head2 C<< $obj->watch_read( $boolean ) >>
811 Turn 'readable' event notification on or off.
815 my PublicInbox::DS $self = shift;
816 return if $self->{closed} || !$self->{sock};
819 my $event = $self->{event_watch};
821 $event &= ~POLLIN if ! $val;
822 $event |= POLLIN if $val;
824 # If it changed, set it
825 if ($event != $self->{event_watch}) {
827 $KQueue->EV_SET($self->{fd}, IO::KQueue::EVFILT_READ(),
828 $val ? IO::KQueue::EV_ENABLE() : IO::KQueue::EV_DISABLE());
831 epoll_ctl($Epoll, EPOLL_CTL_MOD, $self->{fd}, $event)
832 and $self->dump_error("couldn't modify epoll settings for $self->{fd} " .
833 "from $self->{event_watch} -> $event: $! (" . ($!+0) . ")");
835 $self->{event_watch} = $event;
839 =head2 C<< $obj->watch_write( $boolean ) >>
841 Turn 'writable' event notification on or off.
845 my PublicInbox::DS $self = shift;
846 return if $self->{closed} || !$self->{sock};
849 my $event = $self->{event_watch};
851 $event &= ~POLLOUT if ! $val;
852 $event |= POLLOUT if $val;
854 # If it changed, set it
855 if ($event != $self->{event_watch}) {
857 $KQueue->EV_SET($self->{fd}, IO::KQueue::EVFILT_WRITE(),
858 $val ? IO::KQueue::EV_ENABLE() : IO::KQueue::EV_DISABLE());
861 epoll_ctl($Epoll, EPOLL_CTL_MOD, $self->{fd}, $event)
862 and $self->dump_error("couldn't modify epoll settings for $self->{fd} " .
863 "from $self->{event_watch} -> $event: $! (" . ($!+0) . ")");
865 $self->{event_watch} = $event;
869 =head2 C<< $obj->dump_error( $message ) >>
871 Prints to STDERR a backtrace with information about this socket and what lead
872 up to the dump_error call.
878 while (my ($file, $line, $sub) = (caller($i++))[1..3]) {
879 push @list, "\t$file:$line called $sub\n";
882 warn "ERROR: $_[1]\n" .
883 "\t$_[0] = " . $_[0]->as_string . "\n" .
887 =head2 C<< $obj->debugmsg( $format, @args ) >>
889 Print the debugging message specified by the C<sprintf>-style I<format> and
894 my ( $self, $fmt, @args ) = @_;
895 confess "Not an object" unless ref $self;
898 printf STDERR ">>> $fmt\n", @args;
901 =head2 C<< $obj->as_string() >>
903 Returns a string describing this socket.
907 my PublicInbox::DS $self = shift;
908 my $rw = "(" . ($self->{event_watch} & POLLIN ? 'R' : '') .
909 ($self->{event_watch} & POLLOUT ? 'W' : '') . ")";
910 my $ret = ref($self) . "$rw: " . ($self->{closed} ? "closed" : "open");
914 package PublicInbox::DS::Timer;
915 # [$abs_float_firetime, $coderef];
922 =head1 AUTHORS (Danga::Socket)
924 Brad Fitzpatrick <brad@danga.com> - author
926 Michael Granger <ged@danga.com> - docs, testing
928 Mark Smith <junior@danga.com> - contributor, heavy user, testing
930 Matt Sergeant <matt@sergeant.org> - kqueue support, docs, timers, other bits