I'm trying to make a chat server thing. Basically, I want more than one client to be able to connect at the same time.
I want it so it's always listening. Whenever anyone tries to connect, it instantly accepts them and adds them to a list of connections.
I could have a listen(1) then a timeout, and keep appending them to a list then closing the socket, and making a new one, then listening with a timeout, etc. Although, this seems very slow, and I'm not even sure it would work
Keep in mind, it does not HAVE to be socket. If there is any other kind of network interface, it would work just as well.
I want it so it's always listening. Whenever anyone tries to connect, it instantly accepts them and adds them to a list of connections.

So you just have:

An accept() loop that does nothing but accept() new connections and start a new thread to handle each one.
A thread per connection that reads with a long timeout, whatever you want your session idle timeout to be. If the timeout expires, you close the socket and exit the thread.

If the server runs out of FDs, which it will if there are enough simultaneous connections, accept() will start failing with a corresponding errno: in this case you just ignore it and keep looping. Maybe you decrease the idle timeout in this situation, and put it back when accepts start to work again.
Having an infinite amount of sockets connected?