Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. checking a pipe status

checking a pipe status

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Martin Blanc
    wrote on last edited by
    #1

    I've got a named pipe. One process writes to its (let's call it A) side, and the other process reads from its oposite (B) side. The process at the B side can randomly connect to and disconnect from the pipe. I'd like to prevent the A-side process from even trying to write to the pipe if the B-side process is disconnected. How can A-side process check the B-side pipe status? I have an idea of using PeekNamedPipe() with all its pointer parameters set to NULL and, when I get return value zero, interpret the result of GetLastError(), but this idea by no means seems that smart to me. Any suggestions? Is GetNamedPipeHandleState() of any use in these situations? TIA Martin

    A 1 Reply Last reply
    0
    • M Martin Blanc

      I've got a named pipe. One process writes to its (let's call it A) side, and the other process reads from its oposite (B) side. The process at the B side can randomly connect to and disconnect from the pipe. I'd like to prevent the A-side process from even trying to write to the pipe if the B-side process is disconnected. How can A-side process check the B-side pipe status? I have an idea of using PeekNamedPipe() with all its pointer parameters set to NULL and, when I get return value zero, interpret the result of GetLastError(), but this idea by no means seems that smart to me. Any suggestions? Is GetNamedPipeHandleState() of any use in these situations? TIA Martin

      A Offline
      A Offline
      Alois Kraus
      wrote on last edited by
      #2

      I did use PeekNamedPipe for this purpose and it worked perfectly. I use a one byte reciever buffer in the PeekNamedPipe function. You could of course use WriteFileEx with an completion Routine and wait for an error to occur. A live ping always involves sending packets and check if the reciever responds to it. There is simply no other way to check if somebody has unplugged Your network cable. PeekNamedPipe does exactly this in a transparent way without disturbing your data transfer.

      M 1 Reply Last reply
      0
      • A Alois Kraus

        I did use PeekNamedPipe for this purpose and it worked perfectly. I use a one byte reciever buffer in the PeekNamedPipe function. You could of course use WriteFileEx with an completion Routine and wait for an error to occur. A live ping always involves sending packets and check if the reciever responds to it. There is simply no other way to check if somebody has unplugged Your network cable. PeekNamedPipe does exactly this in a transparent way without disturbing your data transfer.

        M Offline
        M Offline
        Martin Blanc
        wrote on last edited by
        #3

        Thanks for your reply. Now I know I'm standing on the firm ground. Sometimes it's better to learn from others' successes instead of my own failures. :) Martin

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups