1 |
root |
1.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 try to resolve hostnames this way. |
33 |
|
|
|
34 |
|
|
Impact: likely little, the two functions should be pretty equivalent. |
35 |
|
|
|
36 |
|
|
=item It overwrites IO::Socket::INET::new with Coro::Socket::new |
37 |
|
|
|
38 |
|
|
This is necessary because LWP does not always use select to see wether a |
39 |
|
|
filehandle can be read/written without blocking. |
40 |
|
|
|
41 |
|
|
Impact: Coro::Socket is not at all compatible to IO::Socket::INET. While |
42 |
|
|
it duplicates some undocumented functionality required by LWP, it does not |
43 |
|
|
have all the methods of IO::Socket::INET and might act quite differently |
44 |
|
|
in practise. Every app that uses IO::Socket::INET now has to cope with |
45 |
|
|
Coro::Socket. |
46 |
|
|
|
47 |
|
|
=back |
48 |
|
|
|
49 |
|
|
All this likely makes other libraries than just LWP not block, but thats |
50 |
|
|
just a side effect you cannot rely on. |
51 |
|
|
|
52 |
|
|
Increases parallelism is not supported by all libraries, some might cache |
53 |
|
|
data globally. |
54 |
|
|
|
55 |
|
|
=cut |
56 |
|
|
|
57 |
|
|
package Coro::LWP; |
58 |
|
|
|
59 |
|
|
use strict; |
60 |
|
|
|
61 |
|
|
use Coro::Select; |
62 |
|
|
use Coro::Util; |
63 |
|
|
use Coro::Socket; |
64 |
|
|
|
65 |
|
|
use Socket; |
66 |
|
|
use IO::Socket::INET; |
67 |
|
|
|
68 |
|
|
*Socket::inet_aton = \&Coro::Util::inet_aton; |
69 |
|
|
|
70 |
|
|
*IO::Socket::INET::new = sub { |
71 |
|
|
new Coro::Socket forward_class => @_; |
72 |
|
|
}; |
73 |
|
|
|
74 |
|
|
=cut |
75 |
|
|
|
76 |
|
|
=head1 AUTHOR |
77 |
|
|
|
78 |
|
|
Marc Lehmann <schmorp@schmorp.de> |
79 |
|
|
http://home.schmorp.de/ |
80 |
|
|
|
81 |
|
|
=cut |
82 |
|
|
|
83 |
|
|
|