Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 63856:3f8cef837f07
Issue #8524: Add a forget() method to socket objects, so as to put the
socket into the closed state without closing the underlying file
descriptor.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Sun, 08 Aug 2010 23:24:50 +0000 |
| parents | cab14be0ada1 |
| children | 60076f28c023 |
line wrap: on
line diff
--- a/Modules/socketmodule.c Sun Aug 08 23:08:41 2010 +0000 +++ b/Modules/socketmodule.c Sun Aug 08 23:24:50 2010 +0000 @@ -1869,6 +1869,21 @@ \n\ Close the socket. It cannot be used after this call."); +static PyObject * +sock_forget(PySocketSockObject *s) +{ + s->sock_fd = -1; + Py_INCREF(Py_None); + return Py_None; +} + +PyDoc_STRVAR(forget_doc, +"forget()\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."); + static int internal_connect(PySocketSockObject *s, struct sockaddr *addr, int addrlen, int *timeoutp) @@ -2759,6 +2774,8 @@ connect_ex_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},
