8000 Detach socket in create_server, create_connection, and other APIs by 1st1 · Pull Request #449 · python/asyncio · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 23, 2017. It is now read-only.

Detach socket in create_server, create_connection, and other APIs #449

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address Victor's comments
  • Loading branch information
1st1 committed Oct 19, 2016
commit f1202eb441005e18df6be0826a5d090da05cd6e8
8 changes: 4 additions & 4 deletions asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def _set_reuseport(sock):


def _copy_and_detach_socket(sock):
new_sock = socket.socket(sock.family, sock.type, sock.proto, sock.fileno())
sock.detach()
fd = sock.detach()
new_sock = socket.socket(sock.family, sock.type, sock.proto, fd)
return new_sock


Expand Down Expand Up @@ -835,8 +835,8 @@ def create_datagram_endpoint(self, protocol_factory,
raise ValueError(
'socket modifier keyword arguments can not be used '
'when sock is specified. ({})'.format(problems))
sock = _copy_and_detach_socket(sock)
sock.setblocking(False)
sock = _copy_and_detach_socket(sock)
r_addr = None
else:
if not (local_addr or remote_addr):
Expand Down Expand Up @@ -1055,7 +1055,7 @@ def connect_accepted_socket(self, protocol_factory, sock, *, ssl=None):
This method is a coroutine. When completed, the coroutine
returns a (transport, protocol) pair.
"""
sock = _copy_and_detach_socket(sock)

transport, protocol = yield from self._create_connection_transport(
sock, protocol_factory, ssl, '', server_side=True)
if self._debug:
Expand Down
1 change: 1 addition & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,7 @@ def connection_made(self, transport):
server = self.loop.run_until_complete(f)
sock = server.sockets[0]
self.assertEqual(sock.fileno(), sock_ob_fd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check that sock_ob is detach: sock_ob.fileno() must be equal to -1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

self.assertEqual(sock_ob.fileno(), -1)

host, port = sock.getsockname()
self.assertEqual(host, '0.0.0.0')
Expand Down
0