4 use vars qw($VERSION @ISA);
13 if (${*$self}{'httpnb_read_count'}++) {
14 ${*$self}{'http_buf'} = ${*$self}{'httpnb_save'};
18 my $offset = $_[3] || 0;
19 my $n = sysread($self, $_[1], $_[2], $offset);
20 ${*$self}{'httpnb_save'} .= substr($_[1], $offset);
24 sub read_response_headers {
26 ${*$self}{'httpnb_read_count'} = 0;
27 ${*$self}{'httpnb_save'} = ${*$self}{'http_buf'};
28 my @h = eval { $self->SUPER::read_response_headers(@_) };
30 return if $@ eq "Multi-read\n";
36 sub read_entity_body {
38 ${*$self}{'httpnb_read_count'} = 0;
39 ${*$self}{'httpnb_save'} = ${*$self}{'http_buf'};
40 # XXX I'm not so sure this does the correct thing in case of
41 # transfer-encoding tranforms
42 my $n = eval { $self->SUPER::read_entity_body(@_); };
56 Net::HTTP::NB - Non-blocking HTTP client
61 my $s = Net::HTTP::NB->new(Host => "www.perl.com") || die $@;
62 $s->write_request(GET => "/");
65 my $sel = IO::Select->new($s);
68 die "Header timeout" unless $sel->can_read(10);
69 my($code, $mess, %h) = $s->read_response_headers;
70 redo READ_HEADER unless $code;
74 die "Body timeout" unless $sel->can_read(10);
76 my $n = $s->read_entity_body($buf, 1024);
83 Same interface as C<Net::HTTP> but it will never try multiple reads
84 when the read_response_headers() or read_entity_body() methods are
85 invoked. This make it possible to multiplex multiple Net::HTTP::NB
86 using select without risk blocking.
88 If read_response_headers() did not see enough data to complete the
89 headers an empty list is returned.
91 If read_entity_body() did not see new entity data in its read
92 the value -1 is returned.
100 Copyright 2001 Gisle Aas.
102 This library is free software; you can redistribute it and/or
103 modify it under the same terms as Perl itself.