From 5020bd47f0216cfe8cbe7bd84619d8dc4668839a Mon Sep 17 00:00:00 2001
From: "Constantin P." <papizh.konstantin@demlabs.net>
Date: Fri, 31 May 2024 15:37:03 +0700
Subject: [PATCH 1/3] ...

---
 core/src/dap_common.c                             | 2 +-
 net/server/notify_server/include/dap_notify_srv.h | 2 ++
 net/server/notify_server/src/dap_notify_srv.c     | 9 ++++++++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/core/src/dap_common.c b/core/src/dap_common.c
index 02d476dd9..d088cd907 100755
--- a/core/src/dap_common.c
+++ b/core/src/dap_common.c
@@ -345,7 +345,7 @@ int wdap_common_init( const char *a_console_title, const wchar_t *a_log_filename
         if( s_log_file == NULL)
             s_log_file = _wfopen( a_log_filename , L"w" );
         if ( s_log_file == NULL ) {
-            dap_fprintf( stderr, "Can't open log file %ls to append\n", a_log_filename );
+            fprintf( stderr, "Can't open log file %ls to append\n", a_log_filename );
             return -1;
         }
         //dap_stpcpy(s_log_file_path, a_log_filename);
diff --git a/net/server/notify_server/include/dap_notify_srv.h b/net/server/notify_server/include/dap_notify_srv.h
index f93bfa10b..43904e188 100644
--- a/net/server/notify_server/include/dap_notify_srv.h
+++ b/net/server/notify_server/include/dap_notify_srv.h
@@ -30,3 +30,5 @@ void dap_notify_server_deinit();
 DAP_PRINTF_ATTR(2, 3) int dap_notify_server_send_f_inter(uint32_t a_worker_id, const char *a_format, ...);
 int dap_notify_server_send_mt(const char * a_data);
 DAP_PRINTF_ATTR(1, 2) int dap_notify_server_send_f_mt(const char *a_format, ...);
+
+void dap_notify_srv_set_callback_new(dap_events_socket_callback_t);
\ No newline at end of file
diff --git a/net/server/notify_server/src/dap_notify_srv.c b/net/server/notify_server/src/dap_notify_srv.c
index 18217b835..c5faa9b15 100644
--- a/net/server/notify_server/src/dap_notify_srv.c
+++ b/net/server/notify_server/src/dap_notify_srv.c
@@ -49,6 +49,11 @@ static void s_notify_server_callback_queue(dap_events_socket_t * a_es, void * a_
 static void s_notify_server_callback_new(dap_events_socket_t * a_es, void * a_arg);
 static void s_notify_server_callback_delete(dap_events_socket_t * a_es, void * a_arg);
 
+dap_events_socket_callback_t s_notify_server_callback_new_ex = NULL;
+
+void dap_notify_srv_set_callback_new(dap_events_socket_callback_t a_cb) {
+    s_notify_server_callback_new_ex = a_cb;
+}
 
 /**
  * @brief dap_notify_server_init
@@ -72,7 +77,7 @@ int dap_notify_server_init()
         log_it(L_ERROR,"Notify server not initalized, check config");
         return -1;
     }
-    s_notify_server->client_callbacks.new_callback = s_notify_server_callback_new;
+    s_notify_server->client_callbacks.worker_assign_callback = s_notify_server_callback_new;
     s_notify_server->client_callbacks.delete_callback = s_notify_server_callback_delete;
     s_notify_server_queue = dap_events_socket_create_type_queue_ptr_mt(dap_events_worker_get_auto(),s_notify_server_callback_queue);
     uint32_t l_workers_count = dap_events_thread_get_count();
@@ -253,6 +258,8 @@ static void s_notify_server_callback_new(dap_events_socket_t * a_es, UNUSED_ARG
         HASH_ADD(hh, s_notify_server_clients, uuid, sizeof (l_hh_new->uuid), l_hh_new);
     }
     pthread_rwlock_unlock(&s_notify_server_clients_mutex);
+    if (s_notify_server_callback_new_ex)
+        s_notify_server_callback_new_ex(a_es, NULL);
 }
 
 /**
-- 
GitLab


From 98c098f07737f9d8437a528a7afcd59a1861f8ed Mon Sep 17 00:00:00 2001
From: Constantin P <papizh.konstantin@demlabs.net>
Date: Mon, 3 Jun 2024 14:01:28 +0700
Subject: [PATCH 2/3] ....

---
 net/server/notify_server/src/dap_notify_srv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/server/notify_server/src/dap_notify_srv.c b/net/server/notify_server/src/dap_notify_srv.c
index c5faa9b15..f0caf1fad 100644
--- a/net/server/notify_server/src/dap_notify_srv.c
+++ b/net/server/notify_server/src/dap_notify_srv.c
@@ -77,7 +77,7 @@ int dap_notify_server_init()
         log_it(L_ERROR,"Notify server not initalized, check config");
         return -1;
     }
-    s_notify_server->client_callbacks.worker_assign_callback = s_notify_server_callback_new;
+    s_notify_server->client_callbacks.new_callback = s_notify_server_callback_new;
     s_notify_server->client_callbacks.delete_callback = s_notify_server_callback_delete;
     s_notify_server_queue = dap_events_socket_create_type_queue_ptr_mt(dap_events_worker_get_auto(),s_notify_server_callback_queue);
     uint32_t l_workers_count = dap_events_thread_get_count();
-- 
GitLab


From 0f1707c2e2aa11ad7552a6b9013a87f45ff72ed8 Mon Sep 17 00:00:00 2001
From: Constantin P <papizh.konstantin@demlabs.net>
Date: Mon, 3 Jun 2024 20:32:46 +0700
Subject: [PATCH 3/3] Client socket assignment fix

---
 io/dap_server.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/io/dap_server.c b/io/dap_server.c
index 5b3e09de7..70f77727d 100644
--- a/io/dap_server.c
+++ b/io/dap_server.c
@@ -495,13 +495,13 @@ static void s_es_server_accept(dap_events_socket_t *a_es_listener, SOCKET a_remo
 #endif
         l_es_new->worker = l_worker;
         l_es_new->last_time_active = time(NULL);
-        if (l_es_new->callbacks.new_callback)
-            l_es_new->callbacks.new_callback(l_es_new, NULL);
-        l_es_new->is_initalized = true;
         if (dap_worker_add_events_socket_unsafe(l_worker, l_es_new)) {
             log_it(L_CRITICAL, "Can't add event socket's handler to worker i/o poll mechanism with error %d", errno);
             return;
         }
+        if (l_es_new->callbacks.new_callback)
+            l_es_new->callbacks.new_callback(l_es_new, NULL);
+        l_es_new->is_initalized = true;
         debug_if(g_debug_reactor, L_INFO, "Direct addition of esocket %p uuid 0x%"DAP_UINT64_FORMAT_x" to worker %d",
                  l_es_new, l_es_new->uuid, l_worker->id);
     } else
-- 
GitLab