Sockets: how much broken they are?

Hi.

I’m working on a HomeKit implementation, and it requires a stateful TCP server which can handle multiple long-term connections. To minimize efforts, I want to use a single select() call for both server and all client sockets (as I usually do on a big PC).

But I see it doesn’t work as expected:

  1. Server socket should get into read_fds set when there’s a pending connection, but it actually doesn’t. Is the non-blocking accept the only way to accept a new connection?

  2. When there’s some data available for reading from the socket, it is correctly triggered in read_fds set. But when the socket becomes disconnected, it gets neither into read_fds nor into error_fds set. This is really a problem for a stateful server, because there’s no way to deallocate state data, so the server goes out of memory.

Is there an effective way to handle multiple sockets without trying to recv() from each one, and checking get_socket_active_status() afterwards?