diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-15 20:14:21 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-12-15 20:14:21 (GMT) |
commit | 09bb89b8cf24431ef78bbaa227d2832fb852bb18 (patch) | |
tree | 056643ac4515ef68bbb882e4080b4774e6c24fcb /Modules | |
parent | c48e81ed46604db34783924307bc6bc01d9fa3c6 (diff) | |
download | cpython-09bb89b8cf24431ef78bbaa227d2832fb852bb18.zip cpython-09bb89b8cf24431ef78bbaa227d2832fb852bb18.tar.gz cpython-09bb89b8cf24431ef78bbaa227d2832fb852bb18.tar.bz2 |
Issue #16488: epoll() objects now support the `with` statement.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/selectmodule.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index c0f56a7..52be4d8 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -1394,6 +1394,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}, @@ -1409,6 +1427,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}, }; |