Index: trunk/FACT++/dim/README_v19.txt
===================================================================
--- trunk/FACT++/dim/README_v19.txt	(revision 11071)
+++ trunk/FACT++/dim/README_v19.txt	(revision 11121)
@@ -1,4 +1,4 @@
 
-                    DIM version 19.21 Release Notes
+                    DIM version 19.22 Release Notes
 
 Notes 1 and 2 for Unix Users only
@@ -17,5 +17,15 @@
 		Dns </dev/null >& dns.log &
 
-NOTE 3: The Version Number service provided by servers is now set to 1921.
+NOTE 3: The Version Number service provided by servers is now set to 1922.
+
+21/06/2011
+Changes for version 19.22:
+    - DIM servers would hang when tring to exit due to "Services already declared", if the user
+      exitHandler() didn't directly call exit (instead tried to exit later in the main program).
+      Fixed.
+    - Servers accept now also 'B' or 'V' as format, they are both equivalent to 'C'.
+    - In Linux when a server printed "Write timeout, disconecting from XXX", it didn't always
+      disconnect properly, so the client would not always reconnect afterwards. Fixed. 
+
 
 31/05/2011
Index: trunk/FACT++/dim/dim/dim.h
===================================================================
--- trunk/FACT++/dim/dim/dim.h	(revision 11071)
+++ trunk/FACT++/dim/dim/dim.h	(revision 11121)
@@ -14,5 +14,5 @@
 #include "dim_common.h"
 
-#define DIM_VERSION_NUMBER 1921
+#define DIM_VERSION_NUMBER 1922
 
 #define MY_LITTLE_ENDIAN	0x1
@@ -399,6 +399,8 @@
 	char *buffer;
 	int size;
+/*
 	unsigned short *iosb_r;
 	unsigned short *iosb_w;
+*/
 	char node[MAX_NODE_NAME];
 	char task[MAX_TASK_NAME];
@@ -406,4 +408,5 @@
 	int reading;
 	int timeout;
+	int write_timedout;
 	TIMR_ENT *timr_ent;
 	time_t last_used;
Index: trunk/FACT++/dim/src/dic.c
===================================================================
--- trunk/FACT++/dim/src/dic.c	(revision 11071)
+++ trunk/FACT++/dim/src/dic.c	(revision 11121)
@@ -517,4 +517,8 @@
 	register DIC_SERVICE *servp;
 	
