WIP, borked
This commit is contained in:
@ -1,33 +1,30 @@
|
||||
use std::io::{self, Error};
|
||||
use crate::minecraft::client::Client;
|
||||
use tokio::net::TcpStream;
|
||||
|
||||
pub async fn process_mc_socket(stream: TcpStream) -> io::Result<()> {
|
||||
let mut buf = vec![0 as u8; 1024];
|
||||
pub async fn process_mc_socket(stream: TcpStream) -> Result<(), String> {
|
||||
println!("new client {:?}", stream);
|
||||
|
||||
let mut client = Client::create(stream);
|
||||
|
||||
loop {
|
||||
client.in_stream.readable().await?;
|
||||
|
||||
match client.in_stream.try_read(&mut buf) {
|
||||
Ok(n) => {
|
||||
let result = client.buffer_append((&buf[..n]).to_vec()).await;
|
||||
if let Err(error) = result {
|
||||
eprintln!("mc error : {}", error);
|
||||
tokio::select! {
|
||||
Ok(()) = client.in_stream.readable() => {
|
||||
println!("[{}] in read", client);
|
||||
let res = client.in_read().await?;
|
||||
if res == 0 {
|
||||
break;
|
||||
}
|
||||
if n == 0 {
|
||||
println!("[{}] continue listening", client);
|
||||
}
|
||||
_ = client.out_readable() => {
|
||||
println!("[{}] out read", client);
|
||||
let res = client.out_read().await?;
|
||||
if res == 0 {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||
continue;
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(e.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user