Index: trunk/FACT++/dim/README_v19.txt
===================================================================
--- trunk/FACT++/dim/README_v19.txt	(revision 12757)
+++ trunk/FACT++/dim/README_v19.txt	(revision 13135)
@@ -1,4 +1,4 @@
 
-                    DIM version 19.27 Release Notes
+                    DIM version 19.30 Release Notes
 
 Notes 1 and 2 for Unix Users only
@@ -17,5 +17,28 @@
 		Dns </dev/null >& dns.log &
 
-NOTE 3: The Version Number service provided by servers is now set to 1927.
+NOTE 3: The Version Number service provided by servers is now set to 1930.
+
+14/03/2012
+Changes for version 19.30:
+    - Sometimes when trying to open a connection to a server the client could backoff for too
+      long (10 seconds), now it will retry immediately and then at increasing intervals.
+    - dim_stop() would sometimes not properly stop all threads if a new connection was received
+      in the mean time.
+    - The DimServerDns destructor could crash, fixed.
+    - Removed some compiler warnings about variables set but not used.
+    - Two new functions available:
+	- dim_set_listen_backlog(int size)
+	- int dim_get_listen_backlog()
+    - The DNS will set the listen_backlog to 1024 at startup, but the OS will truncate it to
+      a maximum limit (available in /proc/sys/net/core/somaxconn, linux default=128), 
+      while for servers the constant SOMAXCONN is used.
+
+
+06/02/2012
+Changes for version 19.28:
+    - Added more log messages when a "Write Timeout" occurs to know where it originated.
+    - A server could sometimes not release the connection in case of a "Write Timeout", and
+      then keep on timing out for each message on this connection - fixed.
+
 
 19/01/2012
Index: trunk/FACT++/dim/dim/dim.h
===================================================================
--- trunk/FACT++/dim/dim/dim.h	(revision 12757)
+++ trunk/FACT++/dim/dim/dim.h	(revision 13135)
@@ -14,5 +14,5 @@
 #include "dim_common.h"
 
-#define DIM_VERSION_NUMBER 1927
+#define DIM_VERSION_NUMBER 1930
 
 #define MY_LITTLE_ENDIAN	0x1
Index: trunk/FACT++/dim/dim/dim_common.h
===================================================================
--- trunk/FACT++/dim/dim/dim_common.h	(revision 12757)
+++ trunk/FACT++/dim/dim/dim_common.h	(revision 13135)
@@ -204,4 +204,6 @@
 _DIM_PROTOE( void dim_set_keepalive_timeout,		(int secs) );
 _DIM_PROTOE( int dim_get_keepalive_timeout,		() );
+_DIM_PROTOE( void dim_set_listen_backlog,		(int size) );
+_DIM_PROTOE( int dim_get_listen_backlog,		() );
 
 #ifdef WIN32
Index: trunk/FACT++/dim/src/dic.c
===================================================================
--- trunk/FACT++/dim/src/dic.c	(revision 12757)
+++ trunk/FACT++/dim/src/dic.c	(revision 13135)
@@ -29,5 +29,5 @@
 #endif
 
-#define BAD_CONN_TIMEOUT 10
+#define BAD_CONN_TIMEOUT 2
 
 
@@ -1314,5 +1314,5 @@
 	char *node_name, *task_name;
 	char node_info[MAX_NODE_NAME+4];
-	int i, port, protocol, format, ret, pid;
+	int i, port, protocol, format, pid;
 	register DIC_CONNECTION *dic_connp ;
 	DIC_DNS_PACKET dic_dns_packet;
@@ -1489,5 +1489,5 @@
 			strncpy( bad_connp->conn.task_name, task_name, MAX_TASK_NAME);
 			bad_connp->conn.port = port;
-			tmout = BAD_CONN_TIMEOUT * bad_connp->n_retries;
+			tmout = BAD_CONN_TIMEOUT * (bad_connp->n_retries - 1);
 			if(tmout > 120)
 				tmout = 120;
@@ -1530,5 +1530,5 @@
 	servp->conn_id = conn_id;
 