+/*
+dim_print_date_time();
+printf("In service tmout\n");
+*/
 	servp=(DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
 	if(!servp)
@@ -522,4 +526,8 @@
 	if(servp->tmout_done)
 		return;
+/*
+dim_print_date_time();
+printf("In service tmout %s\n", servp->serv_name);
+*/
 	servp->tmout_done = 1;
 	Curr_conn_id = servp->conn_id;
@@ -1689,4 +1697,8 @@
 				case 'c':
 				case 'C':
+				case 'b':
+				case 'B':
+				case 'v':
+				case 'V':
 					formatp->par_bytes = SIZEOF_CHAR;
 					formatp->flags |= NOSWAP;
Index: trunk/FACT++/dim/src/dis.c
===================================================================
--- trunk/FACT++/dim/src/dis.c	(revision 11071)
+++ trunk/FACT++/dim/src/dis.c	(revision 11121)
@@ -242,4 +242,9 @@
 	{
 	DISABLE_AST
+	if(Serving == -1)
+	{
+		ENABLE_AST
+		return((unsigned) 0);
+	}
 	if(!check_service_name(name))
 	{
@@ -415,4 +420,9 @@
 	{
 	DISABLE_AST
+	if(Serving == -1)
+	{
+		ENABLE_AST
+		return((unsigned) 0);
+	}
 	if(!check_service_name(name))
 	{
@@ -582,4 +592,8 @@
 				case 'c':
 				case 'C':
+				case 'b':
+				case 'B':
+				case 'v':
+				case 'V':
 					format_data->par_bytes = SIZEOF_CHAR;
 					format_data->flags |= NOSWAP;
@@ -649,4 +663,6 @@
 		if(dnsp->dns_dis_conn_id > 0)
 			dna_close(dnsp->dns_dis_conn_id);
+		if(Serving == -1)
+			return;
 		if(dnsp->serving)
 		{
@@ -692,7 +708,10 @@
 			exit(2);
 			*/
+			Serving = -1;
 			error_handler(0, DIM_FATAL, DIMDNSDUPLC, str);
+			/*
 			do_dis_stop_serving_dns(dnsp);
 			dis_stop_serving();
+			*/
 /*
 			exit_tag = 0;
@@ -708,7 +727,10 @@
 			exit(2);
 */
+			Serving = -1;
 			error_handler(0, DIM_FATAL, DIMDNSREFUS, str);
+			/*
 			do_dis_stop_serving_dns(dnsp);
 			dis_stop_serving();
+			*/
 /*
 			exit_tag = 0;
@@ -721,4 +743,7 @@
 			sprintf(str, 
 				"%s: DNS requests Exit",dnsp->task_name);
+/*
+			Serving = -1;
+*/
 			error_handler(0, DIM_FATAL, DIMDNSEXIT, str);
 			break;
@@ -1063,4 +1088,9 @@
 	{
 	DISABLE_AST
+	if(Serving == -1)
+	{
+		ENABLE_AST
+		return(0);
+	}
 	  /*
 #ifdef VxWorks
@@ -1460,5 +1490,13 @@
 	if( !dna_write_nowait(reqp->conn_id, Dis_packet, header_size + size) ) 
 	{
-		reqp->to_delete = 1;
+		if(reqp->delay_delete > 1)
+		{
+			reqp->to_delete = 1;
+		}
+		else
+		{
+			reqp->delay_delete = 0;
+			release_conn(reqp->conn_id, 1, 0);
+		}
 	}
 /*
@@ -1639,4 +1677,9 @@
 
 	DISABLE_AST
+	if(Serving == -1)
+	{
+		ENABLE_AST
+		return(found);
+	}
 	if(!service_id)
 	{
@@ -2233,4 +2276,7 @@
 int hash_index;
 
+/*
+	if(Serving != -1)
+*/
 	Serving = 0;
 	dis_init();
@@ -2279,4 +2325,7 @@
 	dtq_delete(Dis_timer_q);
 	Dis_timer_q = 0;
+/*
+	if(Serving != -1)
+*/
 	dim_stop_threads();
 }
@@ -2517,5 +2566,5 @@
 /* Would do it too early, the client will disconnect anyway
 */
-	if((remove) && (!Serving))
+	if((remove) && (Serving == 0))
 	{
 		clip = find_client(conn_id);
Index: trunk/FACT++/dim/src/dns.c
===================================================================
--- trunk/FACT++/dim/src/dns.c	(revision 11071)
+++ trunk/FACT++/dim/src/dns.c	(revision 11121)
@@ -74,7 +74,7 @@
 static int Last_conn_id;
 /*
-static int Debug = TRUE;
-*/
-static int Debug = FALSE;
+static int Debug = 2;
+*/
+static int Debug = 0;
 
 static int Timer_q;
@@ -93,5 +93,5 @@
 _DIM_PROTO( void send_dns_server_info,   (int conn_id, int **bufp, int *size) );
 _DIM_PROTO( void print_stats,            (void) );
-_DIM_PROTO( void set_debug_on,           (void) );
+_DIM_PROTO( void set_debug_on,           (int level) );
 _DIM_PROTO( void set_debug_off,          (void) );
 _DIM_PROTO( void kill_servers,           (void) );
@@ -207,4 +207,5 @@
 				rem_only = 1;
 		}
+/*
     if( Debug )
 	{
@@ -217,4 +218,5 @@
 			fflush(stdout);
 	}
+*/
 		if(rem_only)
 			return 0;
Index: trunk/FACT++/dim/src/examples/test_client.c
===================================================================
--- trunk/FACT++/dim/src/examples/test_client.c	(revision 11071)
+++ trunk/FACT++/dim/src/examples/test_client.c	(revision 11121)
@@ -54,4 +54,9 @@
 }
 */
+
+void version_rout( int *tag, int *buf, int *size)
+{
+	printf("Received VERSION %x, %d\n", buf, *size);
+}
 
 void rout( tag, buf, size )
@@ -124,4 +129,7 @@
 			  &no_link, 4 );
 
+	sprintf(str,"%s/VERSION_NUMBER",argv[2]);
+	dic_info_service( str, MONITORED, 0, 0, 0, version_rout, 0,
+			  NULL, 0 );
 /*	
 	sprintf(aux,"%s/TestMem",argv[2]);
Index: trunk/FACT++/dim/src/examples/test_server.c
===================================================================
--- trunk/FACT++/dim/src/examples/test_server.c	(revision 11071)
+++ trunk/FACT++/dim/src/examples/test_server.c	(revision 11121)
@@ -145,4 +145,13 @@
 		printf("client %s\n",name);
 	}
+/*
+	for(i = 0; i < 5; i++)
+	{
+		sleep(10);
+
+	}
+	dis_stop_serving();
+	sleep(59);
+*/
 	while(1)
 	{
@@ -183,4 +192,5 @@
 		}
 */
+		/*
 		if(new_dns)
 		{
@@ -195,5 +205,5 @@
 				}
 				NewIds[10] = 0;
-				dis_start_serving_dns(dnsid, "xx_new"/*, NewIds*/);
+				dis_start_serving_dns(dnsid, "xx_new");
 				on = 1;
 			}
@@ -208,4 +218,5 @@
 			}
 		}
