Net-Server-Coro

 view release on metacpan or  search on metacpan

lib/Net/Server/Coro.pm  view on Meta::CPAN

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    $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

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
    $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

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    }
 
    $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

248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
}
 
=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
 
=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.309 second using v1.01-cache-2.11-cpan-4e96b696675 )