mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 01:10:01 +00:00
fix using errno module instead of hardcoded
since error code numbers differ based on OS
This commit is contained in:
@@ -25,6 +25,7 @@ from typing import Any, Dict, Optional
|
|||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import errno
|
||||||
import subprocess
|
import subprocess
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import asyncio
|
import asyncio
|
||||||
@@ -59,11 +60,11 @@ class Web(blenderbim.core.tool.Web):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def is_port_available(cls, port):
|
def is_port_available(cls, port):
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
# connect_ex returns 0 if the connection succeeds
|
# connect_ex returns errno.SUCCESS (0) if the connection succeeds
|
||||||
# indicating the port is in use
|
# indicating the port is in use
|
||||||
# otherwise returns 10061 if no server is listening
|
# otherwise returns errno.ECONNREFUSED (111 or 10061) if no server is listening
|
||||||
# indicating the port is available for use
|
# indicating the port is available for use
|
||||||
return s.connect_ex(("localhost", port)) == 10061
|
return s.connect_ex(("localhost", port)) == errno.ECONNREFUSED
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def start_websocket_server(cls, port):
|
def start_websocket_server(cls, port):
|
||||||
|
|||||||
Reference in New Issue
Block a user