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

Comparing Coro/eg/lwp (file contents):
Revision 1.2 by root, Sat Jul 28 01:41:58 2001 UTC vs.
Revision 1.6 by root, Sat Apr 14 15:06:06 2007 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2
3# this hack shows how one can overwrite IO::Socket::INET to provide
4# non-blocking sockets by default. This makes lwp magically
5# non-blocking. I hope.
6
7{
8 # this is all the required magic: we replace the constructor.
9 use Coro::Socket;
10 use IO::Socket::INET;
11 sub IO::Socket::INET::new {
12 shift; new Coro::Socket @_;
13 };
14}
15 2
16use Coro; 3use Coro;
17use Coro::Event; 4use Coro::Event;
5use Coro::LWP; # should be use'd as early as possible
18use LWP::Simple; 6use LWP::Simple;
19 7
20async { 8$SIG{PIPE} = 'IGNORE';
21 print "hi\n";
22 get "http://localhost/";
23 print "ho\n";
24 9
10my @pids;
11
12push @pid, async {
13 print "starting to fetch http://www.google.de/\n";
14 get "http://www.google.de/";
15 print "fetched http://www.google.de/\n";
25}; 16};
26 17
27async { 18push @pid, async {
28 print "hi2\n"; 19 print "starting to fetch http://www.yahoo.com/\n";
29 get "http://localhost/"; 20 get "http://www.yahoo.com/";
30 print "ho2\n"; 21 print "fetched http://www.yahoo.com/\n";
31}; 22};
32 23
33loop; 24$_->join for @pid;
25

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines