What are Async Sockets?
There are three ways to communicate with sockets in async way:
Open regular socket, but do not read from it (because
read()
blocks) until you know there it something to be read. You can useselect()
orpoll()
to check whether there are data to read from socket(s), and if there is something, read it, asread()
won't block.Switch socket to non-blocking I/O, by setting
O_NONBLOCK
flag withfcntl()
function. In this caseread()
won't block.Set socket's
O_ASYNC
flag usingFIOASYNC
option ofioctl()
(see man 7 socket for details). In this case you will receiveSIGIO
signal when there is something to read from socket.
Third approach is async socket.
Comparison of the following five different models for I/O in UNIX Network Programming: The sockets networking API would be helpful:
Blocking
Nonblocking
I/O multiplexing
Signal-driven I/O
Asynchronous I/O