ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/Coro/LWP.pm
Revision: 1.4
Committed: Sat Mar 24 19:17:13 2007 UTC (17 years, 3 months ago) by root
Branch: MAIN
CVS Tags: rel-4_22, rel-4_21, rel-4_0, rel-4_3, rel-4_13, rel-4_11, rel-3_55, rel-4_01, rel-4_03, rel-4_02, rel-3_6, rel-3_62, rel-3_63, rel-3_61, rel-4_50, rel-4_51, rel-4_4, rel-4_45, rel-4_49, rel-4_48, rel-4_1, rel-4_2, rel-4_47, rel-4_46, rel-4_31, rel-4_32, rel-4_33, rel-4_34, rel-4_35, rel-4_36, rel-4_37
Changes since 1.3: +0 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Coro::LWP - make LWP non-blocking - as much as possible
4
5 =head1 SYNOPSIS
6
7 use Coro::LWP; # afterwards LWP should not block
8
9 =head1 DESCRIPTION
10
11 This module tries to make L<LWP|LWP> non-blocking with respect to other
12 coroutines as much as possible, and with whatever means it takes.
13
14 LWP really tries very hard to be blocking, so this module had to be very
15 invasive and must be loaded very early to take the proper effect.
16
17 Here is what it currently does (future versions of LWP might require
18 different tricks):
19
20 =over 4
21
22 =item It loads Coro::Select, overwriting the perl C<select> builtin I<globally>.
23
24 This is necessary because LWP calls select quite often for timeouts and
25 who-knows-what.
26
27 Impact: everybody else uses this (slower) version of select, too. It should be quite
28 compatible to perls builtin select, though.
29
30 =item It overwrites Socket::inet_aton with Coro::Util::inet_aton.
31
32 This is necessary because LWP might (and does) try to resolve hostnames
33 this way.
34
35 Impact: likely little, the two functions should be pretty equivalent.
36
37 =item It replaces the base class of Net::HTTP, Net::FTP, Net::NNTP.
38
39 This is necessary because LWP does not always use select to see wether
40 a filehandle can be read/written without blocking, so the base class
41 C<IO::Socket::INET> needs to be replaced by C<Coro::Socket>.
42
43 Impact: Coro::Socket is not at all compatible to IO::Socket::INET. While
44 it duplicates some undocumented functionality required by LWP, it does not
45 have all the methods of IO::Socket::INET and might act quite differently
46 in practise. Also, protocols other than the above mentioned will still block,
47 at least some of the time.
48
49 =back
50
51 All this likely makes other libraries than just LWP not block, but thats
52 just a side effect you cannot rely on.
53
54 Increases parallelism is not supported by all libraries, some might cache
55 data globally.
56
57 =cut
58
59 package Coro::LWP;
60
61 use strict;
62
63 use Coro::Select;
64 use Coro::Util;
65 use Coro::Socket;
66
67 use Socket;
68 use IO::Socket::INET;
69
70 use Net::HTTP;
71 use Net::FTP;
72 use Net::NNTP;
73
74 our $VERSION = '0.9';
75
76 *Socket::inet_aton = \&Coro::Util::inet_aton;
77
78 for (@Net::HTTP::ISA, @Net::FTP::ISA, @Net::NTTP::ISA) {
79 $_ = Coro::LWP::Socket:: if $_ eq IO::Socket::INET::;
80 }
81
82 package Coro::LWP::Socket;
83
84 use base Coro::Socket::;
85
86 sub new {
87 my $self = shift;
88
89 $self->SUPER::new (@_, partial => 1)
90 }
91
92 1;
93
94 =head1 AUTHOR
95
96 Marc Lehmann <schmorp@schmorp.de>
97 http://home.schmorp.de/
98
99 =cut
100
101