Adapted from a patch by Barry Scott, SF patch #102875 and SF bug

#125981: closing sockets was not thread-safe.
This commit is contained in:
Guido van Rossum 2000-12-18 22:23:44 +00:00
parent 99664e455b
commit 20d3fc071b

View file

@ -904,14 +904,15 @@ pair (host, port); the host must refer to the local host.";
static PyObject * static PyObject *
PySocketSock_close(PySocketSockObject *s, PyObject *args) PySocketSock_close(PySocketSockObject *s, PyObject *args)
{ {
SOCKET_T fd;
if (!PyArg_ParseTuple(args, ":close")) if (!PyArg_ParseTuple(args, ":close"))
return NULL; return NULL;
if (s->sock_fd != -1) { if ((fd = s->sock_fd) != -1) {
s->sock_fd = -1;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
(void) SOCKETCLOSE(s->sock_fd); (void) SOCKETCLOSE(fd);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
} }
s->sock_fd = -1;
Py_INCREF(Py_None); Py_INCREF(Py_None);
return Py_None; return Py_None;
} }