AnyEvent::TFTPd - Trivial File Transfer Protocol daemon


NAME

AnyEvent::TFTPd - Trivial File Transfer Protocol daemon


VERSION

0.11


DESCRIPTION

This module handles TFTP request in an AnyEvent environment. It will set up a socket, handled by the AnyEvent::Handle::UDP manpage. Every time a new packet has arrived, it will call on_read() which handles the request. The rest is up to the the AnyEvent::TFTPd::Connection manpage object, which is possible to customize either by subclassing or modifying with Moose.

Want timeout mechanism? See the AnyEvent::TFTPd::CheckConnections manpage.


SYNOPSIS

 package My::AnyEvent::Connection;
 use Moose;
 extends 'AnyEvent::TFTPd::Connection';
 sub _build_filehandle {
    my $self = shift;
    my $file = $self->file;
    # ...
    return $filehandle;
     }
 package main;
 my $tftpd = AnyEvent::TFTPd->new(
                 address => 'localhost',
                 port => 69,
                 connection_class => 'My::AnyEvent::Connection',
                 max_connections => 100,
             )->setup or die $@;


ATTRIBUTES

address

Holds the address this server should bind to. Default is "127.0.0.1".

port

Holds the default port this server should listen to. Default is 69.

retries

This value will never be changes. It is used as default for the the AnyEvent::TFTPd::Connection::retries manpage attribute.

Default number of retries are 3. (default value is subject for change)

connection_class

This string holds the classname where the connection objects should be constructed from. The default the AnyEvent::TFTPd::Connection manpage class is quite useless without subclassing it. See SYNOPSIS for more details.

max_connections

The max concurrent connections this object can handle. Used inside on_connect() to decide if a new connection should be establised or not.

Setting this to zero (the default) means that the server should handle unlimited connections.

_connections

 $connection_obj = $self->get_connection(peername);
 $connection_obj = $self->add_connection($connection_obj);
 @connections = $self->get_all_connections;

This attribute holds a hash-ref, where the keys are peername() of the connections, and the values point to the AnyEvent::TFTPd::Connection manpage objects. Use the delegated methods listed above to access this attribute.

_handle

 $io_socket_inet = $self->socket;
 $packed = $self->peername;

This attribute holds an instance of the AnyEvent::Handle::UDP manpage, which handles the methods listed above.


METHODS

setup

This method will prepare the handle/socket for incoming connections. It will return c<$self> on success and 0 on failure. Check $@ for a full error message on failure.

Return value $self allows you to chain new() and setup().

on_read

This hook is called each time data is received from a peer host. It will parse the datagram received and act accordingly.

on_connect

This method returns a new the AnyEvent::TFTPd::Connection manpage object for a new connection. This method is called when either a RRQ/WRQ opcode is received in on_read().

This method might skip these steps if no more connections are available. This is computed by comparing the number of connections and max_connections.

on_error

This hook is called from the handler, when something unexpected has happened. See the AnyEvent::Handle manpage for details.


COPYRIGHT & LICENSE

Copyright 2007 Jan Henning Thorsen, all rights reserved.

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


AUTHOR

Jan Henning Thorsen jhthorsen at cpan.org

 AnyEvent::TFTPd - Trivial File Transfer Protocol daemon