ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Async-Interrupt/Interrupt.pm
(Generate patch)

Comparing Async-Interrupt/Interrupt.pm (file contents):
Revision 1.21 by root, Thu Jul 30 03:59:47 2009 UTC vs.
Revision 1.37 by root, Tue Apr 17 19:24:32 2018 UTC

114callback just sets a global variable, as we are only interested in 114callback just sets a global variable, as we are only interested in
115synchronous signals (i.e. when the event loop polls), which is why the 115synchronous signals (i.e. when the event loop polls), which is why the
116pipe draining is not done automatically. 116pipe draining is not done automatically.
117 117
118 my $interrupt = new Async::Interrupt 118 my $interrupt = new Async::Interrupt
119 cb => sub { undef $SIGNAL_RECEIVED{$signum} } 119 cb => sub { undef $SIGNAL_RECEIVED{$signum} },
120 signal => $signum, 120 signal => $signum,
121 pipe => [$SIGPIPE->filenos], 121 pipe => [$SIGPIPE->filenos],
122 pipe_autodrain => 0, 122 pipe_autodrain => 0,
123 ; 123 ;
124 124
233use common::sense; 233use common::sense;
234 234
235BEGIN { 235BEGIN {
236 # the next line forces initialisation of internal 236 # the next line forces initialisation of internal
237 # signal handling variables, otherwise, PL_sig_pending 237 # signal handling variables, otherwise, PL_sig_pending
238 # etc. will be null pointers. 238 # etc. might be null pointers.
239 $SIG{KILL} = sub { }; 239 $SIG{KILL} = sub { };
240 240
241 our $VERSION = '1.0'; 241 our $VERSION = 1.24;
242 242
243 require XSLoader; 243 require XSLoader;
244 XSLoader::load ("Async::Interrupt", $VERSION); 244 XSLoader::load ("Async::Interrupt", $VERSION);
245} 245}
246 246
419might imply, do anything with POSIX signals). 419might imply, do anything with POSIX signals).
420 420
421C<$value> must be in the valid range for a C<sig_atomic_t>, except C<0> 421C<$value> must be in the valid range for a C<sig_atomic_t>, except C<0>
422(1..127 is portable). 422(1..127 is portable).
423 423
424=item $async->handle
425
426Calls the callback if the object is pending.
427
428This method does not need to be called normally, as it will be invoked
429automatically. However, it can be used to force handling of outstanding
430interrupts while the object is blocked.
431
432One reason why one might want to do that is when you want to switch
433from asynchronous interruptions to synchronous one, using e.g. an event
434loop. To do that, one would first C<< $async->block >> the interrupt
435object, then register a read watcher on the C<pipe_fileno> that calls C<<
436$async->handle >>.
437
438This disables asynchronous interruptions, but ensures that interrupts are
439handled by the event loop.
440
424=item $async->signal_hysteresis ($enable) 441=item $async->signal_hysteresis ($enable)
425 442
426Enables or disables signal hysteresis (default: disabled). If a POSIX 443Enables or disables signal hysteresis (default: disabled). If a POSIX
427signal is used as a signal source for the interrupt object, then enabling 444signal is used as a signal source for the interrupt object, then enabling
428signal hysteresis causes Async::Interrupt to reset the signal action to 445signal hysteresis causes Async::Interrupt to reset the signal action to
432When you expect a lot of signals (e.g. when using SIGIO), then enabling 449When you expect a lot of signals (e.g. when using SIGIO), then enabling
433signal hysteresis can reduce the number of handler invocations 450signal hysteresis can reduce the number of handler invocations
434considerably, at the cost of two extra syscalls. 451considerably, at the cost of two extra syscalls.
435 452
436Note that setting the signal to C<SIG_IGN> can have unintended side 453Note that setting the signal to C<SIG_IGN> can have unintended side
437effects when you fork and exec other programs, as often they do nto expect 454effects when you fork and exec other programs, as often they do not expect
438signals to be ignored by default. 455signals to be ignored by default.
439 456
440=item $async->block 457=item $async->block
441 458
442=item $async->unblock 459=item $async->unblock
495=item $fileno = $async->pipe_fileno 512=item $fileno = $async->pipe_fileno
496 513
497Returns the reading side of the signalling pipe. If no signalling pipe is 514Returns the reading side of the signalling pipe. If no signalling pipe is
498currently attached to the object, it will dynamically create one. 515currently attached to the object, it will dynamically create one.
499 516
500Note that the only valid oepration on this file descriptor is to wait 517Note that the only valid operation on this file descriptor is to wait
501until it is readable. The fd might belong currently to a pipe, a tcp 518until it is readable. The fd might belong currently to a pipe, a tcp
502socket, or an eventfd, depending on the platform, and is guaranteed to be 519socket, or an eventfd, depending on the platform, and is guaranteed to be
503C<select>able. 520C<select>able.
504 521
505=item $async->pipe_autodrain ($enable) 522=item $async->pipe_autodrain ($enable)
510draining. 527draining.
511 528
512This is useful when you want to share one pipe among many Async::Interrupt 529This is useful when you want to share one pipe among many Async::Interrupt
513objects. 530objects.
514 531
532=item $async->pipe_drain
533
534Drains the pipe manually, for example, when autodrain is disabled. Does
535nothing when no pipe is enabled.
536
515=item $async->post_fork 537=item $async->post_fork
516 538
517The object will not normally be usable after a fork (as the pipe fd is 539The object will not normally be usable after a fork (as the pipe fd is
518shared between processes). Calling this method after a fork in the child 540shared between processes). Calling this method after a fork in the child
519ensures that the object will work as expected again. It only needs to be 541ensures that the object will work as expected again. It only needs to be
536 558
537=back 559=back
538 560
539=head1 THE Async::Interrupt::EventPipe CLASS 561=head1 THE Async::Interrupt::EventPipe CLASS
540 562
541Pipes are the predominent utility to make asynchronous signals 563Pipes are the predominant utility to make asynchronous signals
542synchronous. However, pipes are hard to come by: they don't exist on the 564synchronous. However, pipes are hard to come by: they don't exist on the
543broken windows platform, and on GNU/Linux systems, you might want to use 565broken windows platform, and on GNU/Linux systems, you might want to use
544an C<eventfd> instead. 566an C<eventfd> instead.
545 567
546This class creates selectable event pipes in a portable fashion: on 568This class creates selectable event pipes in a portable fashion: on
576 598
577=item $epipe->drain 599=item $epipe->drain
578 600
579Drain (empty) the pipe. 601Drain (empty) the pipe.
580 602
603=item ($c_func, $c_arg) = $epipe->signal_func
604
581=item ($c_func, $c_arg) = $epipe->drain_func 605=item ($c_func, $c_arg) = $epipe->drain_func
582 606
583Returns a function pointer and C<void *> argument that can be called to 607These two methods returns a function pointer and C<void *> argument
584have the effect of C<< $epipe->drain >> on the XS level. 608that can be called to have the effect of C<< $epipe->signal >> or C<<
609$epipe->drain >>, respectively, on the XS level.
585 610
586It has the following prototype and needs to be passed the specified 611They both have the following prototype and need to be passed their
587C<$c_arg>, which is a C<void *> cast to C<IV>: 612C<$c_arg>, which is a C<void *> cast to an C<IV>:
588 613
589 void (*c_func) (void *c_arg) 614 void (*c_func) (void *c_arg)
590 615
591An example call would look like: 616An example call would look like:
592 617
593 c_func (c_arg); 618 c_func (c_arg);
594 619
595=item $epipe->renew 620=item $epipe->renew
596 621
597Recreates the pipe (useful after a fork). The reading side will not change 622Recreates the pipe (usually required in the child after a fork). The
598it's file descriptor number, but the writing side might. 623reading side will not change it's file descriptor number, but the writing
624side might.
599 625
600=item $epipe->wait 626=item $epipe->wait
601 627
602This method blocks the process until there are events on the pipe. This is 628This method blocks the process until there are events on the pipe. This is
603not a very event-based or ncie way of usign an event pipe, but it can be 629not a very event-based or ncie way of usign an event pipe, but it can be

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines