Skip to content

Commit

Permalink
Improve detecting of a run PIO Home Server
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Dec 9, 2019
1 parent 09852dc commit 31eed6c
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions platformio/commands/home/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import click

from platformio import exception
from platformio.compat import WINDOWS
from platformio.managers.core import get_core_package_dir, inject_contrib_pysite


Expand Down Expand Up @@ -123,11 +124,20 @@ def cli(port, host, no_open, shutdown_timeout):


def is_port_used(host, port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
s.close()
return False
except (OSError, socket.error):
pass
socket.setdefaulttimeout(1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if WINDOWS:
try:
s.bind((host, port))
s.close()
return False
except (OSError, socket.error):
pass
else:
try:
s.connect((host, port))
s.close()
except socket.error:
return False

return True

0 comments on commit 31eed6c

Please sign in to comment.