Take the 2-minute tour ×

To clarify, I am wondering what are the cons and pros of writing a "multiple simultaneous clients to a single server" using TCP/IP sockets and signal handlers that are called in response to "can read / can write" signal conditions on client socket file descriptors? As far as I understand at least the Linux kernel uses signals to notify a process of conditions related to socket descriptors? Obviously one has to be careful in a signal handler, which, again as I understand, interrupts the process - reentrancy, atomicity, undefined state for variables, etc.

But one does not have to have signals do most work, in fact quite the opposite - add the socket to a set of sockets ready for reading, writing, much like select, poll and epoll_wait do, and let the default process code flow work with these sets? In effect, one emulates much the same pattern as with the functions mentioned, but purely principally, is it doable and how can it be worth it?

share|improve this question
add comment

1 Answer

There is already a couple of such methods. One is using the SIGIO signal, check man 7 socket and look for the section named "Signals" for more information.

The other method is standardized by POSIX and called async I/O. The functions to use are all prefixed with aio_ (for example aio_read). See this link for an example on how to use this or check the manual page.

share|improve this answer
Thank you. A question though: why would POSIX standardize something that is already provided by the standard with socket and signal APIs? Surely writing code using both is still standard? Why build another standard that is the AIO on top of them? –  amn Nov 8 '11 at 14:34
@amn The POSIX aio functions are much more flexible than the simple SIGIO scheme, but the downside is that it's much more complicated to do something simple. The performance should be pretty good though. –  Joachim Pileborg Nov 8 '11 at 14:37
But, if the AIO is much more flexible than its supposed underlying API(s) that are POSIX signals and POSIX sockets, surely this means that it relies on something else as well to work? I like to use as little dependencies as possible, that is why I thought about whether it is a good idea to write a flexible socket I/O client-server model using nothing else but sockets and signals. –  amn Nov 8 '11 at 19:59
@amn aio relies on kernel support, and is implemented in the rt library (link with -lrt) which is a part of the standard library in Linux. My suggestion is that you make a small client and server applications using the different methods available, and benchmark them for performance, and use whatever you like the best. –  Joachim Pileborg Nov 9 '11 at 3:26
add comment

Your Answer


