I'm currently working on an actix-web application but I have some difficulty in understanding how HttpServer.listen()
and HttpServer.bind()
are different and what do these functions do.
HttpServer::bind
takes a (bunch of) socket address(es), resolves them, opens the corresponding connections, then listens.
HttpServer::listen
just listens.
rustdoc has a source
link next to most functions, so you can actually browse the code to bind
and it's pretty straightforward:
pub fn bind<A: net::ToSocketAddrs>(mut self, addrs: A) -> io::Result<Self> {
let sockets = self.bind2(addrs)?;
for lst in sockets {
self = self.listen(lst)?;
}
Ok(self)
}