From 465db3c69ad69df013149eaecffc3ac719b177ca Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 26 Jul 2014 14:47:56 +0200 Subject: [PATCH] socketmodule.c: backport INVALID_SOCKET from Python 3.5 to simplify the code --- Modules/socketmodule.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 880f31165a..130b6b3c8c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -94,6 +94,10 @@ Local naming conventions: #include "structmember.h" #include "timefuncs.h" +#ifndef INVALID_SOCKET /* MS defines this */ +#define INVALID_SOCKET (-1) +#endif + #undef MAX #define MAX(x, y) ((x) < (y) ? (y) : (x)) @@ -1705,11 +1709,7 @@ sock_accept(PySocketSockObject *s) return NULL; memset(&addrbuf, 0, addrlen); -#ifdef MS_WINDOWS newfd = INVALID_SOCKET; -#else - newfd = -1; -#endif if (!IS_SELECTABLE(s)) return select_error(); @@ -1727,11 +1727,7 @@ sock_accept(PySocketSockObject *s) } END_SELECT_LOOP(s) -#ifdef MS_WINDOWS if (newfd == INVALID_SOCKET) -#else - if (newfd < 0) -#endif return s->errorhandler(); /* Create the new object with unspecified family, @@ -3185,12 +3181,7 @@ sock_initobj(PyObject *self, PyObject *args, PyObject *kwds) fd = socket(family, type, proto); Py_END_ALLOW_THREADS -#ifdef MS_WINDOWS - if (fd == INVALID_SOCKET) -#else - if (fd < 0) -#endif - { + if (fd == INVALID_SOCKET) { set_error(); return -1; } -- 2.50.1