Acme-Sort-Sleep
view release on metacpan or search on metacpan
local/lib/perl5/IO/Async/Socket.pm view on Meta::CPAN
=cut
sub _init
{
my $self = shift;
$self->{recv_len} = 65536;
$self->SUPER::_init( @_ );
}
=head1 PARAMETERS
The following named parameters may be passed to C<new> or C<configure>:
=head2 read_handle => IO
The IO handle to receive from. Must implement C<fileno> and C<recv> methods.
=head2 write_handle => IO
The IO handle to send to. Must implement C<fileno> and C<send> methods.
=head2 handle => IO
Shortcut to specifying the same IO handle for both of the above.
=head2 on_recv => CODE
=head2 on_recv_error => CODE
=head2 on_outgoing_empty => CODE
=head2 on_send_error => CODE
=head2 autoflush => BOOL
Optional. If true, the C<send> method will atempt to send data to the
operating system immediately, without waiting for the loop to indicate the
filehandle is write-ready.
=head2 recv_len => INT
Optional. Sets the buffer size for C<recv> calls. Defaults to 64 KiB.
=head2 recv_all => BOOL
Optional. If true, repeatedly call C<recv> when the receiving handle first
becomes read-ready. By default this is turned off, meaning at most one
fixed-size buffer is received. If there is still more data in the kernel's
buffer, the handle will stil be readable, and will be received from again.
This behaviour allows multiple streams and sockets to be multiplexed
simultaneously, meaning that a large bulk transfer on one cannot starve other
filehandles of processing time. Turning this option on may improve bulk data
transfer rate, at the risk of delaying or stalling processing on other
filehandles.
=head2 send_all => INT
Optional. Analogous to the C<recv_all> option, but for sending. When
C<autoflush> is enabled, this option only affects deferred sending if the
initial attempt failed.
The condition requiring an C<on_recv> handler is checked at the time the
object is added to a Loop; it is allowed to create a C<IO::Async::Socket>
object with a read handle but without a C<on_recv> handler, provided that
one is later given using C<configure> before the stream is added to its
containing Loop, either directly or by being a child of another Notifier
already in a Loop, or added to one.
=cut
sub configure
{
my $self = shift;
my %params = @_;
for (qw( on_recv on_outgoing_empty on_recv_error on_send_error
recv_len recv_all send_all autoflush )) {
$self->{$_} = delete $params{$_} if exists $params{$_};
}
$self->SUPER::configure( %params );
if( $self->loop and defined $self->read_handle ) {
$self->can_event( "on_recv" ) or
croak 'Expected either an on_recv callback or to be able to ->on_recv';
}
}
sub _add_to_loop
{
my $self = shift;
if( defined $self->read_handle ) {
$self->can_event( "on_recv" ) or
croak 'Expected either an on_recv callback or to be able to ->on_recv';
}
$self->SUPER::_add_to_loop( @_ );
}
=head1 METHODS
=cut
=head2 send
$socket->send( $data, $flags, $addr )
This method adds a segment of data to be sent, or sends it immediately,
according to the C<autoflush> parameter. C<$flags> and C<$addr> are optional.
If the C<autoflush> option is set, this method will try immediately to send
the data to the underlying filehandle, optionally using the given flags and
destination address. If this completes successfully then it will have been
sent by the time this method returns. If it fails to send, then the data is
queued as if C<autoflush> were not set, and will be flushed as normal.
=cut
( run in 0.471 second using v1.01-cache-2.11-cpan-39bf76dae61 )