[pywin32-checkins] pywin32/win32/src win32file.i,1.106,1.107
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2009-02-16 03:56:32
|
Update of /cvsroot/pywin32/pywin32/win32/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4284/src Modified Files: win32file.i Log Message: * Fix vc6 build error. * autoduck clarifications for ConnectEx and AcceptEx * Add new CalculateSocketEndPointSize() method so AcceptEx can be invoked without attempting to read from the connection. Index: win32file.i =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32file.i,v retrieving revision 1.106 retrieving revision 1.107 diff -C2 -d -r1.106 -r1.107 *** win32file.i 15 Feb 2009 23:49:10 -0000 1.106 --- win32file.i 16 Feb 2009 03:56:25 -0000 1.107 *************** *** 41,44 **** --- 41,48 ---- #endif #include "Ws2tcpip.h" + // *sob* - msvc6 can't handle the _WSPIAPI_COUNTOF in later SDKs... + #if _MSC_VER < 1300 + #define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0])) + #endif #include "Wspiapi.h" // for WspiapiGetAddrInfo/WspiapiFreeAddrInfo #endif *************** *** 1774,1778 **** // ConnectEx(sock, (addr, port), buf, overlap) // @rdesc Returns the completion code and number of bytes sent. ! // The error code will be 0 for a completed operation, or ERROR_IO_PENDING for a pending overlapped operation. static PyObject *py_ConnectEx( PyObject *self, PyObject *args, PyObject *kwargs ) { OVERLAPPED *pOverlapped = NULL; --- 1778,1785 ---- // ConnectEx(sock, (addr, port), buf, overlap) // @rdesc Returns the completion code and number of bytes sent. ! // The completion code will be 0 for a completed operation, or ERROR_IO_PENDING for a pending overlapped operation. ! // @rdesc If the platform does not support ConnectEx (eg, Windows 2000), an ! // exception will be thrown indicating the WSAIoctl function (which is used to ! // fetch the function pointer) failed with error code WSAEINVAL (10022). static PyObject *py_ConnectEx( PyObject *self, PyObject *args, PyObject *kwargs ) { OVERLAPPED *pOverlapped = NULL; *************** *** 1943,1949 **** // @comm In order to make sure the connection has been accepted, either use the hEvent in PyOVERLAPPED, GetOverlappedResult, or GetQueuedCompletionStatus. // @comm To use this with I/O completion ports, don't forget to attach sAccepting to your completion port. ! // @comm To have sAccepting inherit the properties of sListening, you need to do the following after a connection is successfully accepted: ! // @comm import struct ! // @comm sAccepting.setsockopt(socket.SOL_SOCKET, win32file.SO_UPDATE_ACCEPT_CONTEXT, struct.pack("I", sListening.fileno())) if (!PySocket_AsSOCKET(obListening, &sListening)) --- 1950,1958 ---- // @comm In order to make sure the connection has been accepted, either use the hEvent in PyOVERLAPPED, GetOverlappedResult, or GetQueuedCompletionStatus. // @comm To use this with I/O completion ports, don't forget to attach sAccepting to your completion port. ! // @ex To have sAccepting inherit the properties of sListening, you need to do the following after a connection is successfully accepted| ! // import struct ! // sAccepting.setsockopt(socket.SOL_SOCKET, win32file.SO_UPDATE_ACCEPT_CONTEXT, struct.pack("I", sListening.fileno())) ! // @comm Pass a buffer of exactly the size returned by <om win32file.CalculateSocketEndPointSize> ! // to have AcceptEx return without reading any bytes from the remote connection. if (!PySocket_AsSOCKET(obListening, &sListening)) *************** *** 2057,2062 **** --- 2066,2107 ---- } + // @pyswig int|CalculateSocketEndPointSize|Calculate how many bytes are needed for the connection endpoints data for a socket. + PyObject *MyCalculateSocketEndPointSize(PyObject *self, PyObject *args) + { + // @comm This function allows you to determine the minumum buffer size + // which can be passed to <om win32file.AcceptEx> + PyObject *obs; + // @pyparm <o PySocket>/int|socket||The socket for which to determine the size. + if (!PyArg_ParseTuple(args, "O", &obs)) + return NULL; + SOCKET s; + if (!PySocket_AsSOCKET(obs, &s)) + return NULL; + + WSAPROTOCOL_INFO wsProtInfo; + UINT cbSize = sizeof(wsProtInfo); + int rc; + + // Grab the protocol information for the socket + Py_BEGIN_ALLOW_THREADS + rc = getsockopt( + s, + SOL_SOCKET, + SO_PROTOCOL_INFO, + (char *)&wsProtInfo, + (int *)&cbSize); + Py_END_ALLOW_THREADS + if (rc == SOCKET_ERROR) + { + PyWin_SetAPIError("getsockopt", WSAGetLastError()); + return NULL; + } + return PyInt_FromLong((wsProtInfo.iMaxSockAddr + 16) * 2); + } + %} + %native(CalculateSocketEndPointSize) MyCalculateSocketEndPointSize; + %{ // @pyswig (iFamily, <o LocalSockAddr>, <o RemoteSockAddr>)|GetAcceptExSockaddrs|Parses the connection endpoints from the buffer passed into AcceptEx PyObject *MyGetAcceptExSockaddrs |