Following up on my other post, my main task reads from a TCP socket and needs to be interrupted on a signal:
void main()
{
bool do_shutdown;
auto t = runTask({
auto conn = connectTCP("localhost", 4711);
auto recvbuf = new ubyte[12345];
while (!do_shutdown) {
conn.read(recvbuf);
logInfo("Still alive...");
}
});
eventDriver.signals.listen(SIGINT, (id, status, sig) {
auto l = yieldLock();
eventDriver.signals.releaseRef(id);
logInfo("Caught SIGINT!");
runTask({
logInfo("Initiating shutdown procedure...");
// Cancel the read() call in the other task
t.join();
logInfo("Shut down!");
exitEventLoop();
});
});
runApplication();
}
How do I cancel the read
call during a shutdown? I found eventcore.socket.cancelRead
, which accepts a ref StreamSocket
argument, and I am not sure how to pass a TCPSocket
.