views:

123

answers:

1

When I call ConnectNamedPipe with an OVERLAPPED structure and check GetLastError afterwards, I often see GetLastError return ERROR_SUCCESS. The way I'm reading the documentation, that should never happen. My understanding is that if a client has already connected, ERROR_PIPE_CONNECTED should be set, not ERROR_SUCCESS.

Has anyone else seen this? The OS is 32-bit Windows 7.

A: 

That's typical for OVERLAPPED. It tells whether the parameters are okay before connecting, assuming an asynchronous socket. Once a connection completes or fails, then GetOverlappedResult() returns the proper status. So I guess this is a minor documentation error.

wallyk
So, to clarify, if GetLastError() returns ERROR_SUCCESS after ConnectNamedPipe(), I should treat it as ERROR_IO_PENDING and call GetOverlappedResult()?
Ray
Kind of. It doesn't really mean the i/o is pending. It could fail, for example if there is an improper IP address. So i/o isn't pending. It just hasn't occurred yet.
wallyk