feat: enhance connection management with logging and status checks
This commit is contained in:
@@ -158,26 +158,43 @@ pub extern "C" fn sdxr_start(app_id: *const std::os::raw::c_char) -> i32 {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
println!("[bridge] Connecting to Stardust server...");
|
||||||
|
|
||||||
// Run the client - asteroids will manage the projector and call reify() each frame
|
// Run the client - asteroids will manage the projector and call reify() each frame
|
||||||
|
// This blocks until the client disconnects or is shut down
|
||||||
ast::client::run::<BridgeState>(&[]).await;
|
ast::client::run::<BridgeState>(&[]).await;
|
||||||
|
|
||||||
|
println!("[bridge] Client disconnected");
|
||||||
let _ = cmd_task;
|
let _ = cmd_task;
|
||||||
});
|
});
|
||||||
drop(rt);
|
drop(rt);
|
||||||
let _ = res;
|
let _ = res;
|
||||||
STARTED.store(false, Ordering::SeqCst);
|
STARTED.store(false, Ordering::SeqCst);
|
||||||
|
CONNECTED.store(false, Ordering::SeqCst);
|
||||||
});
|
});
|
||||||
|
|
||||||
ctrl.rt = None; // runtime consumed inside thread
|
ctrl.rt = None; // runtime consumed inside thread
|
||||||
ctrl.handle = Some(handle);
|
ctrl.handle = Some(handle);
|
||||||
// Store the shared state so we can read from it later
|
// Store the shared state so we can read from it later
|
||||||
ctrl.shared_state = Some(shared_state);
|
ctrl.shared_state = Some(shared_state);
|
||||||
|
|
||||||
|
// Give the async runtime a moment to attempt connection
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
|
||||||
|
// If the thread is still alive, assume connection succeeded
|
||||||
|
// (if it failed immediately, STARTED would be false)
|
||||||
|
if STARTED.load(Ordering::SeqCst) {
|
||||||
|
CONNECTED.store(true, Ordering::SeqCst);
|
||||||
|
}
|
||||||
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn sdxr_poll() -> i32 {
|
pub extern "C" fn sdxr_poll() -> i32 {
|
||||||
if !STARTED.load(Ordering::SeqCst) { return -1; }
|
if !STARTED.load(Ordering::SeqCst) { return -1; }
|
||||||
0
|
// Return 0 if connected and running, -1 if disconnected
|
||||||
|
if CONNECTED.load(Ordering::SeqCst) { 0 } else { -1 }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
Reference in New Issue
Block a user