diff -r a0421b30a841 Modules/selectmodule.c --- a/Modules/selectmodule.c Sun Nov 18 10:42:42 2012 +0000 +++ b/Modules/selectmodule.c Sun Nov 18 17:27:29 2012 -0500 @@ -48,8 +48,7 @@ #endif #ifdef MS_WINDOWS -# define WIN32_LEAN_AND_MEAN -# include +# include "socketmodule.h" #else # define SOCKET int # if defined(__VMS) @@ -325,8 +324,12 @@ PyObject_HEAD PyObject *dict; int ufd_uptodate; +#ifdef MS_WINDOWS + ULONG ufd_len; +#else int ufd_len; - struct pollfd *ufds; +#endif + pollfd_t *ufds; } pollObject; static PyTypeObject poll_Type; @@ -340,10 +343,10 @@ { Py_ssize_t i, pos; PyObject *key, *value; - struct pollfd *old_ufds = self->ufds; + pollfd_t *old_ufds = self->ufds; self->ufd_len = PyDict_Size(self->dict); - PyMem_RESIZE(self->ufds, struct pollfd, self->ufd_len); + PyMem_RESIZE(self->ufds, pollfd_t, self->ufd_len); if (self->ufds == NULL) { self->ufds = old_ufds; PyErr_NoMemory(); @@ -378,9 +381,13 @@ return NULL; } +#ifdef MS_WINDOWS + events &= ~POLLPRI; +#endif + fd = PyObject_AsFileDescriptor(o); if (fd == -1) return NULL; - + /* Add entry to the internal dictionary: the key is the file descriptor, and the value is the event mask. */ key = PyLong_FromLong(fd); @@ -421,6 +428,10 @@ return NULL; } +#ifdef MS_WINDOWS + events &= ~POLLPRI; +#endif + fd = PyObject_AsFileDescriptor(o); if (fd == -1) return NULL; @@ -495,6 +506,9 @@ { PyObject *result_list = NULL, *tout = NULL; int timeout = 0, poll_result, i, j; +#ifdef MS_WINDOWS + int wsa_errno; +#endif PyObject *value = NULL, *num = NULL; if (!PyArg_UnpackTuple(args, "poll", 0, 1, &tout)) { @@ -529,10 +543,18 @@ poll_result = poll(self->ufds, self->ufd_len, timeout); Py_END_ALLOW_THREADS +#ifdef MS_WINDOWS + if (poll_result == SOCKET_ERROR) { + wsa_errno = WSAGetLastError(); + PyErr_SetExcFromWindowsErr(PyExc_OSError, wsa_errno); + return NULL; + } +#else if (poll_result < 0) { PyErr_SetFromErrno(PyExc_OSError); return NULL; } +#endif /* build the result list */ @@ -551,7 +573,11 @@ value = PyTuple_New(2); if (value == NULL) goto error; +#ifndef MS_WINDOWS num = PyLong_FromLong(self->ufds[i].fd); +#else + num = PyLong_FromLongLong(self->ufds[i].fd); +#endif if (num == NULL) { Py_DECREF(value); goto error; @@ -662,7 +688,7 @@ int fd_devpoll; int max_n_fds; int n_fds; - struct pollfd *fds; + pollfd_t *fds; } devpollObject; static PyTypeObject devpoll_Type; @@ -673,7 +699,7 @@ if (!self->n_fds) return 0; - size = sizeof(struct pollfd)*self->n_fds; + size = sizeof(pollfd_t)*self->n_fds; self->n_fds = 0; Py_BEGIN_ALLOW_THREADS @@ -895,7 +921,7 @@ { devpollObject *self; int fd_devpoll, limit_result; - struct pollfd *fds; + pollfd_t *fds; struct rlimit limit; Py_BEGIN_ALLOW_THREADS @@ -919,7 +945,7 @@ return NULL; } - fds = PyMem_NEW(struct pollfd, limit.rlim_cur); + fds = PyMem_NEW(pollfd_t, limit.rlim_cur); if (fds == NULL) { close(fd_devpoll); PyErr_NoMemory(); @@ -1023,7 +1049,7 @@ int poll_test; int filedes[2]; - struct pollfd poll_struct = { 0, POLLIN|POLLPRI|POLLOUT, 0 }; + pollfd_t poll_struct = { 0, POLLIN|POLLPRI|POLLOUT, 0 }; /* Create a file descriptor to make invalid */ if (pipe(filedes) < 0) { diff -r a0421b30a841 Modules/socketmodule.c --- a/Modules/socketmodule.c Sun Nov 18 10:42:42 2012 +0000 +++ b/Modules/socketmodule.c Sun Nov 18 17:27:29 2012 -0500 @@ -652,7 +652,11 @@ * which can't be done with select(). */ #ifdef HAVE_POLL { +#ifndef MS_WINDOWS struct pollfd pollfd; +#else + WSAPOLLFD pollfd; +#endif int timeout; pollfd.fd = s->sock_fd; @@ -660,7 +664,11 @@ /* s->sock_timeout is in seconds, timeout in ms */ timeout = (int)(interval * 1000 + 0.5); +#ifndef MS_WINDOWS n = poll(&pollfd, 1, timeout); +#else + n = WSAPoll(&pollfd, 1, timeout); +#endif } #else { @@ -1829,7 +1837,10 @@ } } - +#ifdef MS_WINDOWS +#undef CMSG_LEN +#undef CMSG_SPACE +#endif /* Support functions for the sendmsg() and recvmsg[_into]() methods. Currently, these methods are only compiled if the RFC 2292/3542 diff -r a0421b30a841 Modules/socketmodule.h --- a/Modules/socketmodule.h Sun Nov 18 10:42:42 2012 +0000 +++ b/Modules/socketmodule.h Sun Nov 18 17:27:29 2012 -0500 @@ -30,6 +30,8 @@ # else typedef int socklen_t; # endif /* IPPROTO_IPV6 */ +#define pollfd_t WSAPOLLFD +#define poll WSAPoll #endif /* MS_WINDOWS */ #ifdef HAVE_SYS_UN_H diff -r a0421b30a841 PC/pyconfig.h --- a/PC/pyconfig.h Sun Nov 18 10:42:42 2012 +0000 +++ b/PC/pyconfig.h Sun Nov 18 17:27:29 2012 -0500 @@ -158,12 +158,12 @@ /* set the version macros for the windows headers */ #ifdef MS_WINX64 /* 64 bit only runs on XP or greater */ -#define Py_WINVER 0x0501 /* _WIN32_WINNT_WINXP */ -#define Py_NTDDI NTDDI_WINXP +#define Py_WINVER 0x0600 /* _WIN32_WINNT_WINXP */ +#define Py_NTDDI NTDDI_WIN6 #else /* Python 2.6+ requires Windows 2000 or greater */ -#define Py_WINVER 0x0500 /* _WIN32_WINNT_WIN2K */ -#define Py_NTDDI NTDDI_WIN2KSP4 +#define Py_WINVER 0x0600 /* _WIN32_WINNT_WIN2K */ +#define Py_NTDDI NTDDI_WIN6 #endif /* We only set these values when building Python - we don't want to force @@ -433,6 +433,8 @@ #endif #endif +#define HAVE_POLL 1 + /* Fairly standard from here! */ /* Define to 1 if you have the `copysign' function. */