diff options
Diffstat (limited to 'Modules/selectmodule.c')
-rw-r--r-- | Modules/selectmodule.c | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 2ca2d41a15..252dee2360 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -47,11 +47,6 @@ extern void bzero(void *, int); #include <sys/types.h> #endif -#if defined(PYOS_OS2) && !defined(PYCC_GCC) -#include <sys/time.h> -#include <utils.h> -#endif - #ifdef MS_WINDOWS # define WIN32_LEAN_AND_MEAN # include <winsock.h> @@ -304,9 +299,9 @@ select_select(PyObject *self, PyObject *args) else ret = PyTuple_Pack(3, ifdlist, ofdlist, efdlist); - Py_DECREF(ifdlist); - Py_DECREF(ofdlist); - Py_DECREF(efdlist); + Py_XDECREF(ifdlist); + Py_XDECREF(ofdlist); + Py_XDECREF(efdlist); } finally: @@ -1403,6 +1398,24 @@ Wait for events on the epoll file descriptor for a maximum time of timeout\n\ in seconds (as float). -1 makes poll wait indefinitely.\n\ Up to maxevents are returned to the caller."); +static PyObject * +pyepoll_enter(pyEpoll_Object *self, PyObject *args) +{ + if (self->epfd < 0) + return pyepoll_err_closed(); + + Py_INCREF(self); + return (PyObject *)self; +} + +static PyObject * +pyepoll_exit(PyObject *self, PyObject *args) +{ + _Py_IDENTIFIER(close); + + return _PyObject_CallMethodId(self, &PyId_close, NULL); +} + static PyMethodDef pyepoll_methods[] = { {"fromfd", (PyCFunction)pyepoll_fromfd, METH_VARARGS | METH_CLASS, pyepoll_fromfd_doc}, @@ -1418,6 +1431,10 @@ static PyMethodDef pyepoll_methods[] = { METH_VARARGS | METH_KEYWORDS, pyepoll_unregister_doc}, {"poll", (PyCFunction)pyepoll_poll, METH_VARARGS | METH_KEYWORDS, pyepoll_poll_doc}, + {"__enter__", (PyCFunction)pyepoll_enter, METH_NOARGS, + NULL}, + {"__exit__", (PyCFunction)pyepoll_exit, METH_VARARGS, + NULL}, {NULL, NULL}, }; @@ -2166,7 +2183,7 @@ PyInit_select(void) #undef PIPE_BUF #define PIPE_BUF 512 #endif - PyModule_AddIntConstant(m, "PIPE_BUF", PIPE_BUF); + PyModule_AddIntMacro(m, PIPE_BUF); #endif #if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL) @@ -2181,27 +2198,27 @@ PyInit_select(void) #endif if (PyType_Ready(&poll_Type) < 0) return NULL; - PyModule_AddIntConstant(m, "POLLIN", POLLIN); - PyModule_AddIntConstant(m, "POLLPRI", POLLPRI); - PyModule_AddIntConstant(m, "POLLOUT", POLLOUT); - PyModule_AddIntConstant(m, "POLLERR", POLLERR); - PyModule_AddIntConstant(m, "POLLHUP", POLLHUP); - PyModule_AddIntConstant(m, "POLLNVAL", POLLNVAL); + PyModule_AddIntMacro(m, POLLIN); + PyModule_AddIntMacro(m, POLLPRI); + PyModule_AddIntMacro(m, POLLOUT); + PyModule_AddIntMacro(m, POLLERR); + PyModule_AddIntMacro(m, POLLHUP); + PyModule_AddIntMacro(m, POLLNVAL); #ifdef POLLRDNORM - PyModule_AddIntConstant(m, "POLLRDNORM", POLLRDNORM); + PyModule_AddIntMacro(m, POLLRDNORM); #endif #ifdef POLLRDBAND - PyModule_AddIntConstant(m, "POLLRDBAND", POLLRDBAND); + PyModule_AddIntMacro(m, POLLRDBAND); #endif #ifdef POLLWRNORM - PyModule_AddIntConstant(m, "POLLWRNORM", POLLWRNORM); + PyModule_AddIntMacro(m, POLLWRNORM); #endif #ifdef POLLWRBAND - PyModule_AddIntConstant(m, "POLLWRBAND", POLLWRBAND); + PyModule_AddIntMacro(m, POLLWRBAND); #endif #ifdef POLLMSG - PyModule_AddIntConstant(m, "POLLMSG", POLLMSG); + PyModule_AddIntMacro(m, POLLMSG); #endif } #endif /* HAVE_POLL */ @@ -2219,25 +2236,25 @@ PyInit_select(void) Py_INCREF(&pyEpoll_Type); PyModule_AddObject(m, "epoll", (PyObject *) &pyEpoll_Type); - PyModule_AddIntConstant(m, "EPOLLIN", EPOLLIN); - PyModule_AddIntConstant(m, "EPOLLOUT", EPOLLOUT); - PyModule_AddIntConstant(m, "EPOLLPRI", EPOLLPRI); - PyModule_AddIntConstant(m, "EPOLLERR", EPOLLERR); - PyModule_AddIntConstant(m, "EPOLLHUP", EPOLLHUP); - PyModule_AddIntConstant(m, "EPOLLET", EPOLLET); + PyModule_AddIntMacro(m, EPOLLIN); + PyModule_AddIntMacro(m, EPOLLOUT); + PyModule_AddIntMacro(m, EPOLLPRI); + PyModule_AddIntMacro(m, EPOLLERR); + PyModule_AddIntMacro(m, EPOLLHUP); + PyModule_AddIntMacro(m, EPOLLET); #ifdef EPOLLONESHOT /* Kernel 2.6.2+ */ - PyModule_AddIntConstant(m, "EPOLLONESHOT", EPOLLONESHOT); + PyModule_AddIntMacro(m, EPOLLONESHOT); #endif /* PyModule_AddIntConstant(m, "EPOLL_RDHUP", EPOLLRDHUP); */ - PyModule_AddIntConstant(m, "EPOLLRDNORM", EPOLLRDNORM); - PyModule_AddIntConstant(m, "EPOLLRDBAND", EPOLLRDBAND); - PyModule_AddIntConstant(m, "EPOLLWRNORM", EPOLLWRNORM); - PyModule_AddIntConstant(m, "EPOLLWRBAND", EPOLLWRBAND); - PyModule_AddIntConstant(m, "EPOLLMSG", EPOLLMSG); + PyModule_AddIntMacro(m, EPOLLRDNORM); + PyModule_AddIntMacro(m, EPOLLRDBAND); + PyModule_AddIntMacro(m, EPOLLWRNORM); + PyModule_AddIntMacro(m, EPOLLWRBAND); + PyModule_AddIntMacro(m, EPOLLMSG); #ifdef EPOLL_CLOEXEC - PyModule_AddIntConstant(m, "EPOLL_CLOEXEC", EPOLL_CLOEXEC); + PyModule_AddIntMacro(m, EPOLL_CLOEXEC); #endif #endif /* HAVE_EPOLL */ |