[python-win32] ConnectNamedPipe Defect???

Mark Hammond mhammond at skippinet.com.au
Sun Jul 16 13:08:15 CEST 2006


> I am checking the return type something like this
>
>
> CreateNamedPipe.....
>
> While...
>        hr  = ConnectName....
>
>        if(hr !=0 and hr!=win32pipe.ERROR_PIPE_CONNECTED):
>             raise MyOwnException
>
>       DoSomeStuff
>
> Ideally it should return 535 for ERROR_PIPE_CONNECTED. But
> sometimes it
> returns 234 which is ERROR_MORE_DATA.

I see the problem here.  In summary, ConnectNamedPipe() would always return
the result of GetLastError() - even if the function worked.  As the docs
implied, ERROR_IO_PENDING and ERROR_PIPE_CONNECTED get special treatment -
so in effect, the rules have been:

* If rc == ERROR_IO_PENDING or ERROR_PIPE_CONNECTED, then rc was accurate.
* If the function failed for any other reason, an exception was thrown.
* Otherwise, rc should be ignored (currently, it is GetLastError())

I've fixed that to always return zero if the function succeeds.  If the
function fails, the semantics are otherwise the same (actually, for the
record, slightly different - previously, if the function failed but
GetLastError() returned 0, we would still return 0.  Now we will raise an
exception - ie, we trust the BOOL result more than we trust GetLastError())

> Is it a defect??? or how can i get around my problem. Probably use
> SetlastError before Calling ConnectNamedPipe.

It will be fixed in 209 - but otherwise, see above - just completely ignore
the rc unless it is one of those 2 values.

Cheers,

Mark



More information about the Python-win32 mailing list