refmt server network

This commit is contained in:
CodeSteak 2019-04-25 23:37:53 +02:00
parent 8cbee2fcc5
commit 25b05d90fa
2 changed files with 19 additions and 19 deletions

View File

@ -7,8 +7,8 @@ use std::time::Duration;
use super::*;
pub fn listen_forever<H>(handler: H, config: &ProtocolConfig) -> io::Result<()>
where
H: 'static + ProtocolHandler + Sized,
where
H: 'static + ProtocolHandler + Sized,
{
let listener = TcpListener::bind((config.listen_addr.as_str(), config.port))?;
@ -29,8 +29,8 @@ pub fn listen_forever<H>(handler: H, config: &ProtocolConfig) -> io::Result<()>
}
fn client_loop<H>(connection: TcpStream, mut handler: H) -> io::Result<()>
where
H: 'static + ProtocolHandler + Sized,
where
H: 'static + ProtocolHandler + Sized,
{
let mut connection = Connection::from_tcp(connection)?;
'outer: loop {
@ -78,9 +78,9 @@ fn client_loop<H>(connection: TcpStream, mut handler: H) -> io::Result<()>
}
Package::Command(Command::GetTexturePreview {
texture_hash,
desired_format,
}) => {
texture_hash,
desired_format,
}) => {
connection.send(&Package::from(
handler.get_texture_preview(texture_hash, desired_format),
))?;
@ -101,18 +101,18 @@ fn client_loop<H>(connection: TcpStream, mut handler: H) -> io::Result<()>
match pkg {
Package::Binary(data) => {
match handler.replace_texture(old.clone(), new.clone(), Some(data))
{
Ok(ReplaceTextureStatus::Ok) => {
connection.send(&Package::Json(JsonValue::True))?;
}
Ok(ReplaceTextureStatus::NeedTextureData(hash)) => {
panic!("Contract Violation: handler must not return NeedTextureData \
when data is given.");
}
Err(err) => {
connection.send(&Package::from(err))?;
}
{
Ok(ReplaceTextureStatus::Ok) => {
connection.send(&Package::Json(JsonValue::True))?;
}
Ok(ReplaceTextureStatus::NeedTextureData(hash)) => {
panic!("Contract Violation: handler must not return NeedTextureData \
when data is given.");
}
Err(err) => {
connection.send(&Package::from(err))?;
}
}
}
Package::Error(_, _) => {
// Just close the connection.

View File

@ -93,4 +93,4 @@ impl From<ProtocolResult<Vec<u8>>> for Package {
Err(err) => Package::from(err),
}
}
}
}