Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(165260)

Delta Between Two Patch Sets: Modules/selectmodule.c

Issue 18794: select.devpoll objects have no close() method
Left Patch Set: Created 6 years, 3 months ago
Right Patch Set: Created 6 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« Lib/test/test_epoll.py ('K') | « Lib/test/test_kqueue.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* select - Module containing unix select(2) call. 1 /* select - Module containing unix select(2) call.
2 Under Unix, the file descriptors are small integers. 2 Under Unix, the file descriptors are small integers.
3 Under Win32, select only exists for sockets, and sockets may 3 Under Win32, select only exists for sockets, and sockets may
4 have any value except INVALID_SOCKET. 4 have any value except INVALID_SOCKET.
5 */ 5 */
6 6
7 #include "Python.h" 7 #include "Python.h"
8 #include <structmember.h> 8 #include <structmember.h>
9 9
10 #ifdef HAVE_SYS_DEVPOLL_H 10 #ifdef HAVE_SYS_DEVPOLL_H
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 /* 320 /*
321 * poll() support 321 * poll() support
322 */ 322 */
323 323
324 typedef struct { 324 typedef struct {
325 PyObject_HEAD 325 PyObject_HEAD
326 PyObject *dict; 326 PyObject *dict;
327 int ufd_uptodate; 327 int ufd_uptodate;
328 int ufd_len; 328 int ufd_len;
329 struct pollfd *ufds; 329 struct pollfd *ufds;
330 int poll_running;
330 } pollObject; 331 } pollObject;
331 332
332 static PyTypeObject poll_Type; 333 static PyTypeObject poll_Type;
333 334
334 /* Update the malloc'ed array of pollfds to match the dictionary 335 /* Update the malloc'ed array of pollfds to match the dictionary
335 contained within a pollObject. Return 1 on success, 0 on an error. 336 contained within a pollObject. Return 1 on success, 0 on an error.
336 */ 337 */
337 338
338 static int 339 static int
339 update_ufd_array(pollObject *self) 340 update_ufd_array(pollObject *self)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 else { 517 else {
517 tout = PyNumber_Long(tout); 518 tout = PyNumber_Long(tout);
518 if (!tout) 519 if (!tout)
519 return NULL; 520 return NULL;
520 timeout = _PyLong_AsInt(tout); 521 timeout = _PyLong_AsInt(tout);
521 Py_DECREF(tout); 522 Py_DECREF(tout);
522 if (timeout == -1 && PyErr_Occurred()) 523 if (timeout == -1 && PyErr_Occurred())
523 return NULL; 524 return NULL;
524 } 525 }
525 526
527 /* Avoid concurrent poll() invocation, issue 8865 */
528 if (self->poll_running) {
529 PyErr_SetString(PyExc_RuntimeError,
530 "concurrent poll() invocation");
531 return NULL;
532 }
533
526 /* Ensure the ufd array is up to date */ 534 /* Ensure the ufd array is up to date */
527 if (!self->ufd_uptodate) 535 if (!self->ufd_uptodate)
528 if (update_ufd_array(self) == 0) 536 if (update_ufd_array(self) == 0)
529 return NULL; 537 return NULL;
530 538
539 self->poll_running = 1;
540
531 /* call poll() */ 541 /* call poll() */
532 Py_BEGIN_ALLOW_THREADS 542 Py_BEGIN_ALLOW_THREADS
533 poll_result = poll(self->ufds, self->ufd_len, timeout); 543 poll_result = poll(self->ufds, self->ufd_len, timeout);
534 Py_END_ALLOW_THREADS 544 Py_END_ALLOW_THREADS
545
546 self->poll_running = 0;
535 547
536 if (poll_result < 0) { 548 if (poll_result < 0) {
537 PyErr_SetFromErrno(PyExc_OSError); 549 PyErr_SetFromErrno(PyExc_OSError);
538 return NULL; 550 return NULL;
539 } 551 }
540 552
541 /* build the result list */ 553 /* build the result list */
542 554
543 result_list = PyList_New(poll_result); 555 result_list = PyList_New(poll_result);
544 if (!result_list) 556 if (!result_list)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 newPollObject(void) 614 newPollObject(void)
603 { 615 {
604 pollObject *self; 616 pollObject *self;
605 self = PyObject_New(pollObject, &poll_Type); 617 self = PyObject_New(pollObject, &poll_Type);
606 if (self == NULL) 618 if (self == NULL)
607 return NULL; 619 return NULL;
608 /* ufd_uptodate is a Boolean, denoting whether the 620 /* ufd_uptodate is a Boolean, denoting whether the
609 array pointed to by ufds matches the contents of the dictionary. */ 621 array pointed to by ufds matches the contents of the dictionary. */
610 self->ufd_uptodate = 0; 622 self->ufd_uptodate = 0;
611 self->ufds = NULL; 623 self->ufds = NULL;
624 self->poll_running = 0;
612 self->dict = PyDict_New(); 625 self->dict = PyDict_New();
613 if (self->dict == NULL) { 626 if (self->dict == NULL) {
614 Py_DECREF(self); 627 Py_DECREF(self);
615 return NULL; 628 return NULL;
616 } 629 }
617 return self; 630 return self;
618 } 631 }
619 632
620 static void 633 static void
621 poll_dealloc(pollObject *self) 634 poll_dealloc(pollObject *self)
(...skipping 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 /* NETDEV filter flags */ 2416 /* NETDEV filter flags */
2404 #ifdef EVFILT_NETDEV 2417 #ifdef EVFILT_NETDEV
2405 PyModule_AddIntConstant(m, "KQ_NOTE_LINKUP", NOTE_LINKUP); 2418 PyModule_AddIntConstant(m, "KQ_NOTE_LINKUP", NOTE_LINKUP);
2406 PyModule_AddIntConstant(m, "KQ_NOTE_LINKDOWN", NOTE_LINKDOWN); 2419 PyModule_AddIntConstant(m, "KQ_NOTE_LINKDOWN", NOTE_LINKDOWN);
2407 PyModule_AddIntConstant(m, "KQ_NOTE_LINKINV", NOTE_LINKINV); 2420 PyModule_AddIntConstant(m, "KQ_NOTE_LINKINV", NOTE_LINKINV);
2408 #endif 2421 #endif
2409 2422
2410 #endif /* HAVE_KQUEUE */ 2423 #endif /* HAVE_KQUEUE */
2411 return m; 2424 return m;
2412 } 2425 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+