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

I'm "trying" to use Win32::Pipe (see http://www.roth.net/perl/pipe/ ). It works very nicely, but there are a few problems: I'm trying to use the 'peek' method to find out if anything is in the pipe. This works quite nicely, but always returns nothing if the "other side" closed the pipe. I'd like to know when the "other side" closes the pipe (after it was opened), so I can finish up my musings on my end. The normal 'Read' method works well for this, BUT it blocks. What to do? It seems that the 'Peek' method needs 3 returns: 1) Nothing there, 2) Something there (go ahead and read it), and 3) Other side closed the thing, (aka End File). I can get 1 & 2, but not 3. Bummer!! Is there any hope?? Thanks.
  • Comment on Win32::Pipe, how to tell if the other side went away?

Replies are listed 'Best First'.
Re: Win32::Pipe, how to tell if the other side went away?
by BrowserUk (Patriarch) on Feb 15, 2006 at 00:57 UTC

    I'm not in a position to test this speculation, but try checking the value returned by Win32::GetLastError(), (which may or may not be the same as $^E), immediately after Peek() returns false. I would expect, but cannot substantiate that you woud get a different error code if the pipe is just empty, to if it has disconnected.

    Maybe RPC_X_PIPE_EMPTY (1918L) in the former case and RPC_X_PIPE_CLOSED (1916L) in the latter. Those are guesses, there are several possibilities. Should be fairly easy to verify (once you have a working copy of a version of Win32::Pipe that supports the Peek() function :()


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Win32::Pipe, how to tell if the other side went away?
by acid06 (Friar) on Feb 15, 2006 at 00:05 UTC
    I'm shooting in the dark here, but have you tried using the GetInfo() method?

    According to the module's documentation:
    GetInfo() Retrieves an array of information about the pipe: Element 0: State of Pipe Element 1: Number of instances the pipe has Element 2: Name of user connected as the client Element 3: Max number of bytes collected before the pipe sends the + data Element 4: Max amount of time before data is sent
    I guess Element 0 there should provide something useful. Other than this, I can't provide any further help, sorry.

    Just a side note, but I never really got it why Roth Consulting's modules aren't on the CPAN.


    acid06
    perl -e "print pack('h*', 16369646), scalar reverse $="

      Unfortunately, that 'state' field is bit encoded and can indicate blocking/non-blocking, and byte/message mode which doesn't help unless you can enable non-blocking mode and I don't think that module exposes that to Perl.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.