-	ret = send_service_command( servp );
+	send_service_command( servp );
 /*
 	if( ret == 1)
@@ -1942,4 +1942,11 @@
 	}
 */
+	if(!ret)
+	{
+		dim_print_date_time();
+		printf(" Client Sending Command: Couldn't write to Conn %3d : Server %s@%s\n",conn_id,
+			Net_conns[conn_id].task, Net_conns[conn_id].node);
+		fflush(stdout);
+	}
 	return(ret);
 }
@@ -2244,7 +2251,32 @@
 void dic_stop()
 {
+	int dic_find_server_conns();
+
 	dtq_delete(Dic_timer_q);
 	dic_close_dns();
-	dim_stop();
+	if(!dic_find_server_conns())
+		dim_stop();
+}
+
+int dic_find_server_conns()
+{
+	int i;
+	int n = 0;
+
+	for( i = 0; i< Curr_N_Conns; i++ )
+	{
+		if(Net_conns[i].channel != 0)
+		{
+			if(Dna_conns[i].read_ast == recv_rout)
+			{
+				dna_close(i);
+			}
+			else
+			{
+				n++;
+			}
+		}
+	}
+	return(n);
 }
 
Index: trunk/FACT++/dim/src/dim_thr.c
===================================================================
--- trunk/FACT++/dim/src/dim_thr.c	(revision 12757)
+++ trunk/FACT++/dim/src/dim_thr.c	(revision 13135)
@@ -182,7 +182,8 @@
 void dim_stop()
 {
+	void dim_tcpip_stop(), dim_dtq_stop();
+/*
 	int i;
 	int n = 0;
-	void dim_tcpip_stop(), dim_dtq_stop();
 
 	for( i = 0; i< Curr_N_Conns; i++ )
@@ -193,4 +194,5 @@
 	if(n)
 		return;
+*/
 	if(IO_thread)
 		pthread_cancel(IO_thread);
@@ -666,4 +668,5 @@
 void dim_stop_threads()
 {
+/*
 	int i;
 	int n = 0;
@@ -676,4 +679,5 @@
 	if(n)
 		return;
+*/
 	if(hIO_thread)
 		TerminateThread(hIO_thread, 0);
Index: trunk/FACT++/dim/src/dis.c
===================================================================
--- trunk/FACT++/dim/src/dis.c	(revision 12757)
+++ trunk/FACT++/dim/src/dis.c	(revision 13135)
@@ -1388,6 +1388,5 @@
 	register SERVICE *servp;
 	char str[80], def[MAX_NAME];
-	register char *ptr;
-	int last_conn_id;
+	int conn_id, last_conn_id;
 	int *pkt_buffer, header_size, aux;
 #ifdef WIN32
@@ -1406,7 +1405,17 @@
 	reqp->delay_delete++;
 	servp = reqp->service_ptr;
+	conn_id = reqp->conn_id;
+
+if(Debug_on)
+{
+dim_print_date_time();
+printf("Updating %s for %s@%s (req_id = %d)\n",
+	   servp->name, 
+	   Net_conns[conn_id].task, Net_conns[conn_id].node, 
+	   reqp->req_id);
+}
+
 	last_conn_id = Curr_conn_id;
-	Curr_conn_id = reqp->conn_id;
-	ptr = servp->def;
+	Curr_conn_id = conn_id;
 	if(servp->type == COMMAND)
 	{
@@ -1415,5 +1424,4 @@
 		size = 26;
 		sprintf(def,"c:26");
-		ptr = def;
 	}
 	else if( servp->user_routine != 0 ) 
@@ -1491,6 +1499,23 @@
 		buffp, size);
 	Dis_packet->size = htovl(header_size + size);
-	if( !dna_write_nowait(reqp->conn_id, Dis_packet, header_size + size) ) 
-	{
+	if( !dna_write_nowait(conn_id, Dis_packet, header_size + size) ) 
+	{
+		if(Net_conns[conn_id].write_timedout)
+		{
+			dim_print_date_time();
+			if(reqp->delay_delete > 1)
+			{
+				printf(" Server (Explicitly) Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n",
+					servp->name, conn_id,
+					Net_conns[conn_id].task, Net_conns[conn_id].node);
+			}
+			else
+			{
+				printf(" Server Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n",
+					servp->name, conn_id,
+					Net_conns[conn_id].task, Net_conns[conn_id].node);
+			}
+		}
+		fflush(stdout);
 		if(reqp->delay_delete > 1)
 		{
@@ -1500,5 +1525,5 @@
 		{
 			reqp->delay_delete = 0;
-			release_conn(reqp->conn_id, 1, 0);
+			release_conn(conn_id, 1, 0);
 		}
 	}
@@ -1513,5 +1538,6 @@
 	}
 */
-	reqp->delay_delete--;
+	if(reqp->delay_delete > 0)
+		reqp->delay_delete--;
 	return(1);
 }
@@ -1520,5 +1546,4 @@
 {
 	register REQUEST *reqp;
-	register SERVICE *servp;
 	static DIS_PACKET *dis_packet;
 	static int packet_size = 0;
@@ -1528,5 +1553,4 @@
 	if(!reqp)
 		return;
-	servp = reqp->service_ptr;
 	if( !packet_size ) {
 		dis_packet = (DIS_PACKET *)malloc(DIS_HEADER);
@@ -1708,4 +1732,5 @@
 		(DLL *) reqp)) ) 
 	{
+/*
 if(Debug_on)
 {
@@ -1715,4 +1740,5 @@
 	   Net_conns[reqp->conn_id].task, Net_conns[reqp->conn_id].node, reqp->req_id, (unsigned long)reqp);
 }
+*/
 		if(check_client(reqp, client_ids))
 		{
@@ -2051,4 +2077,8 @@
 		if( !dna_write_nowait(conn_id, dis_packet, size + DIS_HEADER) )
 		{
+			dim_print_date_time();
+			printf(" Server Sending Service: Couldn't write to Conn %3d : Client %s@%s\n",conn_id,
+				Net_conns[conn_id].task, Net_conns[conn_id].node);
+			fflush(stdout);
 			release_conn(conn_id, 1, 0);
 		}
@@ -2142,9 +2172,14 @@
 	n_services = dnsp->dis_n_services;
 
-	ENABLE_AST
 	if(dnsp->serving)
 	{
 		if(n_services == 5)
 		{
+			if(Dis_conn_id)
+			{
+				dna_close(Dis_conn_id);
+				Dis_conn_id = 0;
+			}
+			ENABLE_AST
 /*
 			dis_stop_serving();
@@ -2152,4 +2187,12 @@
 			do_dis_stop_serving_dns(dnsp);
 		}
+		else
+		{
+			ENABLE_AST
+		}
+	}
+	else
+	{
+		ENABLE_AST
 	}
 	return(found);
@@ -2281,4 +2324,5 @@
 register SERVICE *servp, *prevp;
 void dim_stop_threads(void);
+int dis_find_client_conns();
 int hash_index;
 
@@ -2335,5 +2379,28 @@
 	if(Serving != -1)
 */
-	dim_stop_threads();
+	if(!dis_find_client_conns())
+		dim_stop_threads();
+}
+
+int dis_find_client_conns()
+{
+	int i;
+	int n = 0;
+
+	for( i = 0; i< Curr_N_Conns; i++ )
+	{
+		if(Net_conns[i].channel != 0)
+		{
+			if(Dna_conns[i].read_ast == dis_insert_request)
+			{
+				dna_close(i);
+			}
+			else
+			{
+				n++;
+			}
+		}
+	}
+	return(n);
 }
 
Index: trunk/FACT++/dim/src/discpp.cxx
===================================================================
--- trunk/FACT++/dim/src/discpp.cxx	(revision 12757)
+++ trunk/FACT++/dim/src/discpp.cxx	(revision 13135)
@@ -312,9 +312,9 @@
 void DimServerDns::init(const char *node, int port)
 {
-	if(!itsNode)
-	{
+//	if(!itsNode)
+//	{
 		itsNode = new char[strlen(node)+1];
 		strcpy(itsNode,node);
-	}
+//	}
 	itsPort = port;
 	autoStart = 1;
@@ -365,5 +365,5 @@
 //			delete[] itsName;
 	}
-	if(itsNode)
+//	if(itsNode)
 		delete[] itsNode;
 }
Index: trunk/FACT++/dim/src/dna.c
===================================================================
--- trunk/FACT++/dim/src/dna.c	(revision 12757)
+++ trunk/FACT++/dim/src/dna.c	(revision 13135)
@@ -821,4 +821,8 @@
 	if (tcpip_failure(tcpip_code))
 	{
+		dim_print_date_time();
+		printf(" Client Establishing Connection: Couldn't write to Conn %3d : Server %s@%s\n",conn_id,
+			Net_conns[conn_id].task, Net_conns[conn_id].node);
+		fflush(stdout);
 		dna_close(conn_id);
 		return(0);
@@ -934,3 +938,2 @@
 	}
 }
-
Index: trunk/FACT++/dim/src/dns.c
===================================================================
--- trunk/FACT++/dim/src/dns.c	(revision 12757)
+++ trunk/FACT++/dim/src/dns.c	(revision 13135)
@@ -1438,4 +1438,5 @@
 	}
 	dim_set_write_timeout(10);
