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.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 IO::Socket::INET to provide 3# this hack shows how one can get LWP to be less blocking.
4# non-blocking sockets by default. This makes lwp magically
5# 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
20$SIG{PIPE} = 'IGNORE'; 22$SIG{PIPE} = 'IGNORE';
21 23
22async { 24async {
25 print "hi2\n";
26 get "http://www.google.de/";
27 print "ho2\n";
28};
29
30async {
23 print "hi\n"; 31 print "hi\n";
24 get "http://localhost/"; 32 get "http://www.yahoo.com/";
25 print "ho\n"; 33 print "ho\n";
26 34
27}; 35};
28 36
29async { 37loop;
30 print "hi2\n";
31 get "http://localhost/";
32 print "ho2\n";
33};
34 38
35loop;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines