| IO::Async::Notifier |
parent()children()
IO::Async::Notifier - event callbacks for a non-blocking file descriptor
use IO::Socket::INET; use IO::Async::Notifier;
my $socket = IO::Socket::INET->new( LocalPort => 1234, Listen => 1 );
my $notifier = IO::Async::Notifer->new(
handle => $socket,
on_read_ready => sub {
my $new_client = $socket->accept();
...
},
);
my $loop = IO::Async::Loop::... $loop->add( $notifier );
For most other uses with sockets, pipes or other filehandles that carry a byte
stream, the IO::Async::Stream class is likely to be more suitable.
This module provides a base class for implementing non-blocking IO on file
descriptors. The object provides ways to integrate with existing asynchronous
IO handling code, by way of the various IO::Async::Loop::* collection
classes.
This object may be used in one of two ways; with callback functions, or as a base class.
If the on_read_ready or on_write_ready keys are supplied in the
constructor, they should contain CODE references to callback functions to be
called when the underlying IO handle becomes readable or writable:
$on_read_ready->( $self )
$on_write_ready->( $self )
Optionally, an on_closed key can also be specified, which will be called
when the close method is invoked. This is intended for subclasses.
$on_closed->( $self )
If a subclass is built, then it can override the on_read_ready or
on_write_ready methods of the base to perform its work. In this case, it
should not call the SUPER:: versions of those methods.
$self->on_read_ready()
$self->on_write_ready()
If either of the readyness methods calls the close() method, then
the handle is internally marked as closed within the object.
This function returns a new instance of a IO::Async::Notifier object.
The %params hash takes the following keys:
The reading and writing IO handles. Each must implement the fileno method.
At most one of read_handle or write_handle is allowed to be undef.
Primarily used for passing STDIN / STDOUT; see the SYNOPSIS section of
IO::Async::Stream for an example.
The IO handle for both reading and writing; instead of passing each separately
as above. Must implement fileno method in way that IO::Handle does.
CODE references to handlers for when the handle becomes read-ready or write-ready. If these are not supplied, subclass methods will be called instead.
CODE reference to the handler for when the handle becomes closed.
It is required that at on_read_ready or on_write_ready are provided for
any handle that is provided; either as a callback reference or that the object
is a subclass that overrides the method. I.e. if only a read_handle is
given, then on_write_ready can be absent. If handle is used as a
shortcut, then both read and write-ready callbacks or methods are required.
This method calls close on the underlying IO handles. This method will will
remove the notifier from its containing loop.
These accessors return the underlying IO handles.
These accessors return the file descriptor numbers of the underlying IO handles.
This accessor returns the IO::Async::Loop object to which this notifier
belongs.
These are the accessor for the want_readready and want_writeready
properties, which define whether the object is interested in knowing about
read- or write-readiness on the underlying file handle.
During the execution of a program, it may be the case that certain IO handles
cause other handles to be created; for example, new sockets that have been
accept()ed from a listening socket. To facilitate these, a notifier may
contain child notifier objects, that are automatically added to or removed
from the IO::Async::Loop that manages their parent.
parent()Returns the parent of the notifier, or undef if does not have one.
children()Returns a list of the child notifiers contained within this one.
Adds a child notifier. This notifier will be added to the containing loop, if the parent has one. Only a notifier that does not currently have a parent and is not currently a member of any loop may be added as a child. If the child itself has grandchildren, these will be recursively added to the containing loop.
Removes a child notifier. The child will be removed from the containing loop, if the parent has one. If the child itself has grandchildren, these will be recurively removed from the loop.
the IO::Handle manpage - Supply object methods for I/O handles
Paul Evans <leonerd@leonerd.org.uk>
| IO::Async::Notifier |