The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

=head1 NAME

Net::SIP::NATHelper::Server - server for Net::SIP::NATHelper::Client

=head1 DESCRIPTION

This module is a wrapper around L<Net::SIP::NATHelper::Base> and
will receive it's instructions from L<Net::SIP::NATHelper::Client>
using RPC via sockets.

=head1 CONSTRUCTOR

=over 4

=item new ( [ HELPER ], @FDS )

Will create an object which listens on all file descriptors
given in FDS for RPC from clients.

If HELPER is given and a L<Net::SIP::NATHelper::Base> object
or derived it will be used, otherwise the helper will be created.

=back

=head1 METHODS

=over 4

=item do_command ( FD )

Called when FD is available for reading.
Calls B<accept> on FD and reads the RPC packet from the
resulting file descriptor, executes it and returns result back.

Currently implemented commands are "allocate","activate" and
"close" which will map to the local methods B<allocate_sockets>,
B<activate_session> and B<close_session>.

One might redefine or add commands by changing C<< $self->{commands} >>.
The key of this hash reference is the command name and the value
is the callback.

Unknown commands will be ignored, e.g nothing returned.

=item loop

This will loop over all file descriptors it gets from B<callbacks>
in L<Net::SIP::NATHelper::Base> and the file descriptors for
the RPC sockets.

When file descriptors gets available for reading it will execute
the callbacks, e.g. forward the RTP data or call B<do_command>.
In regular intervals it will call B<expire> from L<Net::SIP::NATHelper::Base>
to expire the RTP sockets and sessions.

=item allocate_sockets ( ... )

Calls B<allocate_sockets> of the local L<Net::SIP::NATHelper::Base>
object. Takes and returns the same arguments.

=item activate_session ( ... )

Calls B<activate_session> of the local L<Net::SIP::NATHelper::Base>
object. Takes the same arguments and returns 1 if the session was
newly activated, -1 if it was activated before and false if activation failed.
Updates callbacks into the event loop.

=item close_session ( ... )

Calls B<activate_session> of the local L<Net::SIP::NATHelper::Base>
object. Takes the same arguments and returns the number of closed
sessions.
Updates callbacks into the event loop.

=item expire ( ... )

Calls B<expire> of the local L<Net::SIP::NATHelper::Base>
object. Takes the same arguments and returns the number of expired
sessions.
Updates callbacks into the event loop if necessary.

=back

=head1 BUGS

The local event loop should be pluggable, so that other implementations
could be used. Right now it's a hard coded loop using select.