socket_server_accept/4 cannot be interrupted with Ctrl-c
Currently, I get:
?- use_module(library(sockets)). true. ?- socket_server_open(7014, Socket), socket_server_accept(Socket, Client, Stream, [type(binary)]). ^C^C^C^C^Z
Ideally, socket_server_accept/4 can also be interrupted, much like read/1.
This might require a transition to mio or some other asynchronous I/O crate.
This might require a transition to
mioor some other asynchronous I/O crate.
I think Tokio would be more appropriate, mio is really the low-level library on top of which Tokio is built. This is an issue I can take a look at I think!
@matt2xu : Thank you a lot, I would greatly appreciate this!
what would be the relevant areas to modify to accomodate this? I can find some http server definitions here, for example.
@matt2xu, @razetime: The most important section for this is in system_calls.rs, specifically in:
https://github.com/mthom/scryer-prolog/blob/de10ccfdeea33abb5d64d5a4bc33ee39b14ab002/src/machine/system_calls.rs#L6136
For comparison, the HTTP server already uses tokio:
https://github.com/mthom/scryer-prolog/blob/de10ccfdeea33abb5d64d5a4bc33ee39b14ab002/src/machine/system_calls.rs#L4323
Can the ideas from #1998 be used to make this also work for socket_server_accept/4? (@aarroyoc ?)
Technically the same idea could be used. On tcp_listener.accept() do something like a timeout to check if while waiting for a connection, a Ctrl-C has happened. But the TcpListener API doesn't provide an easy way to check for timeouts. They do have a non_blocking mode which will just return an error if there's nothing there, but putting that on a loop isn't good for the CPU. Tokio's TcpListener doesn't provide an accept_timeout method either but since it returns a future I think it can be combined with tokio timeouts to achieve the goal.