mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-35934: Add socket.create_server() utility function (GH-11784)
This commit is contained in:
parent
58721a9030
commit
eb7e29f2a9
17 changed files with 289 additions and 88 deletions
|
@ -302,26 +302,7 @@ class FTP:
|
|||
|
||||
def makeport(self):
|
||||
'''Create a new socket and send a PORT command for it.'''
|
||||
err = None
|
||||
sock = None
|
||||
for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
|
||||
af, socktype, proto, canonname, sa = res
|
||||
try:
|
||||
sock = socket.socket(af, socktype, proto)
|
||||
sock.bind(sa)
|
||||
except OSError as _:
|
||||
err = _
|
||||
if sock:
|
||||
sock.close()
|
||||
sock = None
|
||||
continue
|
||||
break
|
||||
if sock is None:
|
||||
if err is not None:
|
||||
raise err
|
||||
else:
|
||||
raise OSError("getaddrinfo returns an empty list")
|
||||
sock.listen(1)
|
||||
sock = socket.create_server(("", 0), family=self.af, backlog=1)
|
||||
port = sock.getsockname()[1] # Get proper port
|
||||
host = self.sock.getsockname()[0] # Get proper host
|
||||
if self.af == socket.AF_INET:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue