GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Reflex::Role::Recving(3) User Contributed Perl Documentation Reflex::Role::Recving(3)

Reflex::Role::Recving - Mix standard send/recv code into a class.

This document describes version 0.100, released on April 02, 2017.

This UDP echo service comes from a more complete program, eg/eg-06-moose-roles.pl in Reflex's tarball.

TODO - New!

        package Reflex::UdpPeer::Echo;
        use Moose;
        with 'Reflex::Role::UdpPeer';

        sub on_udppeer_datagram {
                my ($self, $datagram) = @_;
                my $octets = $datagram->octets();

                if ($octets =~ /^\s*shutdown\s*$/) {
                        $self->destruct();
                        return;
                }

                $self->send(
                        octets => $octets,
                        peer   => $args->peer(),
                );
        }

        sub on_udppeer_error {
                my ($self, $args) = @_;
                warn "$args->{op} error $args->{errnum}: $args->{errstr}";
                $self->destruct();
        }

        1;

Programs may inherit from Reflex::UdpPeer rather than use the Moose role directly.

        package UdpEchoPeer;
        use base 'Reflex::UdpPeer';

        ...;

        1;

Reflex::Role::UdpPeer implements non-blocking UDP socket work. This isn't very hard, since UDP sockets don't normally block anyway.

Reflex::Role::UdpPeer will create a UDP socket during construction. The socket will be bound to the port (numeric or symbolic name) specified in the "port" attribute.

This may change in the future. Reflex really should be letting you create and provide your own handle, via a "handle" attribute, bound and otherwise set up how you like it.

"max_datagram_size" sets the limit for recv() calls. It defaults to 16KB (16384). This may change in the future.

Reflex::Role::UdpPeer's send() is a wrapper around Perl's built-in send() function. It checks the return value, and it will emit() an "error" message if send() fails.

This may also change, as the conventions for failure events solidify. Your feedback will help expedite the solidification.

destruct() clears the UDP peer's "handle" attribute and performs other cleanup to shut down the object.

The name will probably change to stop() or shutdown() as naming conventions standardize.

Reflex::Role::UdpPeer emits "datagram" events when datagrams arrive. These events include two named values: "datagram" contains the data returned by recv(). "remote_addr" holds the datagram sender's packed address.

Reflex::Role::UdpPeer will emit() an "error" event if send() fails. It follows a standard convention for reporting errors or failures. Errors include three fields: "errfun" describes the function that failed, generally "send" or "recv". "errnum" and "errstr" hold the numeric and stringified versions of $! at the time of the failure.

Programs should not examine $! directly, as the value of this global special variable may have changed between the time of failure and the time of callback.

Reflex generally uses "failure" rather than "error" to indicate failures. This "error" event may be renamed later to conform with that emerging conventino.

eg/eg-04-inheritance.pl inherits from Reflex::UdpPeer.

eg/eg-05-composition.pl uses a Reflex::UdpPeer object as a helper, and composes with it in a has-a relationship.

eg/eg-06-moose-roles.pl composes an ojbect with Reflex::Role::UdpPeer.

Please see those modules/websites for more information related to this module.
  • Reflex
  • Moose::Manual::Concepts
  • Reflex
  • Reflex::Base
  • Reflex::UdpPeer
  • "ACKNOWLEDGEMENTS" in Reflex
  • "ASSISTANCE" in Reflex
  • "AUTHORS" in Reflex
  • "BUGS" in Reflex
  • "BUGS" in Reflex
  • "CONTRIBUTORS" in Reflex
  • "COPYRIGHT" in Reflex
  • "LICENSE" in Reflex
  • "TODO" in Reflex

You can make new bug reports, and view existing ones, through the web interface at <http://rt.cpan.org/Public/Dist/Display.html?Name=Reflex>.

Rocco Caputo <rcaputo@cpan.org>

This software is copyright (c) 2017 by Rocco Caputo.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <http://www.perl.com/CPAN/> to find a CPAN site near you, or see <https://metacpan.org/module/Reflex/>.

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

2017-04-02 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.