diff -r a9a38b274b8a Lib/ssl.py --- a/Lib/ssl.py Sat Jun 19 21:58:37 2010 +0200 +++ b/Lib/ssl.py Sun Jun 20 00:13:12 2010 +0200 @@ -79,7 +79,6 @@ from _ssl import ( from socket import getnameinfo as _getnameinfo from socket import error as socket_error -from socket import dup as _dup from socket import socket, AF_INET, SOCK_STREAM import base64 # for DER-to-PEM translation import traceback @@ -148,7 +147,7 @@ class SSLSocket(socket): family=sock.family, type=sock.type, proto=sock.proto, - fileno=_dup(sock.fileno())) + fileno=sock.fileno()) self.settimeout(sock.gettimeout()) # see if it's connected try: @@ -158,7 +157,7 @@ class SSLSocket(socket): raise else: connected = True - sock.close() + sock.forget() elif fileno is not None: socket.__init__(self, fileno=fileno) else: diff -r a9a38b274b8a Modules/socketmodule.c --- a/Modules/socketmodule.c Sat Jun 19 21:58:37 2010 +0200 +++ b/Modules/socketmodule.c Sun Jun 20 00:13:12 2010 +0200 @@ -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},