No description
This repository has been archived on 2026-08-22. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2010-06-03 23:27:50 +02:00
lib/Reflex check return value from the first send_packet/send_ack 2010-06-03 23:27:50 +02:00
script removed connection_class from example script 2010-06-03 22:14:09 +02:00
t do weaken when adding a connection. not on the server attribute 2010-06-03 22:09:10 +02:00
.gitignore do weaken when adding a connection. not on the server attribute 2010-06-03 22:09:10 +02:00
Changes check return value from the first send_packet/send_ack 2010-06-03 23:27:50 +02:00
Makefile.PL updated requirement list 2010-05-23 11:12:42 +02:00
README updated requirement list 2010-05-23 11:12:42 +02:00
README.markdown add README.markdown 2010-05-23 10:15:28 +02:00

NAME
    Reflex::TFTPd - Trivial File Transfer Protocol daemon

VERSION
    0.20

DESCRIPTION
    Reflex::TFTPd allows you to serve and receive files, using the <Trivial
    File Transfer Protocol>.

    This module does not do any checking on input data by its own, so you
    probably want to do some changes before using it. These changes can be
    done by subclassing Reflex::TFTPd::Connection. Since it is based on
    Moose and Reflex, it is also possible to modify the methods in this
    class using the meta protocol, but it is more sane to follow the
    "SYNOPSIS" below.

    The documentation for "ATTRIBUTES" and "METHODS" below, refers to the
    attribute and methods in Reflex::TFTPd::Role.

SYNOPSIS
        package MyTFTPServer::Connection;
        use Moose;
        extends 'Reflex::TFTPd::Connection';

        sub _build_filehandle {
            my $self = shift;
            my $file = $self->file;

            # verify $file (maybe it contains / or .. ?)
            # open file or return with empty list
            # can also do open $FH, '<', \$data_from_memory;

            return $FH ? $FH : undef;
        }

        sub logf {
            my($self, $level, $format, @args) = @_;

            # use Log::Log4perl or craft your own
            Log::Log4perl->get_logger->$level(sprintf $format, @args);
        }

        package MyTFTPServer;
        use Moose;

        with Reflex::TFTPd::Role => {
            mode => 'rw',
            connection_class => 'MyTFTPServer::Connection',
            check_connections => 1,
        };

        package main;

        my $tftpd = MyTFTPServer->new(
                        address => 'localhost',
                        port => 69,
                        max_connections => 100,
                    )->setup or die $@;

        $tftpd->run_all;

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
    Reflex::TFTPd::Connection::retries attribute.

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

  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.

  socket
    Holds the IO::INET::Socket object used as filehandle by POE.

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()".

  get_connection
    Might return a connection, identified by a "peername".

  add_connection
    Takes a connection object and adds it to the connection map. Can later
    be retrieved with "get_connection", using its
    Reflex::TFTPd::Connection::peername attribute value.

  get_all_connections
    Will return a list of all known Reflex::TFTPd::Connection objects.

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

     OPCODE_RRQ   self->on_connect() and connection->send_packet()
     OPCODE_WRQ   self->on_connect() and connection->send_ack()
     OPCODE_ACK   connection->receive_ack()
     OPCODE_DATA  connection->receive_packet()
     OPCODE_ERROR connection->logf()
     ~            connection->logf()

    It will also garbage collect connections and handle retries.

  on_error
    This method receives an error if data could not be retrieved from the
    socket. It will then re-create the socket, clear all connections, and
    hope for the best.

    This method is subject for change.

  on_connect
    This method returns a new Reflex::TFTPd::Connection object for a new
    connection. This method is called when either a RRQ/WRQ opcode is
    received in "on_datagram()".

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

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"