#!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request; use IO::Handle; pipe(FROM_PARENT, TO_CHILD) or die "pipe: $!"; pipe(FROM_CHILD, TO_PARENT) or die "pipe: $!"; TO_CHILD->autoflush(1); TO_PARENT->autoflush(1); my $pid = fork; unless ($pid) { # Child process close FROM_CHILD; close TO_CHILD; die "cannot fork: $!" unless defined $pid; { chomp(my $address = ); exit 0 if $address =~ /exit/; my $ua = LWP::UserAgent->new(); print "Child: getting $address ...\n"; # proxy server $ua->env_proxy(); my $req = HTTP::Request->new(GET => "$address"); my $response = $ua->request($req); my $http = $response->content; print "Child got the goods!\n"; print TO_PARENT $http,"\n"; print TO_PARENT "end_http_input\n"; redo; } exit 0; } # Parent process only ... use Tk; close FROM_PARENT; close TO_PARENT; my $top = MainWindow->new(-title=>"PerlPrimer v.test"); my $button = $top->Button(-text=>"try it!", -command=>\&do_it, )->pack(); my $quit = $top->Button(-text=>"Exit", -command=>sub { print TO_CHILD "exit\n"; exit 0; }, )->pack(); MainLoop(); sub do_it { # might as well put all these test http requests to good use ... :) my $address = "http://www.microsoft.com"; print TO_CHILD $address; my $unblock=0; my ($content, $data); $top->fileevent(\*FROM_CHILD, 'readable', sub { # This is where it hangs ... doesn't matter if I even go down to taking 1 byte at a time ... sysread(FROM_CHILD, $data, 32); $content.=$data; $unblock = 1 if $content =~ /end_http_input/; }); $top->waitVariable(\$unblock); $top->fileevent(\*FROM_CHILD, 'readable', ""); print "Parent: http content was $content\n"; print "out of loop ....\n"; }