mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 10:07:14 +02:00
Improve detecting of a run PIO Home Server
This commit is contained in:
@ -21,6 +21,7 @@ from os.path import isdir
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from platformio import exception
|
from platformio import exception
|
||||||
|
from platformio.compat import WINDOWS
|
||||||
from platformio.managers.core import get_core_package_dir, inject_contrib_pysite
|
from platformio.managers.core import get_core_package_dir, inject_contrib_pysite
|
||||||
|
|
||||||
|
|
||||||
@ -123,11 +124,20 @@ def cli(port, host, no_open, shutdown_timeout):
|
|||||||
|
|
||||||
|
|
||||||
def is_port_used(host, port):
|
def is_port_used(host, port):
|
||||||
try:
|
socket.setdefaulttimeout(1)
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
s.bind((host, port))
|
if WINDOWS:
|
||||||
s.close()
|
try:
|
||||||
return False
|
s.bind((host, port))
|
||||||
except (OSError, socket.error):
|
s.close()
|
||||||
pass
|
return False
|
||||||
|
except (OSError, socket.error):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
s.connect((host, port))
|
||||||
|
s.close()
|
||||||
|
except socket.error:
|
||||||
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
Reference in New Issue
Block a user