Skip to content

Commit

Permalink
feat(server): add Quit event (#505)
Browse files Browse the repository at this point in the history
Learn to exit the run() loop from user.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
  • Loading branch information
elmarco authored Jul 26, 2024
1 parent 9410f53 commit b6a839e
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions crates/ironrdp-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub struct RdpServer {

#[derive(Debug)]
pub enum ServerEvent {
Quit(String),
Clipboard(ClipboardMessage),
Rdpsnd(RdpsndServerMessage),
}
Expand Down Expand Up @@ -266,10 +267,26 @@ impl RdpServer {
let listener = TcpListener::bind(self.opts.addr).await?;

debug!("Listening for connections");
while let Ok((stream, peer)) = listener.accept().await {
debug!(?peer, "Received connection");
if let Err(error) = self.run_connection(stream).await {
error!(?error, "Connection error");
loop {
tokio::select! {
Some(event) = self.ev_receiver.recv() => {
match event {
ServerEvent::Quit(reason) => {
debug!("Got quit event {reason}");
break;
}
ev => {
debug!("Unexpected event {:?}", ev);
}
}
},
Ok((stream, peer)) = listener.accept() => {
debug!(?peer, "Received connection");
if let Err(error) = self.run_connection(stream).await {
error!(?error, "Connection error");
}
}
else => break,
}
}

Expand Down Expand Up @@ -430,6 +447,10 @@ impl RdpServer {

Some(event) = self.ev_receiver.recv() => {
match event {
ServerEvent::Quit(reason) => {
debug!("Got quit event: {reason}");
break;
}
ServerEvent::Rdpsnd(s) => {
let Some(rdpsnd) = self.get_svc_processor::<RdpsndServer>() else {
warn!("No rdpsnd channel, dropping event");
Expand Down Expand Up @@ -494,6 +515,7 @@ impl RdpServer {

}
}
else => break,
}
}

Expand Down

0 comments on commit b6a839e

Please sign in to comment.