locked
Result from asynchronous ConnectNamedPipe RRS feed

  • Question

  • Dear all,

    I am not sure if it is the right forum to ask win32-related questions but anyway.

    Current MSDN help for ConnectNamedPipe function (see http://msdn.microsoft.com/en-us/library/aa365146(VS.85).aspx) says that in case of asynchronous pipe I can use GetOverlappedResult to check the result ("You can use the GetOverlappedResult function to retrieve the results
    after the operation has finished.") but it does not specify _how_ I should do this.

    Help for GetOverlappedResult (see http://msdn.microsoft.com/en-us/library/aa365146(VS.85).aspx) just says that lpNumberOfBytesTransferred (the only result of GetOverlappedResult) is undefined in case of ConnectNamedPipe ("For a ConnectNamedPipe or WaitCommEvent operation, this value is undefined").

    So my question is: how can I get the success of ConnectNamedPipe in
    case of async IO? Should I check the return value of GetOverlappedResult?

    Best regards,
    Yuri
    Wednesday, May 27, 2009 3:18 PM

Answers

  • An overlapped ConnectNamedPipe will complete when a client connects.  That will cause the server's call to GetOverlappedResult to return success.  So the primary result is simply the fact that it returned.  The lpNumberOfBytesTransferred is meaningless for a connect operation.

    Check the return value, and if it is zero call GetLastError.  I don't know of any errors that can happen: In a pipe server I wrote recently I just checked the return value with an assert, which never failed.

    • Marked as answer by yugr Wednesday, May 27, 2009 5:51 PM
    Wednesday, May 27, 2009 4:43 PM

All replies

  • An overlapped ConnectNamedPipe will complete when a client connects.  That will cause the server's call to GetOverlappedResult to return success.  So the primary result is simply the fact that it returned.  The lpNumberOfBytesTransferred is meaningless for a connect operation.

    Check the return value, and if it is zero call GetLastError.  I don't know of any errors that can happen: In a pipe server I wrote recently I just checked the return value with an assert, which never failed.

    • Marked as answer by yugr Wednesday, May 27, 2009 5:51 PM
    Wednesday, May 27, 2009 4:43 PM
  • You should first verify that you got ERROR_IO_PENDING, the pipe may already be connected (ERROR_PIPE_CONNECTED).  Then call WaitForSingleObject() on the OVERLAPPED.hEvent to wait for a connection.

    Hans Passant.
    Wednesday, May 27, 2009 5:04 PM
  • Thanks. I wish MSDN stated this clearly.
    Wednesday, May 27, 2009 5:52 PM
  • Yes, that is what I am doing.
    Wednesday, May 27, 2009 5:52 PM