Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 63890:60076f28c023
Followup to r83869 and issue #8524: rename socket.forget() to socket.detach()
and make it return the file descriptor.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Mon, 09 Aug 2010 20:39:54 +0000 |
| parents | 3f8cef837f07 |
| children | ca2a859e9bf6 |
line wrap: on
line diff
--- a/Modules/socketmodule.c Mon Aug 09 20:01:35 2010 +0000 +++ b/Modules/socketmodule.c Mon Aug 09 20:39:54 2010 +0000 @@ -1870,19 +1870,19 @@ Close the socket. It cannot be used after this call."); static PyObject * -sock_forget(PySocketSockObject *s) +sock_detach(PySocketSockObject *s) { + SOCKET_T fd = s->sock_fd; s->sock_fd = -1; - Py_INCREF(Py_None); - return Py_None; + return PyLong_FromSocket_t(fd); } -PyDoc_STRVAR(forget_doc, -"forget()\n\ +PyDoc_STRVAR(detach_doc, +"detach()\n\ \n\ Close the socket object without closing the underlying file descriptor.\ The object cannot be used after this call, but the file descriptor\ -can be reused for other purposes."); +can be reused for other purposes. The file descriptor is returned."); static int internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen, @@ -2772,10 +2772,10 @@ connect_doc}, {"connect_ex", (PyCFunction)sock_connect_ex, METH_O, connect_ex_doc}, + {"detach", (PyCFunction)sock_detach, METH_NOARGS, + detach_doc}, {"fileno", (PyCFunction)sock_fileno, METH_NOARGS, fileno_doc}, - {"forget", (PyCFunction)sock_forget, METH_NOARGS, - forget_doc}, #ifdef HAVE_GETPEERNAME {"getpeername", (PyCFunction)sock_getpeername, METH_NOARGS, getpeername_doc},