+		*/
 	}
 	return 1;
Index: trunk/FACT++/dim/src/tcpip.c
===================================================================
--- trunk/FACT++/dim/src/tcpip.c	(revision 11071)
+++ trunk/FACT++/dim/src/tcpip.c	(revision 11121)
@@ -34,7 +34,7 @@
 #else
 /*
-#define closesock(s) shutdown(s,2);
-*/
-#define closesock close
+#define closesock(s) shutdown(s,2)
+*/
+#define closesock(s) close(s)
 #define readsock(a,b,c,d) read(a,b,c)
 
@@ -990,4 +990,5 @@
 	Net_conns[conn_id].reading = -1;
 	Net_conns[conn_id].timr_ent = NULL;
+	Net_conns[conn_id].write_timedout = 0;
 	return(1);
 }
@@ -1114,4 +1115,5 @@
 	Net_conns[conn_id].reading = -1;
 	Net_conns[conn_id].timr_ent = NULL;
+	Net_conns[conn_id].write_timedout = 0;
 	return(1);
 }
@@ -1188,4 +1190,5 @@
 	Net_conns[conn_id].reading = -1;
 	Net_conns[conn_id].timr_ent = NULL;
+	Net_conns[conn_id].write_timedout = 0;
 	return(1);
 }
@@ -1279,5 +1282,11 @@
 		}
 		else
+		{
 			return(0);
+		}
+	}
+	if(wrote == -1)
+	{
+		Net_conns[conn_id].write_timedout = 1;
 	}
 	return(wrote);
@@ -1300,5 +1309,14 @@
 	Net_conns[conn_id].task[0] = 0;
 	if(channel)
+	{
+		if(Net_conns[conn_id].write_timedout)
+		{
+			Net_conns[conn_id].write_timedout = 0;
+#if defined(__linux__) && !defined (darwin)
+			shutdown(channel, 2);
+#endif
+		}
 		closesock(channel);
+	}
 	return(1);
 }
