feat(client): add LocalBridge TCP transport and ServerProcess manager
LocalBridge wraps StreamPeerTCP with 4-byte big-endian length-prefix framing matching server/src/bridge/framing.rs. ServerProcess manages the Rust server as a subprocess via OS.create_process(). Together they form the D-020 IPC transport layer for ticket #79. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
class_name ServerProcess
|
||||
## Manages the Rust simulation server as a subprocess (D-020).
|
||||
|
||||
var _pid: int = -1
|
||||
|
||||
|
||||
## Start the server process. Returns the PID, or -1 on failure.
|
||||
func start(server_path: String, args: Array = []) -> int:
|
||||
if _pid > 0 and is_alive():
|
||||
push_warning("ServerProcess: server already running (pid %d)" % _pid)
|
||||
return _pid
|
||||
_pid = OS.create_process(server_path, args)
|
||||
if _pid <= 0:
|
||||
push_error("ServerProcess: failed to start server at %s" % server_path)
|
||||
return _pid
|
||||
|
||||
|
||||
## Check if the server process is still running.
|
||||
func is_alive() -> bool:
|
||||
if _pid <= 0:
|
||||
return false
|
||||
return OS.is_process_running(_pid)
|
||||
|
||||
|
||||
## Stop the server process.
|
||||
func stop() -> void:
|
||||
if _pid > 0 and is_alive():
|
||||
OS.kill(_pid)
|
||||
_pid = -1
|
||||
|
||||
|
||||
## Get the server PID (-1 if not started).
|
||||
func get_pid() -> int:
|
||||
return _pid
|
||||
|
||||
|
||||
## Clean up on destruction — kill the server if still running.
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_PREDELETE:
|
||||
stop()
|
||||
Reference in New Issue
Block a user