Does anyone have a good pattern for terminating tokio’s
TcpListener::incoming()) stream early? Let me describe a usecase to elaborate.
Server starts up and establishes a TCP listener. The server expects a certain number of client connections - it’s not an infinite stream of them. After accepting a connection, it handshakes with the client - this involves getting some identification information (to make it simple, say the client sends a json message with a string identifier). The server removes this client from the set of clients it’s expecting. If this is the last client it was expecting, the Incoming should be dropped and the server should end up closing the accept socket. It wants to be left with a list of connected clients, which is basically their TcpStream, so it can communicate with them afterwards.
What’s a good way to achieve this? I’ve not found anything in tokio (thus far) that would make this straightforward but maybe I missed something.