[python-win32] Need reviews for a patch in win32file for TransmitFile and ConnectEx

Roger Upole rwupole at msn.com
Tue May 13 19:53:56 CEST 2008


Ionel Maries Cristian wrote:
> the patches are tracked here:
> https://sourceforge.net/tracker/index.php?func=detail&aid=1962146&group_id=78018&atid=551956
> and here:
> https://sourceforge.net/tracker/index.php?func=detail&aid=1937527&group_id=78018&atid=551956
>
> mark hammond requested that i post them here (he's a bit busy)
>
> as notes on the ConnectEx call:
> - one needs to get the pointer to the ConnectEx from the socket via a
> WSAIoctl call and i'm going the safe way and getting the pointer every
> time
> (sadly the msdn docs don't say if we always get the same pointer - suppose
> we use ConnectEx with ip v4 and v6 sockets and the pointer could be
> different)
> - i'm using a getaddrinfo to convert the (host,port) tuple to a addrinfo
> struct
>
> I've included some testcases for the 2 patches on the bugtracker
> (test_connectex.py, test_transmitfile.py)
>

A couple of things in the ConnectEx function:

    The XDECREF of obBuf is unnecessary, and can cause a crash.

    The buffer size is a DWORD, but you're passing a Py_ssize_t.which is
    larger when compiled for 64-bit.  You can use
    PyWinObject_AsReadBuffer to convert a buffer with a DWORD length.
    It will also handle None for you, which allows you to simply initialize
    obBuf  to Py_None instead of NULL.

    Also, the entire output section can be simplified to:
        rv=Py_BuildValue("ii", rc, sent)

             Roger






More information about the python-win32 mailing list