mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
add a flags parameter to select.epoll
This commit is contained in:
parent
e7437a7cb3
commit
2fb9ae9dfc
4 changed files with 31 additions and 24 deletions
|
@ -39,12 +39,19 @@ The module defines the following:
|
||||||
|
|
||||||
.. versionadded:: 3.3
|
.. versionadded:: 3.3
|
||||||
|
|
||||||
.. function:: epoll(sizehint=-1)
|
.. function:: epoll(sizehint=-1, flags=0)
|
||||||
|
|
||||||
(Only supported on Linux 2.5.44 and newer.) Returns an edge polling object,
|
(Only supported on Linux 2.5.44 and newer.) Return an edge polling object,
|
||||||
which can be used as Edge or Level Triggered interface for I/O events; see
|
which can be used as Edge or Level Triggered interface for I/O
|
||||||
section :ref:`epoll-objects` below for the methods supported by epolling
|
events. *sizehint* is deprecated and completely ignored. *flags* can be set
|
||||||
objects.
|
to :const:`EPOLL_CLOEXEC`, which causes the epoll descriptor to be closed
|
||||||
|
automatically when :func:`os.execve` is called. See section
|
||||||
|
:ref:`epoll-objects` below for the methods supported by epolling objects.
|
||||||
|
|
||||||
|
|
||||||
|
.. versionchanged:: 3.3
|
||||||
|
|
||||||
|
Added the *flags* parameter.
|
||||||
|
|
||||||
|
|
||||||
.. function:: poll()
|
.. function:: poll()
|
||||||
|
|
|
@ -74,6 +74,8 @@ class TestEPoll(unittest.TestCase):
|
||||||
ep.close()
|
ep.close()
|
||||||
self.assertTrue(ep.closed)
|
self.assertTrue(ep.closed)
|
||||||
self.assertRaises(ValueError, ep.fileno)
|
self.assertRaises(ValueError, ep.fileno)
|
||||||
|
select.epoll(select.EPOLL_CLOEXEC).close()
|
||||||
|
self.assertRaises(OSError, select.epoll, flags=12356)
|
||||||
|
|
||||||
def test_badcreate(self):
|
def test_badcreate(self):
|
||||||
self.assertRaises(TypeError, select.epoll, 1, 2, 3)
|
self.assertRaises(TypeError, select.epoll, 1, 2, 3)
|
||||||
|
|
|
@ -422,6 +422,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Add a flags parameter to select.epoll.
|
||||||
|
|
||||||
- Issue #12798: Updated the mimetypes documentation.
|
- Issue #12798: Updated the mimetypes documentation.
|
||||||
|
|
||||||
- Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
|
- Issue #13626: Add support for SSL Diffie-Hellman key exchange, through the
|
||||||
|
|
|
@ -1087,20 +1087,10 @@ pyepoll_internal_close(pyEpoll_Object *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
|
newPyEpoll_Object(PyTypeObject *type, int flags, SOCKET fd)
|
||||||
{
|
{
|
||||||
pyEpoll_Object *self;
|
pyEpoll_Object *self;
|
||||||
|
|
||||||
if (sizehint == -1) {
|
|
||||||
sizehint = FD_SETSIZE-1;
|
|
||||||
}
|
|
||||||
else if (sizehint < 1) {
|
|
||||||
PyErr_Format(PyExc_ValueError,
|
|
||||||
"sizehint must be greater zero, got %d",
|
|
||||||
sizehint);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(type != NULL && type->tp_alloc != NULL);
|
assert(type != NULL && type->tp_alloc != NULL);
|
||||||
self = (pyEpoll_Object *) type->tp_alloc(type, 0);
|
self = (pyEpoll_Object *) type->tp_alloc(type, 0);
|
||||||
if (self == NULL)
|
if (self == NULL)
|
||||||
|
@ -1108,7 +1098,7 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
|
||||||
|
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
self->epfd = epoll_create(sizehint);
|
self->epfd = epoll_create1(flags);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1126,14 +1116,18 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
pyepoll_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
int sizehint = -1;
|
int flags = 0, sizehint = 0;
|
||||||
static char *kwlist[] = {"sizehint", NULL};
|
static char *kwlist[] = {"sizehint", "flags", NULL};
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|i:epoll", kwlist,
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ii:epoll", kwlist,
|
||||||
&sizehint))
|
&sizehint, &flags))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
if (sizehint < 0) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "negative sizehint");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return newPyEpoll_Object(type, sizehint, -1);
|
return newPyEpoll_Object(type, flags, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1191,7 +1185,7 @@ pyepoll_fromfd(PyObject *cls, PyObject *args)
|
||||||
if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
|
if (!PyArg_ParseTuple(args, "i:fromfd", &fd))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return newPyEpoll_Object((PyTypeObject*)cls, -1, fd);
|
return newPyEpoll_Object((PyTypeObject*)cls, 0, fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(pyepoll_fromfd_doc,
|
PyDoc_STRVAR(pyepoll_fromfd_doc,
|
||||||
|
@ -1420,7 +1414,7 @@ static PyGetSetDef pyepoll_getsetlist[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
PyDoc_STRVAR(pyepoll_doc,
|
PyDoc_STRVAR(pyepoll_doc,
|
||||||
"select.epoll([sizehint=-1])\n\
|
"select.epoll(sizehint=-1, flags=0)\n\
|
||||||
\n\
|
\n\
|
||||||
Returns an epolling object\n\
|
Returns an epolling object\n\
|
||||||
\n\
|
\n\
|
||||||
|
@ -2218,6 +2212,8 @@ PyInit_select(void)
|
||||||
PyModule_AddIntConstant(m, "EPOLLWRNORM", EPOLLWRNORM);
|
PyModule_AddIntConstant(m, "EPOLLWRNORM", EPOLLWRNORM);
|
||||||
PyModule_AddIntConstant(m, "EPOLLWRBAND", EPOLLWRBAND);
|
PyModule_AddIntConstant(m, "EPOLLWRBAND", EPOLLWRBAND);
|
||||||
PyModule_AddIntConstant(m, "EPOLLMSG", EPOLLMSG);
|
PyModule_AddIntConstant(m, "EPOLLMSG", EPOLLMSG);
|
||||||
|
|
||||||
|
PyModule_AddIntConstant(m, "EPOLL_CLOEXEC", EPOLL_CLOEXEC);
|
||||||
#endif /* HAVE_EPOLL */
|
#endif /* HAVE_EPOLL */
|
||||||
|
|
||||||
#ifdef HAVE_KQUEUE
|
#ifdef HAVE_KQUEUE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue