NAME
Mojo::TFTPd - Trivial File Transfer Protocol daemon
VERSION
0.04
SYNOPSIS
use Mojo::TFTPd;
my $tftpd = Mojo::TFTPd->new;
$tftpd->on(error => sub {
warn "TFTPd: $_[1]\n";
});
$tftpd->on(rrq => sub {
my($tftpd, $c) = @_;
open my $FH, '<', $c->file;
$c->filehandle($FH);
$c->filesize(-s $c->file);
});
$tftpd->on(wrq => sub {
my($tftpd, $c) = @_;
open my $FH, '>', '/dev/null';
$c->filehandle($FH);
});
$tftpd->on(finish => sub {
my($tftpd, $c, $error) = @_;
warn "Connection: $error\n" if $error;
});
$tftpd->start;
$tftpd->ioloop->start unless $tftpd->ioloop->is_running;
DESCRIPTION
This module implements a server for the Trivial File Transfer Protocol
<http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol>.
From Wikipedia:
Trivial File Transfer Protocol (TFTP) is a file transfer protocol notable
for its simplicity. It is generally used for automated transfer of
configuration or boot files between machines in a local environment.
The connection ($c) which is referred to in this document is an instance
of Mojo::TFTPd::Connection.
EVENTS
error
$self->on(error => sub {
my($self, $str) = @_;
});
This event is emitted when something goes wrong: Fail to "listen" to
socket, read from socket or other internal errors.
finish
$self->on(finish => sub {
my($self, $c, $error) = @_;
});
This event is emitted when the client finish, either successfully or due
to an error. $error will be an empty string on success.
rrq
$self->on(rrq => sub {
my($self, $c) = @_;
});
This event is emitted when a new read request arrives from a client. The
callback should set "filehandle" in Mojo::TFTPd::Connection or the
connection will be dropped. "filehandle" in Mojo::TFTPd::Connection can
also be a Mojo::Asset reference.
wrq
$self->on(wrq => sub {
my($self, $c) = @_;
});
This event is emitted when a new write request arrives from a client.
The callback should set "filehandle" in Mojo::TFTPd::Connection or the
connection will be dropped. "filehandle" in Mojo::TFTPd::Connection can
also be a Mojo::Asset reference.
ATTRIBUTES
connection_class
$str = $self->connection_class;
$self = $self->connection_class($str);
Used to set a custom connection class. Defaults to
Mojo::TFTPd::Connection.
ioloop
Holds an instance of Mojo::IOLoop.
listen
$str = $self->server;
$self->server("127.0.0.1:69");
$self->server("tftp://*:69"); # any interface
The bind address for this server.
max_connections
How many concurrent connections this server can handle. Default to 1000.
retries
How many times the server should try to send ACK or DATA to the client
before dropping the connection.
inactive_timeout
How long a connection can stay idle before being dropped. Default is 15
seconds.
retransmit
How many times the server should try to retransmit the last packet on
timeout before dropping the connection. Default is 0 (disable
retransmits)
retransmit_timeout
How long a connection can stay idle before last packet being
retransmitted. Default is 2 seconds.
METHODS
start
Starts listening to the address and port set in "Listen". The "error"
event will be emitted if the server fail to start.
AUTHOR
Svetoslav Naydenov - "harryl@cpan.org"
Jan Henning Thorsen - "jhthorsen@cpan.org"