mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove unused code
As of python 3.5 socket_pair is supported on windows as well
This commit is contained in:
parent
2375f1c295
commit
e5a5065934
@ -5,8 +5,7 @@
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import errno, socket, select, os, time
|
||||
from contextlib import closing
|
||||
import errno, socket, os, time
|
||||
from email.utils import formatdate
|
||||
from operator import itemgetter
|
||||
|
||||
@ -146,41 +145,10 @@ def stop_cork(sock):
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_CORK, 0)
|
||||
|
||||
|
||||
def create_sock_pair(port=0):
|
||||
def create_sock_pair():
|
||||
'''Create socket pair. Works also on windows by using an ephemeral TCP port.'''
|
||||
if hasattr(socket, 'socketpair'):
|
||||
client_sock, srv_sock = socket.socketpair()
|
||||
set_socket_inherit(client_sock, False), set_socket_inherit(srv_sock, False)
|
||||
return client_sock, srv_sock
|
||||
|
||||
# Create a non-blocking temporary server socket
|
||||
temp_srv_sock = socket.socket()
|
||||
set_socket_inherit(temp_srv_sock, False)
|
||||
temp_srv_sock.setblocking(False)
|
||||
temp_srv_sock.bind(('127.0.0.1', port))
|
||||
port = temp_srv_sock.getsockname()[1]
|
||||
temp_srv_sock.listen(1)
|
||||
with closing(temp_srv_sock):
|
||||
# Create non-blocking client socket
|
||||
client_sock = socket.socket()
|
||||
client_sock.setblocking(False)
|
||||
set_socket_inherit(client_sock, False)
|
||||
try:
|
||||
client_sock.connect(('127.0.0.1', port))
|
||||
except socket.error as err:
|
||||
# EWOULDBLOCK is not an error, as the socket is non-blocking
|
||||
if err.errno not in socket_errors_nonblocking:
|
||||
raise
|
||||
|
||||
# Use select to wait for connect() to succeed.
|
||||
timeout = 1
|
||||
readable = select.select([temp_srv_sock], [], [], timeout)[0]
|
||||
if temp_srv_sock not in readable:
|
||||
raise Exception('Client socket not connected in {} second(s)'.format(timeout))
|
||||
srv_sock = temp_srv_sock.accept()[0]
|
||||
set_socket_inherit(srv_sock, False)
|
||||
client_sock.setblocking(True)
|
||||
|
||||
client_sock, srv_sock = socket.socketpair()
|
||||
set_socket_inherit(client_sock, False), set_socket_inherit(srv_sock, False)
|
||||
return client_sock, srv_sock
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user