# HG changeset patch # Parent cb612c5f30cb5fad03200b8d56b160172a5c4a22 diff -r cb612c5f30cb Modules/selectmodule.c --- a/Modules/selectmodule.c Thu Nov 15 18:22:23 2012 +0000 +++ b/Modules/selectmodule.c Tue Dec 04 14:38:19 2012 +0000 @@ -48,8 +48,16 @@ #endif #ifdef MS_WINDOWS +# undef _WIN32_WINNT +# define _WIN32_WINNT 0x0600 +# undef NTDDI_VERSION +# define NTDDI_VERSION NTDDI_LONGHORN # define WIN32_LEAN_AND_MEAN -# include +# include +# include +# define HAVE_POLL +# define poll(fds, nfds, timeout) Py_WSAPoll((fds), (ULONG)(nfds), (timeout)) +static LPFN_WSAPOLL Py_WSAPoll = NULL; #else # define SOCKET int # if defined(__VMS) @@ -371,7 +379,12 @@ poll_register(pollObject *self, PyObject *args) { PyObject *o, *key, *value; +#ifndef MS_WINDOWS int fd, events = POLLIN | POLLPRI | POLLOUT; +#else + /* Requesting the POLLPRI event fails on Windows */ + int fd, events = POLLIN | POLLOUT; +#endif int err; if (!PyArg_ParseTuple(args, "O|i:register", &o, &events)) { @@ -530,7 +543,11 @@ Py_END_ALLOW_THREADS if (poll_result < 0) { +#ifndef MS_WINDOWS PyErr_SetFromErrno(PyExc_OSError); +#else + PyErr_SetFromWindowsErr(WSAGetLastError()); +#endif return NULL; } @@ -551,7 +568,11 @@ value = PyTuple_New(2); if (value == NULL) goto error; +#ifndef MS_WINDOWS num = PyLong_FromLong(self->ufds[i].fd); +#else + num = PyLong_FromSsize_t((Py_ssize_t)self->ufds[i].fd); +#endif if (num == NULL) { Py_DECREF(value); goto error; @@ -2124,6 +2145,17 @@ PyInit_select(void) { PyObject *m; + +#ifdef MS_WINDOWS + HINSTANCE hWs2_32 = GetModuleHandle("WS2_32"); + if (!hWs2_32) { + PyErr_SetString(PyExc_RuntimeError, "could not get handle for Ws2_32"); + return NULL; + } + /* On WinXP WSAPoll is unavailable so Py_WSAPoll will be NULL */ + *(FARPROC *)&Py_WSAPoll = GetProcAddress(hWs2_32, "WSAPoll"); +#endif + m = PyModule_Create(&selectmodule); if (m == NULL) return NULL; @@ -2146,6 +2178,8 @@ PyErr_Clear(); } } else { +#elif defined(MS_WINDOWS) + if (Py_WSAPoll != NULL) { #else { #endif