AnyEvent::Mojo::Server::Connection - An active TCP connection to AnyEvent::Mojo::Server
version 0.8003
use AnyEvent::Mojo::Server::Connection; ...
Foreach connection to a " AnyEvent::Mojo::Server ", a AnyEvent::Mojo::Server::Connection object is created.
AnyEvent::Mojo::Server::Connection
This object keeps track of the current " Mojo::Transaction ".
If an error or EOF condition is detected while reading or writting to the client socket, or in case of a timeout, the socket is disconnected.
The constructor accepts the following parameters:
The client socket.
The IP of the client.
The TCP port number of the client.
The " AnyEvent::Mojo::Server " to whom this connection belongs to.
Seconds (can be fractional) that the connection can be idle (waiting for a request or unable to write more data out).
If the connection is paused, the timeout is ignored.
If the timeout fires, the connection is closed.
It returns the AnyEvent::Mojo::Server::Connection object.
The run() method starts all the " AnyEvent::Handle " processing to read the next request, process it and write the response.
run()
It returns nothing.
The close() method clears the current transaction, destroys the " AnyEvent::Handle " associated with this connection and closes the client socket.
close()
Returns the total request count for the connection. In case of keep-alive requests, the request count grows beyond 1.
Returns the IP address of the peer host.
Returns the TCP port number of the peer host.
While in the middle of a request, an application can pause the current transaction, do something else (including dealing with other requests) and then resume the processing.
To do that, you application must call the $tx-connection->pause()> method.
$tx-
When you are ready to send back the response, call $tx-connection->resume()>.
For example:
# inside your response handler of you Mojo::App $tx->connection->pause(); # Call webservice and deal with result http_get 'http://my.webservice.endpoint/api', sub { my ($data) = @_; $tx->response->body("Webservice returned this: '$data'"); $tx->connection->resume(); };
To make it easier to resume later, the pause() method returns a coderef that will resume the transaction when called. So the code above could be written like this:
pause()
# inside your response handler of you Mojo::App my $resume_cb = $tx->connection->pause(); # Call webservice and deal with result http_get 'http://my.webservice.endpoint/api', sub { my ($data) = @_; $tx->response->body("Webservice returned this: '$data'"); $resume_cb->(); };
Pauses the current transaction.
The transaction state must be write, that is, before sending any status or header responses.
write
While the connection is paused, inactivity timeouts are ignored.
Returns a coderef that, when called, will resume the transaction.
Resumes a paused transaction.
The response must be complete and we will immediatly start sending the data to the client.
Returns nothing.
Pedro Melo, <melo at cpan.org>
<melo at cpan.org>
Copyright 2008-2009 Pedro Melo.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
5 POD Errors
The following errors were encountered while parsing the POD:
L<> starts or ends with whitespace
To install AnyEvent::Mojo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Mojo
CPAN shell
perl -MCPAN -e shell install AnyEvent::Mojo
For more information on module installation, please visit the detailed CPAN module installation guide.