[Python-checkins] cpython: Issue #23618: Refactor the _socket module

victor.stinner python-checkins at python.org
Tue Mar 31 14:11:42 CEST 2015


https://hg.python.org/cpython/rev/e8246baad0f6
changeset:   95322:e8246baad0f6
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Mar 31 13:15:31 2015 +0200
summary:
  Issue #23618: Refactor the _socket module

* Inline internal_select() function
* Rename internal_select_ex() internal_select()

files:
  Modules/socketmodule.c |  28 +++++++++++-----------------
  1 files changed, 11 insertions(+), 17 deletions(-)


diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -597,7 +597,7 @@
    after they've reacquired the interpreter lock.
    Returns 1 on timeout, -1 on error, 0 otherwise. */
 static int
-internal_select_ex(PySocketSockObject *s, int writing, _PyTime_t interval)
+internal_select(PySocketSockObject *s, int writing, _PyTime_t interval)
 {
     int n;
 #ifdef HAVE_POLL
@@ -664,12 +664,6 @@
     return 0;
 }
 
-static int
-internal_select(PySocketSockObject *s, int writing)
-{
-    return internal_select_ex(s, writing, s->sock_timeout);
-}
-
 /*
    Two macros for automatic retry of select() in case of false positives
    (for example, select() could indicate a socket is ready for reading
@@ -678,7 +672,7 @@
 
     BEGIN_SELECT_LOOP(s)
 
-    timeout = internal_select_ex(s, 0, interval);
+    timeout = internal_select(s, 0, interval);
 
     if (!timeout) {
         Py_BEGIN_ALLOW_THREADS
@@ -2075,7 +2069,7 @@
 
     BEGIN_SELECT_LOOP(s)
     do {
-        timeout = internal_select_ex(s, 0, interval);
+        timeout = internal_select(s, 0, interval);
 
         if (!timeout) {
             Py_BEGIN_ALLOW_THREADS
@@ -2498,7 +2492,7 @@
     if (s->sock_timeout > 0
         && res < 0 && errno == EINPROGRESS && IS_SELECTABLE(s)) {
 
-        timeout = internal_select(s, 1);
+        timeout = internal_select(s, 1, s->sock_timeout);
 
         if (timeout == 0) {
             /* Bug #1019808: in case of an EINPROGRESS,
@@ -2731,7 +2725,7 @@
 
     BEGIN_SELECT_LOOP(s)
     do {
-        timeout = internal_select_ex(s, 0, interval);
+        timeout = internal_select(s, 0, interval);
 
         if (!timeout) {
             Py_BEGIN_ALLOW_THREADS
@@ -2907,7 +2901,7 @@
     BEGIN_SELECT_LOOP(s)
     do {
         memset(&addrbuf, 0, addrlen);
-        timeout = internal_select_ex(s, 0, interval);
+        timeout = internal_select(s, 0, interval);
 
         if (!timeout) {
             Py_BEGIN_ALLOW_THREADS
@@ -3114,7 +3108,7 @@
         msg.msg_iovlen = iovlen;
         msg.msg_control = controlbuf;
         msg.msg_controllen = controllen;
-        timeout = internal_select_ex(s, 0, interval);
+        timeout = internal_select(s, 0, interval);
 
         if (timeout == 1) {
             PyErr_SetString(socket_timeout, "timed out");
@@ -3407,7 +3401,7 @@
 
     BEGIN_SELECT_LOOP(s)
     do {
-        timeout = internal_select_ex(s, 1, interval);
+        timeout = internal_select(s, 1, interval);
 
         if (!timeout) {
             Py_BEGIN_ALLOW_THREADS
@@ -3464,7 +3458,7 @@
     }
 
     do {
-        timeout = internal_select(s, 1);
+        timeout = internal_select(s, 1, s->sock_timeout);
 
         n = -1;
         if (!timeout) {
@@ -3554,7 +3548,7 @@
 
     BEGIN_SELECT_LOOP(s)
     do {
-        timeout = internal_select_ex(s, 1, interval);
+        timeout = internal_select(s, 1, interval);
 
         if (!timeout) {
             Py_BEGIN_ALLOW_THREADS
@@ -3770,7 +3764,7 @@
 
     BEGIN_SELECT_LOOP(s)
     do {
-        timeout = internal_select_ex(s, 1, interval);
+        timeout = internal_select(s, 1, interval);
 
         if (!timeout) {
             Py_BEGIN_ALLOW_THREADS;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list