I have a piece of code that binds to a Unix Domain Socket and accepts connections.
This code works and prints the Bind successful message and if there are connections from a client does process it .
Is there a way to time out in the accept ? The server listens to a socket path while the clients attempts to connect to a different socket path . I would like to have a timeout in the server and handle the case of not receiving a connection after X seconds .
The timeouts in the UDS seems to be for the read / write and not for the accept . Any help will be appreciated .
let mut listener_res = UnixListener::bind(&socket);
if listener_res.is_err() {
// Socket is being used by somebody else
}
match listener_res {
Ok(listener)=>{
info!("Bind successful{}!",socket.display());
match listener.accept().await { // I need a timeout here
Ok(listener)=>{
// Process this code
}
Err => {
// Error on socket
}
}
}
}