[Python-checkins] cpython (merge 3.5 -> default): Merge 3.5 (INVALID_SOCKET)
victor.stinner
python-checkins at python.org
Fri Jul 22 11:48:12 EDT 2016
https://hg.python.org/cpython/rev/a4fd4b9cde6d
changeset: 102417:a4fd4b9cde6d
parent: 102415:9abe6b386b42
parent: 102416:025281485318
user: Victor Stinner <victor.stinner at gmail.com>
date: Fri Jul 22 17:47:09 2016 +0200
summary:
Merge 3.5 (INVALID_SOCKET)
files:
Modules/_ssl.c | 8 ++++++--
Modules/socketmodule.c | 12 ++++++------
2 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/Modules/_ssl.c b/Modules/_ssl.c
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -113,6 +113,10 @@
# define HAVE_ALPN
#endif
+#ifndef INVALID_SOCKET /* MS defines this */
+#define INVALID_SOCKET (-1)
+#endif
+
enum py_ssl_error {
/* these mirror ssl.h */
PY_SSL_ERROR_NONE,
@@ -1699,7 +1703,7 @@
}
/* Guard against closed socket */
- if (s->sock_fd < 0)
+ if (s->sock_fd == INVALID_SOCKET)
return SOCKET_HAS_BEEN_CLOSED;
/* Prefer poll, if available, since you can poll() any fd
@@ -2023,7 +2027,7 @@
if (sock != NULL) {
/* Guard against closed socket */
- if ((((PyObject*)sock) == Py_None) || (sock->sock_fd < 0)) {
+ if ((((PyObject*)sock) == Py_None) || (sock->sock_fd == INVALID_SOCKET)) {
_setSSLError("Underlying socket connection gone",
PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__);
return NULL;
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2579,8 +2579,8 @@
int res;
fd = s->sock_fd;
- if (fd != -1) {
- s->sock_fd = -1;
+ if (fd != INVALID_SOCKET) {
+ s->sock_fd = INVALID_SOCKET;
/* We do not want to retry upon EINTR: see
http://lwn.net/Articles/576478/ and
@@ -2606,7 +2606,7 @@
sock_detach(PySocketSockObject *s)
{
SOCKET_T fd = s->sock_fd;
- s->sock_fd = -1;
+ s->sock_fd = INVALID_SOCKET;
return PyLong_FromSocket_t(fd);
}
@@ -4202,7 +4202,7 @@
/* Save the current exception, if any. */
PyErr_Fetch(&error_type, &error_value, &error_traceback);
- if (s->sock_fd != -1) {
+ if (s->sock_fd != INVALID_SOCKET) {
if (PyErr_ResourceWarning((PyObject *)s, 1, "unclosed %R", s)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning)) {
@@ -4215,7 +4215,7 @@
socket.getsockname(). If the socket is closed before, socket
methods fails with the EBADF error. */
fd = s->sock_fd;
- s->sock_fd = -1;
+ s->sock_fd = INVALID_SOCKET;
/* We do not want to retry upon EINTR: see sock_close() */
Py_BEGIN_ALLOW_THREADS
@@ -4275,7 +4275,7 @@
new = type->tp_alloc(type, 0);
if (new != NULL) {
- ((PySocketSockObject *)new)->sock_fd = -1;
+ ((PySocketSockObject *)new)->sock_fd = INVALID_SOCKET;
((PySocketSockObject *)new)->sock_timeout = _PyTime_FromSeconds(-1);
((PySocketSockObject *)new)->errorhandler = &set_error;
}
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list