I am using sockets from socket2 crate to implement a server that will receive stream of data from clients and then use
serde to deserialize.
serde has a
from_reader that can deserialize directly from the stream without buffering in memory
Since the sockets from
socket2 crate implement
Read trait, I've been trying something similar to this:
let (sock, addr) = server_socket.accept().unwrap(); let payload: MyStruct = serde_json::from_reader(sock).unwrap();
This only works if the client
drops its socket to signal an
EOF which then causes
from_reader() to finish & return.
But if client keeps the socket active (say we want to have more back and forth communication), then the above
from_reader does not return and blocks forever.
So do I have to kill/shutdown my client's socket every time to just send one payload and create a new socket for another payload? (doesn't seem right to me!)
Is there a way I can keep the socket active/open but signal to
from_reader an EOF?
By the way the socket type I am using are Unix-domain socket since the client & server will always be on the same machine.
Do you know of any example/source that achieves something similar to this in Rust so I can take a look?
Should I implement my own version of
Thanks in advance for you response!