Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Killing a server-push stream in LWP?

by ryddler (Monk)
on Oct 16, 2001 at 19:34 UTC ( [id://119156]=perlquestion: print w/replies, xml ) Need Help??

ryddler has asked for the wisdom of the Perl Monks concerning the following question:

I have a small proxy script that occasionally runs into a server-push stream that doesn't end. I'd like to be able to do something like:

$response = $useragent->simple_request($request, \&callback, 2048); ... time passes ... $useragent->killstream;

Except that I haven't been able to find any reference anywhere in the docs, searching on perlmonks, or even the lwp mailing list, that such a function or method exists.

I have tried setting the useragent to undef, but the stream continues to flow in. Unless I explicitly kill the script altogether, nothing seems to work.

Fellow monks, has anyone a solution for my woes?

ryddler

Replies are listed 'Best First'.
(jeffa) Re: Killing a server-push stream in LWP?
by jeffa (Bishop) on Oct 16, 2001 at 19:55 UTC
    Hmmmm ... well, you could try a time out:
    $SIG{ALRM} = sub { die "timed out" }; eval { alarm(60); # give it 60 seconds $response = $useragent->simple_request($request,\&callback,2048); alarm(0); }; # now look for "timed out" in $@ if ($@ =~ /timed out/) { # do something }

    UPDATE:
    Bummer that you only have Win2k at your disposal. . As for killing the incoming stream - when are you setting $useragent to undef? Seems to me that you would never be able to that without a time out mechanism - the script would continue to wait indefinetly for the server to end the connection.

    i thought you might be able to use something like:

    undef $useragent if $@ =~ /timed out/;
    but the whole having to deal with Win2k is a right bummer. Sorry i couldn't help more :(

    jeffa

      While this might actually tell me that the process went longer than 60 seconds, unfortunately I can't test it because I'm on a Win2k box.

      However, it still doesn't address the issue of killing the incoming stream that the useragent is currently receiving ;)

      ryddler

Re: Killing a server-push stream in LWP?
by grinder (Bishop) on Oct 17, 2001 at 00:05 UTC

    Just die in your callback and you'll be fine. That's all there is to it.

    Hmm. I never expected to link back to a node I posted yesterday. That must be a record of sorts.

    --
    g r i n d e r

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://119156]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found