From 9eada60a32b2fe25980571aa198f81c9df52c6f9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 11 Aug 2007 15:57:23 -0700 Subject: [PATCH] Allow the connection socket to be reused in SocketWrapper * Source/SocketWrapper.m: ([SocketWrapper connect:]): Allow the socketOpen to reuse addresses, making the bind errors less common --- Source/SocketWrapper.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/SocketWrapper.m b/Source/SocketWrapper.m index 80dc779..5e80c25 100644 --- a/Source/SocketWrapper.m +++ b/Source/SocketWrapper.m @@ -160,6 +160,10 @@ NSString *NsockDataSent = @"SocketWrapper_DataSent"; address.sin_addr.s_addr = htonl(INADDR_ANY); memset(address.sin_zero, '\0', sizeof(address.sin_zero)); + // allow an already-opened socket to be reused + int yes = 1; + setsockopt(socketOpen, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); + // bind the socket... and don't give up until we've tried for a while int tries = 0; while (bind(socketOpen, (struct sockaddr *)&address, sizeof(address)) < 0) -- 2.22.5