summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-08-08 23:24:50 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-08-08 23:24:50 (GMT)
commite43f9d0ed69addbc34bac4af1b3ad7f1bdd3b149 (patch)
treee15aa8c051472ddb7ec9a684d9a4e546ee3e14ca /Modules
parentba8a98600eddc5e2a87a9148e634ada1a1056495 (diff)
downloadcpython-e43f9d0ed69addbc34bac4af1b3ad7f1bdd3b149.zip
cpython-e43f9d0ed69addbc34bac4af1b3ad7f1bdd3b149.tar.gz
cpython-e43f9d0ed69addbc34bac4af1b3ad7f1bdd3b149.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/socketmodule.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 563bdea..fc671e0 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1869,6 +1869,21 @@ PyDoc_STRVAR(close_doc,
\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 @@ static PyMethodDef sock_methods[] = {
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},