WSAAsyncSelect equivalent for linux

Hello, I'm writing a multi-threaded socket server in C++ and I needed something like wsaasyncselect to handle messages like fd_accept, fd_read, fd_connect, fd_close.

Thanks in advance.

Linux doesn't have a Windows event loop, of course.

You can use fcntl() to set the O_ASYNC flag on your file descriptors.

Your process will then receive a SIGIO signal when IO is possible on those file descriptors. Which file descriptor will be specified in the siginfo_t structure you get with each SIGIO signal. The siginfo_t structure might also contain other information as well, but offhand I don't recall if there is any additional data.

You need to be real careful in your signal handler, though. Any system call you make from within the signal handler or anything it calls MUST be async-signal safe. For example, no malloc()/free() or new/delete or anything else that might make those calls.