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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Namedpipe

Namedpipe

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminjson
5 Posts 2 Posters 1 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.
  • C Offline
    C Offline
    charian0920
    wrote on last edited by
    #1

    Hi ... I'm using namedpipe for my interprocess communication. For each client that requires communication will have a separate instance of the namedpipe. My question is: is there an API that I could use to get the number of active instances of a namedpipe? I need this so that when my process ends it will wait first for the nedpipe server to disconnect before exiting my process. Thanks in advance ... :)

    M 1 Reply Last reply
    0
    • C charian0920

      Hi ... I'm using namedpipe for my interprocess communication. For each client that requires communication will have a separate instance of the namedpipe. My question is: is there an API that I could use to get the number of active instances of a namedpipe? I need this so that when my process ends it will wait first for the nedpipe server to disconnect before exiting my process. Thanks in advance ... :)

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Maybe GetNamedPipeHandleState() using the lpCurInstances parameter. Mark

      "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

      C 1 Reply Last reply
      0
      • M Mark Salsbery

        Maybe GetNamedPipeHandleState() using the lpCurInstances parameter. Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        C Offline
        C Offline
        charian0920
        wrote on last edited by
        #3

        hi mark, thanks for the suggestion. however, i tried searching it in the net and couldn't find any sample implementation that uses the GetNamedPipeHandleState API. I also tried coding like this: DWORD dwCurIntances; DWORD dwState; dwCurIntances = 0; dwState = 0; while ( TRUE ) { // Wait for all the namedpipe instances to close first if( !GetNamedPipeHandleState( (HANDLE) hClientReqPipe, &dwState, &dwCurIntances, NULL, NULL, NULL, 0 ) ) { dwResult = GetLastError(); strLog.Format( "@@@@@@@@@@@@@@@@@@@@ GetNamedPipeHandleState Error: %d.", dwResult ); fnAddToMessageLog( 0, strLog ); break; } if ( dwCurIntances == 0 ) { strLog.Format( "@@@@@@@@@@@@@@@@@@@@ All namedpipe instances have been closed." ); fnAddToMessageLog( 0, strLog ); break; } } but I think it does not go the way I expected it. I'm expecting that the value of dwCurIntances during the startup is "1", since I have created the namedpipe once only. the value I get is "7". would appreciate your help. thank you. :)

        M 1 Reply Last reply
        0
        • C charian0920

          hi mark, thanks for the suggestion. however, i tried searching it in the net and couldn't find any sample implementation that uses the GetNamedPipeHandleState API. I also tried coding like this: DWORD dwCurIntances; DWORD dwState; dwCurIntances = 0; dwState = 0; while ( TRUE ) { // Wait for all the namedpipe instances to close first if( !GetNamedPipeHandleState( (HANDLE) hClientReqPipe, &dwState, &dwCurIntances, NULL, NULL, NULL, 0 ) ) { dwResult = GetLastError(); strLog.Format( "@@@@@@@@@@@@@@@@@@@@ GetNamedPipeHandleState Error: %d.", dwResult ); fnAddToMessageLog( 0, strLog ); break; } if ( dwCurIntances == 0 ) { strLog.Format( "@@@@@@@@@@@@@@@@@@@@ All namedpipe instances have been closed." ); fnAddToMessageLog( 0, strLog ); break; } } but I think it does not go the way I expected it. I'm expecting that the value of dwCurIntances during the startup is "1", since I have created the namedpipe once only. the value I get is "7". would appreciate your help. thank you. :)

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Hmm I'm not sure how you're getting 7. I tried your code after a single CreateNamedPipe() call and got 1, as expected. The instance count should remain equal to the number of CreateNamedPipe() calls you've made for a given name until you've closed the handle to the pipe instance. This may not be useful to you. What do you need to wait for before exiting your process ? Are you waiting for all clients to disconnect? Mark

          "Go that way, really fast. If something gets in your way, turn."

          C 1 Reply Last reply
          0
          • M Mark Salsbery

            Hmm I'm not sure how you're getting 7. I tried your code after a single CreateNamedPipe() call and got 1, as expected. The instance count should remain equal to the number of CreateNamedPipe() calls you've made for a given name until you've closed the handle to the pipe instance. This may not be useful to you. What do you need to wait for before exiting your process ? Are you waiting for all clients to disconnect? Mark

            "Go that way, really fast. If something gets in your way, turn."

            C Offline
            C Offline
            charian0920
            wrote on last edited by
            #5

            I need to wait for all the namedpipe instance to be disconnected by the server first before my process exit. I tried again the code, I already getting "1" for the instance count. If the server already called the DisconnectNamedPipe(), shouldn't be the number of instance decreased? thanks again :) -- modified at 10:09 Tuesday 26th June, 2007

            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