Separate the action of starting a TCP listener from the action of waiting to accept the first incoming connection. #8689
Labels
E-easy
Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Currently we do not start listening on a TCP socket until we call .accept() for the first time (at which point we block until there is an incoming connection). This makes it difficult to test TCP code in a multithreaded environment since we cannot guarantee that the server is up and running before attempting to connect without having the client spin on connection attempts.
I would like to move to this alternative interface:
TcpListener.listen() consumes the TcpListener and returns a TcpAcceptor.
TcpAcceptor.accept() replicates the current behavior of TcpListener.accept() (blocks and returns a Result).
TcpAcceptor will implement Iterator and produce an infinite stream of incoming connections.
The socket will be closed when the TcpAcceptor goes out of scope.
The libuv listener takes the backlog size as a parameter. Currently, we hardcode this to 128, but we could make it a argument of TcpListener.listen() and provide a default.
The text was updated successfully, but these errors were encountered: