enh(io): add optional receive timeout when using server
Description
When using `sight::io::igtl::Server to receive messages from client(s) receive (header and Body) are blocking until a data is read from the socket. This can lead to potential deadlocks on some code.
Adding an optional receive timeout can resolve the blocking issue, especially in cases where mutex are involved.
Proposal
- Create an int member variable associated to getter and setter.
- Use std::optional for the value
- If has_value() call
SetReceiveTimeout
on the socket of each client.
Functional specifications
- Nothing should change on actual code
- Using simple setter to set a timeout in ms (same for each client).
- This should be at early stage.
Technical specifications
- Getter / Setter public
- Test in the setter if value is acceptable (> 0), otherwise reset the std::optional
- Timeout should be set after creation of client socket but BEFORE using the client.
runServer
could be the good place, just before pushing newClient in the vector.
Test plan
- Update clientToServer unit test
- Add a timeout when receiving with the server
- Create a test where client never send a message to server
- Check that it throw an tiemout exception.
Edited by Marc SCHWEITZER