Fixed the code, apparently there's nothing actually wrong with it

This commit is contained in:
techmetx11 2024-05-02 14:00:56 +01:00
parent 6bd9b67176
commit fda0eeb863
No known key found for this signature in database
GPG Key ID: 20E0C88A0E7E5AF2
2 changed files with 4 additions and 5 deletions

View File

@ -62,7 +62,7 @@ async fn main() {
Ok(x) => x, Ok(x) => x,
Err(x) => { Err(x) => {
if x.kind() == std::io::ErrorKind::AddrInUse { if x.kind() == std::io::ErrorKind::AddrInUse {
remove_file(socket_url); remove_file(socket_url).await;
UnixListener::bind(socket_url).unwrap() UnixListener::bind(socket_url).unwrap()
} else { } else {
println!("Error occurred while trying to bind: {}", x); println!("Error occurred while trying to bind: {}", x);
@ -89,12 +89,10 @@ async fn main() {
} }
async fn process_socket(state: Arc<GlobalState>, socket: UnixStream) { async fn process_socket(state: Arc<GlobalState>, socket: UnixStream) {
let (rd, wr) = socket.into_split();
let decoder = OpcodeDecoder {}; let decoder = OpcodeDecoder {};
let str = Framed::new(socket, decoder);
let sink = FramedWrite::new(wr, decoder); let (sink, mut stream) = str.split();
let mut stream = FramedRead::new(rd, decoder);
let arc_sink = Arc::new(Mutex::new(sink)); let arc_sink = Arc::new(Mutex::new(sink));
while let Some(opcode_res) = stream.next().await { while let Some(opcode_res) = stream.next().await {

View File

@ -34,6 +34,7 @@ impl Decoder for OpcodeDecoder {
&mut self, &mut self,
src: &mut tokio_util::bytes::BytesMut, src: &mut tokio_util::bytes::BytesMut,
) -> Result<Option<Self::Item>, Self::Error> { ) -> Result<Option<Self::Item>, Self::Error> {
println!("Decoder length: {}", src.len());
if 5 > src.len() { if 5 > src.len() {
return Ok(None); return Ok(None);
} }