[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[coldsync-hackers] Net connection and successive resync



I have had a problem while installing software on my new Palm: I used
coldsync in network mode, many times in a row. I got a "bind: port
already in use" error (while it wasn't) several times. This extra
safety measure provided by the Unix kernels can easily be circumvented
(and is almost always in most daemons) by using setsockopt().

Coldsync works much better for me with the following patch.

  Sam
-- 
Samuel Tardieu -- sam@rfc1149.net -- http://www.rfc1149.net/sam

Index: upstream.2_2_3_20011030.1/i18n/messages.po
--- upstream.2_2_3_20011030.1/i18n/messages.po Mon, 12 Nov 2001 09:16:21 +0100 sam (coldsync/1_messages.p 1.1 644)
+++ Sam.1/i18n/messages.po Mon, 12 Nov 2001 13:00:39 +0100 sam (coldsync/1_messages.p 1.2 644)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 2001-10-30 10:49-0500\n"
+"POT-Creation-Date: 2001-11-12 12:57+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
Index: upstream.2_2_3_20011030.1/i18n/fr.po
--- upstream.2_2_3_20011030.1/i18n/fr.po Mon, 12 Nov 2001 09:16:21 +0100 sam (coldsync/2_fr.po 1.1 644)
+++ Sam.1/i18n/fr.po Mon, 12 Nov 2001 13:00:39 +0100 sam (coldsync/2_fr.po 1.2 644)
@@ -5,7 +5,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: coldsync 1.1.2\n"
-"POT-Creation-Date: 2001-10-30 10:49-0500\n"
+"POT-Creation-Date: 2001-11-12 12:57+0100\n"
 "PO-Revision-Date: 2000-02-05 17:48-0500\n"
 "Last-Translator: Nicolas Bouthors <nicolas@bouthors.org>\n"
 "Language-Team: fr <fr@li.org>\n"
Index: upstream.2_2_3_20011030.1/i18n/de.po
--- upstream.2_2_3_20011030.1/i18n/de.po Mon, 12 Nov 2001 09:16:21 +0100 sam (coldsync/3_de.po 1.1 644)
+++ Sam.1/i18n/de.po Mon, 12 Nov 2001 13:00:39 +0100 sam (coldsync/3_de.po 1.2 644)
@@ -5,7 +5,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: ColdSync 1.1.4\n"
-"POT-Creation-Date: 2001-10-30 10:49-0500\n"
+"POT-Creation-Date: 2001-11-12 12:57+0100\n"
 "PO-Revision-Date: 2000-03-27 16:57+02:00\n"
 "Last-Translator: Philipp Matthias Hahn <pmhahn@titan.lahn.de>\n"
 "Language-Team:  de <de@li.org>\n"
Index: upstream.2_2_3_20011030.1/i18n/it.po
--- upstream.2_2_3_20011030.1/i18n/it.po Mon, 12 Nov 2001 09:16:21 +0100 sam (coldsync/4_it.po 1.1 644)
+++ Sam.1/i18n/it.po Mon, 12 Nov 2001 13:00:39 +0100 sam (coldsync/4_it.po 1.2 644)
@@ -5,7 +5,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: coldsync 2.1.2\n"
-"POT-Creation-Date: 2001-10-30 10:49-0500\n"
+"POT-Creation-Date: 2001-11-12 12:57+0100\n"
 "PO-Revision-Date: 2001-06-19 04:03:+0100\n"
 "Last-Translator: Alessandro Gatti <rigel@telemail.it>\n"
 "Language-Team: it <it@li.org>\n"
Index: upstream.2_2_3_20011030.1/libpconn/PConnection_net.c
--- upstream.2_2_3_20011030.1/libpconn/PConnection_net.c Mon, 12 Nov 2001 09:16:21 +0100 sam (coldsync/c/11_PConnectio 1.1 644)
+++ Sam.1/libpconn/PConnection_net.c Mon, 12 Nov 2001 13:00:39 +0100 sam (coldsync/c/11_PConnectio 1.2 644)
@@ -5,7 +5,7 @@
 #include "config.h"
 #include <stdio.h>
 #include <sys/types.h>
-#include <sys/socket.h>		/* For socket() */
+#include <sys/socket.h>		/* For socket() and setsockopt() */
 #include <netinet/in.h>		/* For sockaddr_in, htonl() etc. */
 #include <arpa/inet.h>		/* For inet_pton() */
 #include <netdb.h>		/* For getservbyname() */
@@ -738,6 +738,17 @@
 	else
 		servaddr.sin_port = service->s_port;
 				/* Port is already in network byte order */
+
+	/* Set the SO_REUSEADDR flag on the listening socket, to prevent
+	 * successive attempts with only a short delay from failing (most
+	 * Unices need a minimum time between having two successive
+	 * sockets bound to the same port). The result needs not to be
+	 * checked.
+	 */
+	{
+	  int one = 1;
+	  setsockopt(pconn->fd, SOL_SOCKET, SO_REUSEADDR ,&one, sizeof(int));
+	}
 
 	IO_TRACE(5)
 		fprintf(stderr, "binding\n");