+	dim_set_listen_backlog(1024);
 	dim_init();
 	conn_arr_create( SRC_DNS );
Index: trunk/FACT++/dim/src/dtq.c
===================================================================
--- trunk/FACT++/dim/src/dtq.c	(revision 12757)
+++ trunk/FACT++/dim/src/dtq.c	(revision 13135)
@@ -85,7 +85,9 @@
 struct sigaction sig_info;
 sigset_t set;
-int pid, ret = 0;
-
+int ret = 0;
+
+/*
 	pid = getpid();
+*/
 	if( !sigvec_done) 
 	{
@@ -796,10 +798,9 @@
 int dtq_stop_timer(long tag)
 {
-	TIMR_ENT *entry, *queue_head, *prevp;
+	TIMR_ENT *entry, *queue_head;
 	int time_left = -1;
 
 	queue_head = timer_queues[SPECIAL_QUEUE].queue_head;
 	entry = queue_head;
-	prevp = entry;
 	while( (entry = (TIMR_ENT *)dll_get_next((DLL *)queue_head,(DLL *)entry)) )
 	{
Index: trunk/FACT++/dim/src/examples/test_server.c
===================================================================
--- trunk/FACT++/dim/src/examples/test_server.c	(revision 12757)
+++ trunk/FACT++/dim/src/examples/test_server.c	(revision 13135)
@@ -74,4 +74,7 @@
 	int new_dns = 0;
 	int index = 0;
+/*
+	dim_set_write_timeout(1);
+*/
 /*
 	int buf_sz, buf_sz1;
Index: trunk/FACT++/dim/src/tcpip.c
===================================================================
--- trunk/FACT++/dim/src/tcpip.c	(revision 12757)
+++ trunk/FACT++/dim/src/tcpip.c	(revision 13135)
@@ -89,4 +89,5 @@
 static int DIM_IO_valid = 1;
 
+static int Listen_backlog = SOMAXCONN;
 static int Keepalive_timeout_set = 0;
 static int Write_timeout = WRITE_TMOUT;
@@ -97,4 +98,14 @@
 int Tcpip_max_io_data_write = TCP_SND_BUF_SIZE - 16;
 int Tcpip_max_io_data_read = TCP_RCV_BUF_SIZE - 16;
+
+void dim_set_listen_backlog(int size)
+{
+	Listen_backlog = size;
+}
+
+int dim_get_listen_backlog()
+{
+	return(Listen_backlog);
+}
 
 void dim_set_keepalive_timeout(int secs)
@@ -1138,5 +1149,5 @@
 	}
 
-	if( (ret = listen(path, SOMAXCONN)) == -1 )
+	if( (ret = listen(path, Listen_backlog)) == -1 )
 	{
 		closesock(path);
