From 88a8ad8c7d83cf009b9ca6756e5b4fb5c333435e Mon Sep 17 00:00:00 2001 From: pixel Date: Mon, 22 Sep 2008 20:55:02 +0000 Subject: Getting rid of the nasty 'TIME_WAIT' issue when server crashes and restarts. --- lib/Socket.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/Socket.cc b/lib/Socket.cc index f66fc5f..21acf3f 100644 --- a/lib/Socket.cc +++ b/lib/Socket.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Socket.cc,v 1.26 2008-07-23 16:08:10 pixel Exp $ */ +/* $Id: Socket.cc,v 1.27 2008-09-22 20:55:02 pixel Exp $ */ #ifdef _WIN32 #include @@ -121,7 +121,6 @@ bool Socket::SetLocal(const String & vhost, int port) { struct in_addr localhostaddr; struct sockaddr_in localsocketaddr; - memset((void *)&localhostaddr, 0, sizeof(localhostaddr)); if (vhost.strlen() != 0) { @@ -139,6 +138,11 @@ bool Socket::SetLocal(const String & vhost, int port) { localsocketaddr.sin_addr = localhostaddr; localsocketaddr.sin_port = htons(port); +#ifndef _WIN32 + int enable = 1; + setsockopt(GetHandle(), SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)); +#endif + if (bind(GetHandle(), (struct sockaddr *) &localsocketaddr, sizeof(localsocketaddr)) < 0) { return false; } else { -- cgit v1.2.3