ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/lwp
(Generate patch)

Comparing Coro/eg/lwp (file contents):
Revision 1.1 by root, Fri Jul 27 02:51:33 2001 UTC vs.
Revision 1.4 by root, Sun Nov 5 02:01:24 2006 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2 2
3# this hack shows how one can overwrite 3# this hack shows how one can get LWP to be less blocking.
4# IO::Socket::INET to provide non-blocking sockets by default.
5# this makes lwp magically non-blocking. I hope.
6 4
7{ 5{
8 # this is all the required magic: we replace the constructor. 6 # we replace Socket::inet_aton and CORE::select
7 use Coro::Select; # must come early
8 use Coro::Util;
9 use Coro::Socket; 9 use Coro::Socket;
10 use IO::Socket::INET; 10 use IO::Socket::INET;
11 sub IO::Socket::INET::new { 11 use Socket;
12 shift; new Coro::Socket @_; 12 BEGIN {
13 *Socket::inet_aton = \&Coro::Util::inet_aton;
14 *IO::Socket::INET::new = sub { new Coro::Socket forward_class => @_ };
13 }; 15 }
14} 16}
15 17
16use Coro; 18use Coro;
17use Coro::Event; 19use Coro::Event;
18use LWP::Simple; 20use LWP::Simple;
19 21
22$SIG{PIPE} = 'IGNORE';
23
24async {
25 print "hi2\n";
26 get "http://www.google.de/";
27 print "ho2\n";
28};
29
20async { 30async {
21 print "hi\n"; 31 print "hi\n";
22 get "http://localhost/"; 32 get "http://www.yahoo.com/";
23 print "ho\n"; 33 print "ho\n";
24 34
25}; 35};
26 36
27async { 37loop;
28 print "hi2\n";
29 get "http://localhost/";
30 print "ho2\n";
31};
32 38
33loop;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines