As a network client I would like to follow the input from two TCP connections. Both servers send a few packets per second. Each packet is small in size when compared to the available bandwidth.
Ideally we'd like to read both sockets from a single thread for the best latency. My initial plan was to use FIONREAD
from ioctl(2) on each connection in a loop, and only read when data is available. Are there other options? CPU consumption is less relevant than low latency.
You want to use one of these I/O multiplexing primitives:
ioctl(2)
. Usually, it's combined with one of the options below to avoid a busy loop.select()
; "On Linux [...] it may be safer to use O_NONBLOCK on sockets that should not block"poll()
epoll()
(Linux)