NAME

AnyEvent::TFTPd::Connection - Represents one connection to TFTPd

DESCRIPTION

SYNOPSIS

ATTRIBUTES

peername

Holds the sockaddr of the remote host.

address

Holds a human readable version of the address part of "peername".

port

Holds a human readable version of the port part of "peername".

opcode

A numeric representation of the opcode which initiated the connection.

mode

Either "ascii" or "octet" or empty string if unknown.

file

A string representing the requested file from client.

filehandle

The filehandle used to read/write data from/to client.

rfc

Contains extra parameters the client has provided. These parameters are stored in a hash ref.

server

A reference back to the AnyEvent::TFTPd object.

connected_at

The time the connection was established: Epoch timestamp.

packet_number

The current packet number received/sent.

last_seen_peer

The last time data was received from the peer: Epoch timestamp. This value is used to calculate when to time out a connection.

retries

The number of retries left before aborting the transmission. This number will be reset to AnyEvent::TFTPd::retries each time "last_seen_peer" is updated.

METHODS

send_packet

This method will send a packet of data from "filehandle" to client, identified by "peername". The packet is calculated using the MIN_BLKSIZE and "packet_number". Returns 1 on success, 2 if this is the last packet to be sent, 0 if something went wrong and -1 if no more data is available from filehandle.

receive_ack

This method will receive a datagram and unwraps the packet number from it using unpack("n"). It will increase the "packet_number" if the received packet number matches "packet_number".

Will always call "send_packet" and return the value it returns. A return value of -1 indicates that the last ACK was received and the connection can be "shut down".

receive_packet

This method will receive a datagram and unwraps the packet number and body from it using unpack("na*"). It stores the data in the current filehandle if the packet number equals "packet_number". It returns 1 on success, 0 on failure and -1 if this was the last packet to be received. The latter indicates that it is safe for this connection to "shut down".

send_ack

This method is called inside "receive_packet()" and is used to tell the peer that a packet is received.

send_error

Takes a "name" indicating a type of error, which is looked up from the %ERROR_CODES variable (see the source for details). Falls back to "not_defined", if an invalid name was passed on. Packs the data from %ERROR_CODES and pass it to the remote client. Returns 1 on success and 1 on failure.

logf

$self->logf($level => @message);

Receives a $level and a list of strings, suitable for printf(): The first element in @message is a format and the rest (if exists) will be the replacement for %s and friends in the format. The level has the same name as defined for Log::Log4perl.

BUGS

COPYRIGHT & LICENSE

AUTHOR

See Top::Module.