|
|
|
@ -22,6 +22,7 @@ pub struct UserStatusMap { |
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: fn insert(&self, UserStatusResponse), since response contains username.
|
|
|
|
// TODO: fn get(&self) -> Option<UserStatusResponse> (returns cloned)
|
|
|
|
|
|
|
|
// TODO: Derive Debug?
|
|
|
|
struct Handler {
|
|
|
|
@ -39,6 +40,7 @@ impl Handler { |
|
|
|
}
|
|
|
|
|
|
|
|
async fn run(mut self) -> io::Result<()> {
|
|
|
|
// TODO: Extract this to a method.
|
|
|
|
match self.frame_stream.read().await? {
|
|
|
|
Some(ServerRequest::LoginRequest(request)) => {
|
|
|
|
info!("Handler: Received login request: {:?}", request);
|
|
|
|
@ -65,9 +67,11 @@ impl Handler { |
|
|
|
self.frame_stream.write(&response).await?;
|
|
|
|
|
|
|
|
while let Some(request) = self.frame_stream.read().await? {
|
|
|
|
// TODO: Extract this.
|
|
|
|
info!("Handler: received request: {:?}", request);
|
|
|
|
match request {
|
|
|
|
ServerRequest::UserStatusRequest(UserStatusRequest { user_name }) => {
|
|
|
|
// TODO: Better interface to UserStatusMap.
|
|
|
|
let entry = self
|
|
|
|
.user_status_map
|
|
|
|
.lock()
|
|
|
|
@ -114,6 +118,13 @@ impl GracefulHandler { |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Rework interface to look like:
|
|
|
|
//
|
|
|
|
// let (server, handle) = FakeServerBuilder::new()
|
|
|
|
// .with_shutdown(shutdown_rx)
|
|
|
|
// .with_user_status_map(map)
|
|
|
|
// .bind().await.unwrap();
|
|
|
|
//
|
|
|
|
/// A fake server for connecting to in tests.
|
|
|
|
pub struct FakeServer {
|
|
|
|
listener: TcpListener,
|
|
|
|
|