Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Checking for NPH client connection

by ryddler (Monk)
on Jan 04, 2001 at 17:05 UTC ( [id://49802]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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

Wise monks, I seek your knowledge and experience.

I have a non-parsed header CGI that runs in a loop once started. Once the user hits "Stop" or moves on to another page, I want to end the script and do cleanup.

Is there any way to check to see if the client is still connected?

ryddler

Replies are listed 'Best First'.
Re: Checking for NPH client connection
by Hot Pastrami (Monk) on Jan 04, 2001 at 17:10 UTC
    I believe that $SIG{PIPE} will indicate if the browser has disconnected... perhaps something like this would work:
    $SIG{PIPE} = sub { exit; }
    ...or, if you have a sub already which performs the cleanup, perhaps called "cleanup()"...
    $SIG{PIPE} = \&cleanup;

    Hot Pastrami
(tye)Re: Checking for NPH client connection
by tye (Sage) on Jan 04, 2001 at 20:24 UTC

    Um, depends. (: If your server does non-parsed headers by giving you a pipe to write to and then notices that the client has closed the socket, you might be able to detect the action that the server takes after noticing. If it closes its handle to the pipe, then your next write to the pipe will generate a SIGPIPE which you can catch. If the server kills you, then you can catch that.

    If the server does non-parsed headers by passing the socket directly to you as your STDOUT, then when the client closes the socket your next write to the socket will fail (print actually has a return value, even though it is usually ignored). If you aren't constantly writing to STDOUT, then you can use select() to detect when the socket gets closed by the client.

            - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://49802]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.