Galimov Albert > MR-AsyncHTTP-0.01 > MR::AsyncHTTP

Download:
MR-AsyncHTTP-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

MR::AsyncHTTP - A zero-overhead Perl module for requesting HTTP in async manner, without event pools

SYNOPSIS ^

  use MR::AsyncHTTP;
  my $asynchttp = new MR::AsyncHTTP( connect_timeout=>0.6 );

  # Send a request, dont wait answer right now
  my $req_id = $asynchttp->send_get( "http://example.com/" );

  #..work with something else..
  my $res = $asynchttp->check_response($req_id);
  if( !$res ) {
    # Not ready yet, work on something other
  }
  
  #..Finally, wait it.
  my $res = $asynchttp->wait($req_id);

  #..Send a couple of requests
  for(1..5) {
    $asynchttp->send_get( "http://example.com/request/".$_ );
  }

  #Dedicate some time for sysread() to free buffers
  $asynchttp->poke;

  # Wait all responses
  $asynchttp->wait_all;

DESCRIPTION ^

 Note this module have limited functionality compared to say, LWP. Its designed to make simple requests async, thats all.

new(%opts)

Captain: create a new object.

%opts can be:

resolve_timeout

Timeout for gethostbyname(). Default is 0.5 second. 0 to point no timeout.

resolve_cache

Enable caching result of gethostbyname(). A false means no resolve cache. 'local' means object-scope cache. Other true values mean global cache between instances.

Default is 1 (global).

connect_timeout

Set timeout for socket connect(). Default is 0.2 second. 0 to point no timeout.

response_timeout

Set timeout for response, not including connect. Affect wait() and wait_all() so they wont block like forever. Default is 1 second.

send_get(url, headers)

Send HTTP GET on given url. headers is a hash field=>value

Returns ID of request. Or undef on fail (sets $@ variable); 0 on timeout

check_response(req_id)

Nonblocking check for response. Returns respnse hash when response is complete.

wait(req_id)

Wait for response upto response_timeout. Returns response hash or 0 if timeout.

poke()

Dedicate some time for sysread() to free system buffers.

Returns number of requests ready for processing in scalar context or list of ready ids in list context.

wait_all()

Blocking wait for all responses. Returns undef.

BUGS / CAVEATS ^

Limited functionality. Does not support nonstandard ports yet. Does not suport SSL yet.

Module massively rely on Time::HiRes::ualarm. So it uses ALRM signal. So do not wrap it with alarm() or ualarm().

AUTHOR ^

Alt, <alt@cpan.org>

COPYRIGHT AND LICENSE ^

Copyright (C) 2012 by Alt

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.

syntax highlighting: