1LWP(3) User Contributed Perl Documentation LWP(3)
2
3
4
6 Coro::LWP - make LWP non-blocking - as much as possible
7
9 use Coro::LWP; # afterwards LWP should not block
10
12 Over the years, a number of less-invasive alternatives have popped up,
13 which you might find more acceptable than this rather invasive and
14 fragile module. All of them only support HTTP (and sometimes HTTPS).
15
16 AnyEvent::HTTP
17 Works fine without Coro. Requires using a very different API than
18 LWP. Probably the best choice iff you can do with a completely
19 different event-based API.
20
21 LWP::Protocol::AnyEvent::http
22 Makes LWP use AnyEvent::HTTP. Does not make LWP event-based, but
23 allows Coro threads to schedule unimpeded through its AnyEvent
24 integration.
25
26 Lets you use the LWP API normally.
27
28 LWP::Protocol::Coro::http
29 Basically the same as above, distinction unclear. :)
30
31 AnyEvent::HTTP::LWP::UserAgent
32 A different user agent implementation, not completely transparent
33 to users, requires Coro.
34
36 This module is an AnyEvent user, you need to make sure that you use and
37 run a supported event loop.
38
39 This module tries to make LWP non-blocking with respect to other
40 coroutines as much as possible, and with whatever means it takes.
41
42 LWP really tries very hard to be blocking (and relies on a lot of
43 undocumented functionality in IO::Socket), so this module had to be
44 very invasive and must be loaded very early to take the proper effect.
45
46 Note that the module AnyEvent::HTTP might offer an alternative to the
47 full LWP that is designed to be non-blocking.
48
49 Here is what it currently does (future versions of LWP might require
50 different tricks):
51
52 It loads Coro::Select, overwriting the perl "select" builtin globally.
53 This is necessary because LWP calls select quite often for timeouts
54 and who-knows-what.
55
56 Impact: everybody else uses this (slower) version of select, too.
57 It should be quite compatible to perls builtin select, though.
58
59 It overwrites Socket::inet_aton with Coro::Util::inet_aton.
60 This is necessary because LWP might (and does) try to resolve
61 hostnames this way.
62
63 Impact: some code might not expect coroutine semantics, for
64 example, when you fork you might prefer the blocking variant
65 because other coroutines shouldn't actually run.
66
67 It replaces the base class of Net::HTTP, Net::FTP, Net::NNTP.
68 This is necessary because LWP does not always use select to see
69 whether a filehandle can be read/written without blocking, so the
70 base class "IO::Socket::INET" needs to be replaced by
71 "Coro::Socket".
72
73 Impact: Coro::Socket is not at all compatible to IO::Socket::INET.
74 While it duplicates some undocumented functionality required by
75 LWP, it does not have all the methods of IO::Socket::INET and might
76 act quite differently in practise. Also, protocols other than the
77 above mentioned will still block, at least some of the time.
78
79 All this likely makes other libraries than just LWP not block, but
80 that's just a side effect you cannot rely on.
81
82 Increases parallelism is not supported by all libraries, some might
83 cache data globally.
84
86 Marc A. Lehmann <schmorp@schmorp.de>
87 http://software.schmorp.de/pkg/Coro.html
88
89
90
91perl v5.34.0 2022-01-21 LWP(3)