There is something I don’t understand. socket recv() is blocking by default. If blocked in recv() there is no safe way to exit the thread. One can set a timeout, but I can’t imagine this works well with lots of threads with a recv() on each thread. One can use select() which has mostly the same problems, either block potentially forever or use a timeout. Although one can create an additional 2 sockets, connect them together and put one of them in the select read set to allow controlled unblocking, but this doesn’t feel like a great solution, so I have always used async for socket code, because I just don’t know how it’s possible to use sync code.
I have read you can call close(fd) and get recv(fd) to return, but I also hear this is not safe.