From 02e8c8ef65271d6252c6eaf1ba1271de29cf4a9e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 6 Sep 2013 14:53:04 +0200 Subject: [PATCH] include: clarify uv_tcp_bind() behavior On BSD-like platforms, EADDRINUSE is returned by the bind() system call. On other platforms, it's returned by the listen() system call. In other words, some platforms are 'first to bind wins', others are 'first to listen wins' - but only with TCP sockets: UNIX domain sockets always return EADDRINUSE from the bind() system call, UDP sockets don't call listen() in the first place. Fixes #769. --- include/uv.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/uv.h b/include/uv.h index 134759f6..87debe12 100644 --- a/include/uv.h +++ b/include/uv.h @@ -769,6 +769,12 @@ UV_EXTERN int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable); /* * Bind the handle to an address and port. `addr` should point to an * initialized struct sockaddr_in or struct sockaddr_in6. + * + * When the port is already taken, you can expect to see an UV_EADDRINUSE + * error from either uv_tcp_bind(), uv_listen() or uv_tcp_connect(). + * + * That is, a successful call to uv_tcp_bind() does not guarantee that + * the call to uv_listen() or uv_tcp_connect() will succeed as well. */ UV_EXTERN int uv_tcp_bind(uv_tcp_t* handle, const struct sockaddr* addr);