Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f84d1b9

Browse files
committed
Introduce Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE.
Proposed by Tim Peters.
1 parent 03ca23d commit f84d1b9

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

Modules/_ssl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,10 @@ check_socket_and_wait_for_timeout(PySocketSockObject *s, int writing)
377377
return SOCKET_HAS_BEEN_CLOSED;
378378

379379
/* Guard against socket too large for select*/
380+
#ifndef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
380381
if (s->sock_fd >= FD_SETSIZE)
381382
return SOCKET_INVALID;
383+
#endif
382384

383385
/* Construct the arguments to select */
384386
tv.tv_sec = (int)s->sock_timeout;

Modules/socketmodule.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,14 @@ static int taskwindow;
396396
static PyTypeObject sock_type;
397397

398398
/* Can we call select() with this socket without a buffer overrun? */
399+
#ifdef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
400+
/* Platform can select file descriptors beyond FD_SETSIZE */
401+
#define IS_SELECTABLE(s) 1
402+
#else
403+
/* POSIX says selecting file descriptors beyond FD_SETSIZE
404+
has undefined behaviour. */
399405
#define IS_SELECTABLE(s) ((s)->sock_fd < FD_SETSIZE)
406+
#endif
400407

401408
static PyObject*
402409
select_error(void)

PC/pyconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,4 +572,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
572572

573573
/* Define if you have the thread library (-lthread). */
574574
/* #undef HAVE_LIBTHREAD */
575+
576+
/* WinSock does not use a bitmask in select, and uses
577+
socket handles greater than FD_SETSIZE */
578+
#define Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
579+
575580
#endif /* !Py_CONFIG_H */

0 commit comments

Comments
 (0)