Rename test Server to UnixServer

main
Laurent Pelecq 2 years ago
parent f55ac7aa69
commit 4619b2c57f

@ -18,7 +18,7 @@ use ssip_client::*;
mod server;
#[cfg(feature = "async-mio")]
use server::Server;
use server::UnixServer;
#[cfg(feature = "async-mio")]
struct State<'a, 'b> {
@ -91,7 +91,7 @@ fn basic_async_communication() -> ClientResult<()> {
let socket_dir = tempfile::tempdir()?;
let socket_path = socket_dir.path().join("basic_async_communication.socket");
assert!(!socket_path.exists());
let handle = Server::run(&socket_path, &COMMUNICATION);
let handle = UnixServer::run(&socket_path, &COMMUNICATION);
let mut poll = Poll::new()?;
let mut events = Events::with_capacity(128);
let mut client = QueuedClient::new(fifo::Builder::new().path(&socket_path).build()?);

@ -15,7 +15,7 @@ use std::{io, os::unix::net::UnixStream};
mod server;
#[cfg(not(feature = "async-mio"))]
use server::Server;
use server::UnixServer;
/// Create a server and run the client
///
@ -32,7 +32,7 @@ where
let socket_path = socket_dir.path().join("test_client.socket");
assert!(!socket_path.exists());
let mut process_wrapper = std::panic::AssertUnwindSafe(process);
let handle = Server::run(&socket_path, communication);
let handle = UnixServer::run(&socket_path, communication);
let mut client = ssip_client::fifo::Builder::new()
.path(&socket_path)
.build()?;

@ -13,12 +13,12 @@ use std::thread;
use std::os::unix::net::UnixListener;
/// Server on a named socket.
pub struct Server {
pub struct UnixServer {
listener: UnixListener,
communication: Vec<(&'static str, &'static str)>,
}
impl Server {
impl UnixServer {
/// Create a new server on a named socket.
///
/// Argument `communication` is an array of pairs. The first item is a list of strings
@ -31,7 +31,7 @@ impl Server {
P: AsRef<Path>,
{
let listener = UnixListener::bind(socket_path.as_ref())?;
Ok(Server {
Ok(Self {
listener,
communication: communication.to_vec(),
})
@ -50,7 +50,7 @@ impl Server {
let mut input = BufReader::new(stream.try_clone()?);
let mut output = BufWriter::new(stream);
for (questions, answer) in self.communication.iter() {
for question in Server::split_lines(questions).iter() {
for question in Self::split_lines(questions).iter() {
let mut line = String::new();
input.read_line(&mut line)?;
if line != *question {
@ -74,7 +74,7 @@ impl Server {
P: AsRef<Path>,
{
let server_path = socket_path.as_ref().to_path_buf();
let mut server = Server::new(&server_path, communication).unwrap();
let mut server = Self::new(&server_path, communication).unwrap();
thread::spawn(move || -> io::Result<()> {
server.serve()?;
Ok(())
@ -85,12 +85,12 @@ impl Server {
#[cfg(test)]
mod test {
use super::Server;
use super::UnixServer;
#[test]
fn test_split_lines() {
const ONE_LINE: &str = "one line\r\n";
let one_line = Server::split_lines(ONE_LINE);
let one_line = UnixServer::split_lines(ONE_LINE);
assert_eq!(&[ONE_LINE], one_line.as_slice());
}
}

Loading…
Cancel
Save