|
|
|
@ -1,22 +1,18 @@ |
|
|
|
//! Provides utilities for testing protocol code.
|
|
|
|
// TODO: Move this to a separate crate, so that it can be depended upon as a
|
|
|
|
// dev dependency in tests and run standalone as examples. Layering should be:
|
|
|
|
// solstice-client -(dev)-> solstice-server -> solstice-proto
|
|
|
|
|
|
|
|
use std::io;
|
|
|
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
|
|
|
|
|
|
|
use anyhow::{bail, Context};
|
|
|
|
use log::{info, warn};
|
|
|
|
use solstice_proto::core::{FrameReader, FrameWriter, Worker};
|
|
|
|
use solstice_proto::server::{LoginResponse, ServerRequest, ServerResponse};
|
|
|
|
use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf};
|
|
|
|
use tokio::net::{TcpListener, TcpStream};
|
|
|
|
use tokio::sync::mpsc;
|
|
|
|
use tokio::sync::oneshot;
|
|
|
|
use tokio::sync::watch;
|
|
|
|
|
|
|
|
use crate::core::{FrameReader, FrameWriter, Worker};
|
|
|
|
use crate::server::{LoginResponse, ServerRequest, ServerResponse};
|
|
|
|
|
|
|
|
/// A handler for a single client connected to the server.
|
|
|
|
pub trait ClientHandler {
|
|
|
|
/// Runs this handler against the given incoming stream of requests.
|
|
|
|
@ -300,6 +296,7 @@ where |
|
|
|
///
|
|
|
|
/// Useful for tests who need to guarantee a handler is spawned before the
|
|
|
|
/// server shuts down.
|
|
|
|
#[cfg(test)]
|
|
|
|
async fn accept(&mut self) -> io::Result<()> {
|
|
|
|
let (stream, peer_address) = self.listener.accept().await?;
|
|
|
|
self.spawn_handler(stream, peer_address);
|