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

Comparing Coro/eg/lwp (file contents):
Revision 1.3 by root, Mon Sep 3 02:50:18 2001 UTC vs.
Revision 1.9 by root, Mon Nov 24 07:55:28 2008 UTC

1#!/usr/bin/perl 1#!/usr/bin/perl
2 2
3# this hack shows how one can overwrite IO::Socket::INET to provide 3use Coro::LWP; # should be use'd as early as possible
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 4
16use Coro; 5use Coro;
17use Coro::Event; 6use Coro::AnyEvent;
18use LWP::Simple; 7use LWP::Simple;
19 8
20$SIG{PIPE} = 'IGNORE'; 9$SIG{PIPE} = 'IGNORE';
21 10
22async { 11my @pids;
23 print "hi\n";
24 get "http://localhost/";
25 print "ho\n";
26 12
27}; 13for (1..1) {
14 push @pid, async {
15 print "starting to fetch http://www.google.de/\n";
16 get "http://www.google.de/";
17 print "fetched http://www.google.de/\n";
18 };
28 19
29async { 20 push @pid, async {
30 print "hi2\n"; 21 print "starting to fetch http://www.yahoo.com/\n";
31 get "http://localhost/"; 22 get "http://www.yahoo.com/";
32 print "ho2\n"; 23 print "fetched http://www.yahoo.com/\n";
33}; 24 };
25}
34 26
35loop; 27$_->join for @pid;
28

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines