]> jxnshi.xyz Git - mesange.git/commitdiff
Set connect to host as non blocking
authorjxnshi <jxnshi@cock.li>
Sat, 11 Jan 2025 22:58:05 +0000 (23:58 +0100)
committerjxnshi <jxnshi@cock.li>
Sat, 11 Jan 2025 22:58:05 +0000 (23:58 +0100)
client-cli/main.odin
client-cli/state.odin
common/request.odin
server/main.odin
server/server

index 454974529f30c8b56d319452109af116e8e0179f..98739b4bb0f52d57bb5d2ba9f4d4cac1dfba1439 100644 (file)
@@ -57,7 +57,8 @@ App :: struct {
     seed_phrase_entropy: u128,
     seed_phrase_checksum: u8,
 
-    host: net.TCP_Socket,
+    host: Maybe(net.TCP_Socket),
+    connection_thread: Maybe(^thread.Thread),
 }
 
 app_init :: proc(storage_path: string) -> App {
@@ -432,5 +433,18 @@ main :: proc() {
             time.sleep(1_000_000)
             free_all(context.temp_allocator)
         }
+
+        #partial switch app.state {
+        case .Main:
+            {
+                sync.mutex_lock(&app.mutex)
+                defer sync.mutex_unlock(&app.mutex)
+
+                if app.host != nil && app.connection_thread != nil {
+                    thread.destroy(app.connection_thread)
+                    app.connection_thread = nil
+                }
+            }
+        }
     }
 }
index d50fecdc1117b882d32e425f9570598de587d004..7fdd8621f0a19982e5284b79e10112097f06ff65 100644 (file)
@@ -381,13 +381,8 @@ state_ask_profile_confirm_password :: proc(app: ^App) {
     app_set_state(app, .Connect_To_Host)
 }
 
-state_connect_to_host :: proc(app: ^App) {
-    app_set_box_message(
-        app,
-        {
-            "Connecting to host.",
-        }
-    )
+handle_connection_to_host :: proc(app: ^App) {
+    app_set_info_bar(app, "Connecting to host...")
 
     host_endpoint: net.Endpoint
     host_endpoint.port = DEFAULT_PORT
@@ -424,6 +419,22 @@ state_connect_to_host :: proc(app: ^App) {
 
         app.host = host
     }
+}
+
+state_connect_to_host :: proc(app: ^App) {
+    app_set_box_message(
+        app,
+        {
+            "Connecting to host.",
+        }
+    )
+
+    {
+        sync.mutex_lock(&app.mutex)
+        defer sunc.mutex_unlock(&app.mutex)
+
+        app.connection_thread = thread.create_and_start_with_poly_data(app, handle_connection_to_host, context)
+    }
 
     app_set_state(app, .Main)
 }
index 8e49086d770e1757b243959f41f924564d762391..3a16e2084114744f1b592c58a653d90a462f0954 100644 (file)
@@ -4,29 +4,12 @@ import "core:crypto/ed25519"
 
 Public_Key_Bytes :: [32]u8
 
-Create_Room :: struct {
-    room_id: string,
-    public: bool,
-}
-
-Kick_User :: struct {
-    user_public_key: ed25519.Public_Key,
-}
-
-Ban_User :: struct {
-    user_public_key: ed25519.Public_Key,
-}
-
 Message :: struct {
     room_id: string,
     content: string,
 }
 
 Client_Request_Content :: union {
-    Create_Room,
-    Kick_User,
-    Ban_User,
-
     Message,
 }
 
index 06197b6f437c998c82244396103089524c3e0540..b88772afa6cb3a4605680734e80b1dfd876cc522 100644 (file)
@@ -26,8 +26,8 @@ handle_client :: proc(data: Handle_Client_Data) {
     defer {
         log.infof("Client %v disconnected.", client_endpoint_string)
 
-        sync.mutex_lock(clients_sockets_mutex)
-        defer sync.mutex_unlock(clients_sockets_mutex)
+        sync.mutex_lock(mutex)
+        defer sync.mutex_unlock(mutex)
 
         delete_key(clients_sockets, client_endpoint)
     }
@@ -111,7 +111,7 @@ main :: proc() {
     }
 
     server_endpoint := net.Endpoint{
-        address = net.IP4_Address{ 127, 0, 0, 1 },
+        address = net.IP4_Address{ 0, 0, 0, 0 },
         port = 3000,
     }
 
@@ -174,7 +174,7 @@ main :: proc() {
 
         client_handle_data := Handle_Client_Data{
             clients_sockets = &clients_sockets,
-            clients_sockets_mutex = &clients_sockets_mutex,
+            mutex = &mutex,
             
             client_socket = client_socket,
             client_endpoint = client_endpoint,
index 5281b5a6e6b840841fe12afd1ba20662db82f5ec..0f3f2857c4bfccdf6a20effd5d19fc16f303bc8e 100755 (executable)
Binary files a/server/server and b/server/server differ