Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket in _refuses_connection is now blocking. #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions port_for/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ def _refuses_connection(port, host):
sock = socket.socket()
with contextlib.closing(sock):
sock.settimeout(1)
sock.setblocking(True)
err = sock.connect_ex((host, port))
return err == errno.ECONNREFUSED
8 changes: 4 additions & 4 deletions port_for/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def test_binding():


def test_binding_high():
port = port_for.available_good_ports().pop()
s = socket.socket()
s.bind(("", 0))
port = s.getsockname()[1]
assert port_for.port_is_used(port) == True
s.bind(("127.0.0.1", port))
assert port_for.port_is_used(port) is True
s.close()
assert port_for.port_is_used(port) == False
assert port_for.port_is_used(port) is False


class SelectPortTest(unittest.TestCase):
Expand Down