From 39eb8fa0dbbcd6568fceb7ca59220aa3281e0cc4 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 16 Nov 2007 01:24:05 +0000 Subject: This is roughly socket2.diff from issue 1378, with a few changes applied to ssl.py (no need to test whether we can dup any more). Regular sockets no longer have a _base, but we still have explicit reference counting of socket objects for the benefit of makefile(); using duplicate sockets won't work for SSLSocket. --- Lib/ssl.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'Lib/ssl.py') diff --git a/Lib/ssl.py b/Lib/ssl.py index c2cfa31c44..9d63d12ce3 100644 --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -78,8 +78,8 @@ from _ssl import ( from socket import socket, AF_INET, SOCK_STREAM, error from socket import getnameinfo as _getnameinfo from socket import error as socket_error +from socket import dup as _dup import base64 # for DER-to-PEM translation -_can_dup_socket = hasattr(socket, "dup") class SSLSocket(socket): @@ -99,20 +99,11 @@ class SSLSocket(socket): if sock is not None: # copied this code from socket.accept() fd = sock.fileno() - nfd = fd - if _can_dup_socket: - nfd = os.dup(fd) - try: - socket.__init__(self, family=sock.family, type=sock.type, - proto=sock.proto, fileno=nfd) - except: - if nfd != fd: - os.close(nfd) - else: - if fd != nfd: - sock.close() - sock = None - + nfd = _dup(fd) + socket.__init__(self, family=sock.family, type=sock.type, + proto=sock.proto, fileno=nfd) + sock.close() + sock = None elif fileno is not None: socket.__init__(self, fileno=fileno) else: -- cgit v1.2.1