svn commit: trunk/busybox/include

vda at vda at
Thu Aug 16 18:27:47 UTC 2007

Author: vda
Date: 2007-08-16 11:27:47 -0700 (Thu, 16 Aug 2007)
New Revision: 19533

add comments regarding SO_REUSEADDR


Modified: trunk/busybox/include/libbb.h
--- trunk/busybox/include/libbb.h	2007-08-16 18:19:42 UTC (rev 19532)
+++ trunk/busybox/include/libbb.h	2007-08-16 18:27:47 UTC (rev 19533)
@@ -282,6 +282,13 @@
 void xconnect(int s, const struct sockaddr *s_addr, socklen_t addrlen);
 ssize_t xsendto(int s, const void *buf, size_t len, const struct sockaddr *to,
 				socklen_t tolen);
+/* SO_REUSEADDR allows a server to rebind to an address that is already
+ * "in use" by old connections to e.g. previous server instance which is
+ * killed or crashed. Without it bind will fail until all such connections
+ * time out. Linux does not allow multiple live binds on same ip:port
+ * regardless of SO_REUSEADDR (unlike some other flavors of Unix).
+ * Turn it on before you call bind(). */
+//TODO: it seems like in Linux this never fails. Change to void, eliminate error checks
 int setsockopt_reuseaddr(int fd);
 int setsockopt_broadcast(int fd);
 /* NB: returns port in host byte order */
@@ -318,6 +325,7 @@
  * numeric IP ("N.N.N.N") or numeric IPv6 address,
  * and can have ":PORT" suffix (for IPv6 use "[X:X:...:X]:PORT").
  * Only if there is no suffix, port argument is used */
+/* NB: these set SO_REUSEADDR before bind */
 int create_and_bind_stream_or_die(const char *bindaddr, int port);
 int create_and_bind_dgram_or_die(const char *bindaddr, int port);
 /* Create client TCP socket connected to peer:port. Peer cannot be NULL.
@@ -345,7 +353,7 @@
 #define host_and_af2sockaddr(host, port, af) ((void)(af), host2sockaddr((host), (port)))
 #define xhost_and_af2sockaddr(host, port, af) ((void)(af), xhost2sockaddr((host), (port)))
-/* Assign sin[6]_port member if the socket is of corresponding type,
+/* Assign sin[6]_port member if the socket is an AF_INET[6] one,
  * otherwise no-op. Useful for ftp.
  * NB: does NOT do htons() internally, just direct assignment. */
 void set_nport(len_and_sockaddr *lsa, unsigned port);

More information about the busybox-cvs mailing list