From 9c198067a904be5f96003cb333896a4bd8ba3524 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Thu, 15 Apr 2004 11:57:22 +0000
Subject: [PATCH] services_terminate() no longer closes service sockets to
 signal shutdown (apparent cause of Win32 lock-up when closing socket from
 non-owner thread) using bool terminate instead, which doesn't abort select(),
 so using shorter default sem_chk_freq value (2 seconds vs 5).

---
 src/sbbs3/services.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/sbbs3/services.c b/src/sbbs3/services.c
index 563ca53f9a..1b208698a9 100644
--- a/src/sbbs3/services.c
+++ b/src/sbbs3/services.c
@@ -1419,15 +1419,10 @@ void DLLCALL services_terminate(void)
 {
 	DWORD i;
 
+   	lprintf(LOG_INFO,"0000 Services terminate");
 	terminated=TRUE;
-	for(i=0;i<services;i++) {
-		if(service[i].socket==INVALID_SOCKET)
-			continue;
-		if(service[i].options&SERVICE_OPT_STATIC)
-			continue;
-		close_socket(service[i].socket);
-		service[i].socket=INVALID_SOCKET;
-	}
+	for(i=0;i<services;i++)
+		service[i].terminated=TRUE;
 }
 
 #define NEXT_FIELD(p)	FIND_WHITESPACE(p); SKIP_WHITESPACE(p)
@@ -1577,7 +1572,8 @@ static void cleanup(int code)
 #endif
 
 	thread_down();
-    lprintf(LOG_DEBUG,"#### Services thread terminated (%lu clients served)",served);
+	if(terminated || code)
+		lprintf(LOG_DEBUG,"#### Services thread terminated (%lu clients served)",served);
 	status("Down");
 	if(startup!=NULL && startup->terminated!=NULL)
 		startup->terminated(startup->cbdata,code);
@@ -1656,7 +1652,7 @@ void DLLCALL services_thread(void* arg)
 #endif
 
 	/* Setup intelligent defaults */
-	if(startup->sem_chk_freq==0)			startup->sem_chk_freq=5;
+	if(startup->sem_chk_freq==0)			startup->sem_chk_freq=2;
 	if(startup->js_max_bytes==0)			startup->js_max_bytes=JAVASCRIPT_MAX_BYTES;
 	if(startup->js_cx_stack==0)				startup->js_cx_stack=JAVASCRIPT_CONTEXT_STACK;
 
-- 
GitLab