Add support for socket timeouts
Summary
When working with sockets, it may be desired to set a timeout for a certain operation. For example, one may wish to wait for a connection to come in but for no more than 5 seconds. Inko should support timeouts for sockets.
Implementation
This isn't clear just yet. The regular socket timeout options won't work, as sockets are non-blocking. Our IO poller in turn polls indefinitely. Probably we'll need to do something like this before performing certain socket operations:
- Check if the operation would block
- Check if a timeout for the operation is set
- If so, register the process with the timeout worker and the IO poller
- When either of these is about to reschedule a process, they try to acquire the rescheduling rights
- Whomever wins reschedules
- When the process resumes after a timeout, it throws an error
Due to rescheduling rights involving atomic operations, the process would only be rescheduled once.
Care must be taken regarding receiving messages. If a process is waiting for IO with a timeout, another process sending it a message must not wake it up.
Drawbacks
This will put more pressure on the timeout worker, and its implementation isn't the best (performance wise) to begin with. In addition, we'll need additional VM logic for the various socket operations that may time out.