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

Skip to content

Commit d3afb62

Browse files
committed
Merge 3.5 (INVALID_SOCKET)
2 parents 5e1989c + 524714e commit d3afb62

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Modules/_ssl.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ struct py_ssl_library_code {
113113
# define HAVE_ALPN
114114
#endif
115115

116+
#ifndef INVALID_SOCKET /* MS defines this */
117+
#define INVALID_SOCKET (-1)
118+
#endif
119+
116120
enum py_ssl_error {
117121
/* these mirror ssl.h */
118122
PY_SSL_ERROR_NONE,
@@ -1699,7 +1703,7 @@ PySSL_select(PySocketSockObject *s, int writing, _PyTime_t timeout)
16991703
}
17001704

17011705
/* Guard against closed socket */
1702-
if (s->sock_fd < 0)
1706+
if (s->sock_fd == INVALID_SOCKET)
17031707
return SOCKET_HAS_BEEN_CLOSED;
17041708

17051709
/* Prefer poll, if available, since you can poll() any fd
@@ -2023,7 +2027,7 @@ _ssl__SSLSocket_shutdown_impl(PySSLSocket *self)
20232027

20242028
if (sock != NULL) {
20252029
/* Guard against closed socket */
2026-
if ((((PyObject*)sock) == Py_None) || (sock->sock_fd < 0)) {
2030+
if ((((PyObject*)sock) == Py_None) || (sock->sock_fd == INVALID_SOCKET)) {
20272031
_setSSLError("Underlying socket connection gone",
20282032
PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__);
20292033
return NULL;

Modules/socketmodule.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,8 +2579,8 @@ sock_close(PySocketSockObject *s)
25792579
int res;
25802580

25812581
fd = s->sock_fd;
2582-
if (fd != -1) {
2583-
s->sock_fd = -1;
2582+
if (fd != INVALID_SOCKET) {
2583+
s->sock_fd = INVALID_SOCKET;
25842584

25852585
/* We do not want to retry upon EINTR: see
25862586
http://lwn.net/Articles/576478/ and
@@ -2606,7 +2606,7 @@ static PyObject *
26062606
sock_detach(PySocketSockObject *s)
26072607
{
26082608
SOCKET_T fd = s->sock_fd;
2609-
s->sock_fd = -1;
2609+
s->sock_fd = INVALID_SOCKET;
26102610
return PyLong_FromSocket_t(fd);
26112611
}
26122612

@@ -4202,7 +4202,7 @@ sock_finalize(PySocketSockObject *s)
42024202
/* Save the current exception, if any. */
42034203
PyErr_Fetch(&error_type, &error_value, &error_traceback);
42044204

4205-
if (s->sock_fd != -1) {
4205+
if (s->sock_fd != INVALID_SOCKET) {
42064206
if (PyErr_ResourceWarning((PyObject *)s, 1, "unclosed %R", s)) {
42074207
/* Spurious errors can appear at shutdown */
42084208
if (PyErr_ExceptionMatches(PyExc_Warning)) {
@@ -4215,7 +4215,7 @@ sock_finalize(PySocketSockObject *s)
42154215
socket.getsockname(). If the socket is closed before, socket
42164216
methods fails with the EBADF error. */
42174217
fd = s->sock_fd;
4218-
s->sock_fd = -1;
4218+
s->sock_fd = INVALID_SOCKET;
42194219

42204220
/* We do not want to retry upon EINTR: see sock_close() */
42214221
Py_BEGIN_ALLOW_THREADS
@@ -4275,7 +4275,7 @@ sock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
42754275

42764276
new = type->tp_alloc(type, 0);
42774277
if (new != NULL) {
4278-
((PySocketSockObject *)new)->sock_fd = -1;
4278+
((PySocketSockObject *)new)->sock_fd = INVALID_SOCKET;
42794279
((PySocketSockObject *)new)->sock_timeout = _PyTime_FromSeconds(-1);
42804280
((PySocketSockObject *)new)->errorhandler = &set_error;
42814281
}

0 commit comments

Comments
 (0)