refmt server network
This commit is contained in:
parent
8cbee2fcc5
commit
25b05d90fa
@ -7,8 +7,8 @@ use std::time::Duration;
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn listen_forever<H>(handler: H, config: &ProtocolConfig) -> io::Result<()>
|
pub fn listen_forever<H>(handler: H, config: &ProtocolConfig) -> io::Result<()>
|
||||||
where
|
where
|
||||||
H: 'static + ProtocolHandler + Sized,
|
H: 'static + ProtocolHandler + Sized,
|
||||||
{
|
{
|
||||||
let listener = TcpListener::bind((config.listen_addr.as_str(), config.port))?;
|
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<()>
|
fn client_loop<H>(connection: TcpStream, mut handler: H) -> io::Result<()>
|
||||||
where
|
where
|
||||||
H: 'static + ProtocolHandler + Sized,
|
H: 'static + ProtocolHandler + Sized,
|
||||||
{
|
{
|
||||||
let mut connection = Connection::from_tcp(connection)?;
|
let mut connection = Connection::from_tcp(connection)?;
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
@ -78,9 +78,9 @@ fn client_loop<H>(connection: TcpStream, mut handler: H) -> io::Result<()>
|
|||||||
}
|
}
|
||||||
|
|
||||||
Package::Command(Command::GetTexturePreview {
|
Package::Command(Command::GetTexturePreview {
|
||||||
texture_hash,
|
texture_hash,
|
||||||
desired_format,
|
desired_format,
|
||||||
}) => {
|
}) => {
|
||||||
connection.send(&Package::from(
|
connection.send(&Package::from(
|
||||||
handler.get_texture_preview(texture_hash, desired_format),
|
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 {
|
match pkg {
|
||||||
Package::Binary(data) => {
|
Package::Binary(data) => {
|
||||||
match handler.replace_texture(old.clone(), new.clone(), Some(data))
|
match handler.replace_texture(old.clone(), new.clone(), Some(data))
|
||||||
{
|
{
|
||||||
Ok(ReplaceTextureStatus::Ok) => {
|
Ok(ReplaceTextureStatus::Ok) => {
|
||||||
connection.send(&Package::Json(JsonValue::True))?;
|
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::NeedTextureData(hash)) => {
|
||||||
|
panic!("Contract Violation: handler must not return NeedTextureData \
|
||||||
|
when data is given.");
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
connection.send(&Package::from(err))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Package::Error(_, _) => {
|
Package::Error(_, _) => {
|
||||||
// Just close the connection.
|
// Just close the connection.
|
||||||
|
@ -93,4 +93,4 @@ impl From<ProtocolResult<Vec<u8>>> for Package {
|
|||||||
Err(err) => Package::from(err),
|
Err(err) => Package::from(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user