GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  ANYEVENT::MOJO::SERVER::CONNECTION (3)

.ds Aq ’

NAME

AnyEvent::Mojo::Server::Connection - An active TCP connection to AnyEvent::Mojo::Server

CONTENTS

VERSION

version 0.8003

SYNOPSIS



    use AnyEvent::Mojo::Server::Connection;

    ...



DESCRIPTION

Foreach connection to a AnyEvent::Mojo::Server , a AnyEvent::Mojo::Server::Connection object is created.

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.

METHODS

    new

The constructor accepts the following parameters:
sock The client socket.
peer_host The IP of the client.
peer_port The TCP port number of the client.
server The AnyEvent::Mojo::Server to whom this connection belongs to.
timeout 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.

    run

The run() method starts all the AnyEvent::Handle processing to read the next request, process it and write the response.

It returns nothing.

    close

The close() method clears the current transaction, destroys the AnyEvent::Handle associated with this connection and closes the client socket.

    request_count

Returns the total request count for the connection. In case of keep-alive requests, the request count grows beyond 1.

    peer_host

Returns the IP address of the peer host.

    peer_port

Returns the TCP port number of the peer host.

ASYNCHRONOUS PROCESSING

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.

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:



    # 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->();
    };



pause()

Pauses the current transaction.

The transaction state must be write, that is, before sending any status or header responses.

While the connection is paused, inactivity timeouts are ignored.

Returns a coderef that, when called, will resume the transaction.

resume()

Resumes a paused transaction.

The response must be complete and we will immediatly start sending the data to the client.

Returns nothing.

AUTHOR

Pedro Melo, <melo at cpan.org>

COPYRIGHT & LICENSE

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.

POD ERRORS

Hey! <B>The above document had some coding errors, which are explained below:B>
Around line 243: L<> starts or ends with whitespace
Around line 246: L<> starts or ends with whitespace
Around line 278: L<> starts or ends with whitespace
Around line 300: L<> starts or ends with whitespace
Around line 309: L<> starts or ends with whitespace
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 ANYEVENT::MOJO::SERVER::CONNECTION (3) 2009-10-10

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.