Net-Server-Coro
view release on metacpan or search on metacpan
lib/Net/Server/Coro.pm view on Meta::CPAN
$self->server_key($args{'server_key'}) if exists $args{'server_key'};
return $self;
}
sub post_bind_hook {
my $self = shift;
my $prop = $self->{server};
delete $prop->{select};
# set up coro::specific variables
foreach my $key (qw(client sockaddr sockport sockhost peeraddr peerport peerhost peername)) {
tie $prop->{$key}, Coro::Specific::;
}
}
=head2 proto_object HOST, PORT, PROTO
Wraps socket creation, turning all socket types into
L<Net::Server::Proto::Coro> objects.
lib/Net/Server/Coro.pm view on Meta::CPAN
$socket = Net::Server::Proto::Coro->new_from_fh(
$socket,
forward_class => ref($socket),
server_cert => $self->server_cert,
server_key => $self->server_key,
expects_ssl => $is_ssl,
);
return $socket;
}
sub coro_instance {
my $self = shift;
my $fh = shift;
my $prop = $self->{server};
$Coro::current->desc("Active connection");
$prop->{client} = $fh;
$self->run_client_connection;
}
sub get_client_info {
my $self = shift;
lib/Net/Server/Coro.pm view on Meta::CPAN
}
$self->log(3, $self->log_time
." CONNECT ".$client->NS_proto
." Peer: \"[$prop->{'peeraddr'}]:$prop->{'peerport'}\""
." Local: \"[$prop->{'sockaddr'}]:$prop->{'sockport'}\"") if $prop->{'log_level'} && 3 <= $prop->{'log_level'};
}
=head2 loop
The main loop uses starts a number of L<Coro> coroutines:
=over 4
=item *
One for each listening socket.
=item *
One for each active connection. Since these may respawn on a firlay
frequent basis, L<Coro/async_pool> is used to maintain a pool of
coroutines.
=item *
An L<AnyEvent> infinite wait, which equates to the "run the event loop."
=back
=cut
sub loop {
my $self = shift;
my $prop = $self->{server};
$prop->{no_client_stdout} = 1;
for my $socket ( @{ $prop->{sock} } ) {
async {
$Coro::current->desc("Listening on port @{[$socket->sockport]}");
while (1) {
my $accepted = scalar $socket->accept;
next unless $accepted;
async_pool \&coro_instance, $self, $accepted;
}
};
}
async {
# We want this to be higher priority so it gets timeslices
# when other things cede; this guarantees that we notice
# socket activity and deal.
$Coro::current->prio(3);
lib/Net/Server/Coro.pm view on Meta::CPAN
}
=head1 DEPENDENCIES
L<Coro>, L<AnyEvent>, L<Net::Server>
=head1 BUGS AND LIMITATIONS
The client filehandle, socket, and peer information all use
L<Coro::Specific> in order to constrain their information to their
coroutine. Attempting to access them from a different coroutine will
yield possibly unexpected results.
Generally, all those of L<Coro>. Please report any bugs or feature
requests specific to L<Net::Server::Coro> to
C<bug-net-server-coro@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.
=head1 AUTHORS
Alex Vandiver C<< <alexmv@bestpractical.com> >>; code originally from
Audrey Tang C<< <cpan@audreyt.org> >>
=head1 COPYRIGHT
Copyright 2006 by Audrey Tang <cpan@audreyt.org>
( run in 0.438 second using v1.01-cache-2.11-cpan-c6e0e5ac2a7 )