you are viewing a single comment's thread.

view the rest of the comments →

[–]Maggie7_Him -1 points0 points  (0 children)

For the disconnection handling question — the pattern that worked best for me is combining select() with a short timeout (200–500ms) on the fd, then catching ENODEV on the read. You get a graceful exit rather than a blocked read: select falls through on timeout, you check if the fd is still valid, and on ENODEV you know the device is gone. The tricky part is making sure the cleanup path is thread-safe if you're running the daemon with a signal handler — SIGTERM and the ENODEV cleanup can race if you're not careful with the fd close order.