fix: 把服务端错误直接写进 last_error
This commit is contained in:
@@ -39,9 +39,9 @@ def utc_iso_now() -> str:
|
||||
|
||||
|
||||
def load_omnisocket_api():
|
||||
from omnisocket import CONTROL_DEFAULTS, MSG_TYPE_BINARY, Session
|
||||
from omnisocket import CONTROL_DEFAULTS, MSG_TYPE_BINARY, MSG_TYPE_ERROR, Session
|
||||
|
||||
return CONTROL_DEFAULTS, MSG_TYPE_BINARY, Session
|
||||
return CONTROL_DEFAULTS, MSG_TYPE_BINARY, MSG_TYPE_ERROR, Session
|
||||
|
||||
|
||||
def _merge_kcp_defaults(defaults: dict[str, Any], override: dict[str, Any]) -> dict[str, Any]:
|
||||
@@ -115,7 +115,7 @@ def _load_config(config_path: str | None) -> dict[str, Any]:
|
||||
with path.open("r", encoding="utf-8") as file:
|
||||
raw = yaml.safe_load(file) or {}
|
||||
|
||||
control_defaults, _msg_type_binary, _session_cls = load_omnisocket_api()
|
||||
control_defaults, _msg_type_binary, _msg_type_error, _session_cls = load_omnisocket_api()
|
||||
transport = dict(raw.get("transport", {}))
|
||||
control = dict(raw.get("control_receiver", {}))
|
||||
video = dict(raw.get("video_sender", {}))
|
||||
@@ -193,12 +193,13 @@ def _load_config(config_path: str | None) -> dict[str, Any]:
|
||||
|
||||
class ControlRecvManager:
|
||||
def __init__(self, config: dict[str, Any]) -> None:
|
||||
control_defaults, msg_type_binary, session_cls = load_omnisocket_api()
|
||||
control_defaults, msg_type_binary, msg_type_error, session_cls = load_omnisocket_api()
|
||||
transport = config["transport"]
|
||||
control_cfg = config["control_receiver"]
|
||||
daemon_cfg = config["daemon"]
|
||||
|
||||
self._msg_type_binary = msg_type_binary
|
||||
self._msg_type_error = msg_type_error
|
||||
self._session_cls = session_cls
|
||||
self._connect_kwargs = {
|
||||
"server_addr": transport["server_addr"],
|
||||
@@ -307,6 +308,7 @@ class ControlRecvManager:
|
||||
if msg_type != self._msg_type_binary:
|
||||
with self._lock:
|
||||
self._ignored_non_binary += 1
|
||||
self._disconnect(self._describe_unexpected_message(msg_type, payload))
|
||||
continue
|
||||
if len(payload) != CONTROL_PACKET_STRUCT.size:
|
||||
with self._lock:
|
||||
@@ -346,6 +348,14 @@ class ControlRecvManager:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _describe_unexpected_message(self, msg_type: int, payload: bytes) -> str:
|
||||
detail = payload.decode("utf-8", errors="replace").strip()
|
||||
if msg_type == self._msg_type_error:
|
||||
return f"control session rejected by server: {detail or 'unknown error'}"
|
||||
if detail:
|
||||
return f"received unexpected control message type {msg_type}: {detail}"
|
||||
return f"received unexpected control message type {msg_type}"
|
||||
|
||||
def _enqueue_packet(self, payload: bytes) -> None:
|
||||
try:
|
||||
self._queue.put_nowait(payload)
|
||||
|
||||
Reference in New Issue
Block a user