Fix remaining API issues and borrow conflicts
- Rename display param to target_display to avoid tracing conflict - Refactor session loop to avoid holding borrow across handle_message
This commit is contained in:
@@ -59,8 +59,9 @@ impl SessionManager {
|
||||
|
||||
/// Run the session main loop
|
||||
pub async fn run(&mut self) -> Result<()> {
|
||||
let transport = self.transport.as_mut()
|
||||
.ok_or_else(|| anyhow::anyhow!("Not connected"))?;
|
||||
if self.transport.is_none() {
|
||||
anyhow::bail!("Not connected");
|
||||
}
|
||||
|
||||
self.state = SessionState::Active;
|
||||
|
||||
@@ -91,7 +92,17 @@ impl SessionManager {
|
||||
// Main loop
|
||||
loop {
|
||||
// Check for incoming messages (non-blocking)
|
||||
while let Some(msg) = transport.try_recv()? {
|
||||
// Collect messages first, then release borrow before handling
|
||||
let messages: Vec<Message> = {
|
||||
let transport = self.transport.as_mut().unwrap();
|
||||
let mut msgs = Vec::new();
|
||||
while let Some(msg) = transport.try_recv()? {
|
||||
msgs.push(msg);
|
||||
}
|
||||
msgs
|
||||
};
|
||||
|
||||
for msg in messages {
|
||||
self.handle_message(&mut input, msg)?;
|
||||
}
|
||||
|
||||
@@ -107,6 +118,7 @@ impl SessionManager {
|
||||
let msg = Message {
|
||||
payload: Some(message::Payload::VideoFrame(encoded.frame)),
|
||||
};
|
||||
let transport = self.transport.as_mut().unwrap();
|
||||
transport.send(msg).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user