AnyEvent::Handle::UDP - client/server UDP handles for AnyEvent
This module is an abstraction around UDP sockets for use with AnyEvent.
The callback for when a package arrives. It takes three arguments: the datagram, the handle and the address the datagram was received from.
The callback for when an error occurs. It takes three arguments: the handle, a boolean indicating the error is fatal or not, and the error message.
This sets the callback that is called when the send buffer becomes empty. The callback takes the handle as its only argument.
Always attempt to send data to the operating system immediately, without waiting for the loop to indicate the filehandle is write-ready.
The buffer size for the receiving in bytes. It defaults to 1500, which is slightly more than the MTA on ethernet.
Sets the socket family.
The default is
which means either IPv4 or IPv6.
6 mean IPv4 and IPv6 respectively.
The underlying filehandle.
then these enables an "inactivity" timeout: whenever this many seconds pass without a successful read or write on the underlying file handle (or a call to
the on_timeout callback will be invoked (and if that one is missing,
a non-fatal ETIMEDOUT error will be raised).
There are three variants of the timeouts that work independently of each other, for both read and write (triggered when nothing was read OR written), just read (triggered when nothing was read), and just write: timeout, rtimeout and wtimeout, with corresponding callbacks on_timeout, on_rtimeout and on_wtimeout, and reset functions timeout_reset, rtimeout_reset, and wtimeout_reset.
Note that timeout processing is active even when you do not have any outstanding read or write requests: If you plan to keep the connection idle then you should disable the timeout temporarily or ignore the timeout in the corresponding on_timeout callback, in which case AnyEvent::Handle will simply restart the timeout.
clear_timeout (or setting it to zero,
which does the same) disables the corresponding timeout.
The callback that's called whenever the inactivity timeout passes. If you return from this callback, then the timeout will be reset as if some activity had happened, so this condition is not fatal in any way.
Create a new UDP handle. As arguments it accepts any attribute, as well as these two:
Set the address to which datagrams are sent by default, and the only address from which datagrams are received. It must be either a packed sockaddr struct or an arrayref containing a hostname and a portnumber.
The address to bind the socket to. It must be either a packed sockaddr struct or an arrayref containing a hostname and a portnumber.
All are optional,
though using either
bind (or both) is strongly recommended unless you give it a connected/bound
Bind to the specified addres.
Note that a bound socket may be rebound to another address.
$address must be in the same form as the bind argument to new.
Connect to the specified address.
Note that a connected socket may be reconnected to another address.
$address must be in the same form as the connect argument to new.
Try to send a message.
If a socket is not connected a receptient address must also be given.
If it is connected giving a receptient may not work as expected,
depending on your platform.
which will become true when
$message is sent.
Reset the activity timeout, as if data was received or sent.
Destroy the handle.
This module is not backwards compatible in any way with the previous module of the same name by Jan Henning Thorsen. That module was broken by AnyEvent itself and now considered defunct.
Leon Timmermans <firstname.lastname@example.org>
This software is copyright (c) 2011 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.