refmt server network
This commit is contained in:
parent
8cbee2fcc5
commit
25b05d90fa
|
@ -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.
|
||||
|
|
|
@ -93,4 +93,4 @@ impl From<ProtocolResult<Vec<u8>>> for Package {
|
|||
Err(err) => Package::from(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue