diff seobeo/s_linux_network.c @ 33:c0f6c8c7829f

[Seobeo] Linux epoll. Set the client socket to be nonblocking so that it doesn't stop loading when two different threads handle different client calls. I might have problem with socket not being cleaned up properly so need to check that.
author MrJuneJune <me@mrjunejune.com>
date Fri, 10 Oct 2025 06:59:32 -0700
parents 947b81010aba
children 84672efec192
line wrap: on
line diff
--- a/seobeo/s_linux_network.c	Thu Oct 09 07:03:36 2025 -0700
+++ b/seobeo/s_linux_network.c	Fri Oct 10 06:59:32 2025 -0700
@@ -148,6 +148,7 @@
   struct sockaddr_storage addr;
   socklen_t addrlen = sizeof addr;
   char client_inet_addr[INET6_ADDRSTRLEN];
+
   int client_fd = accept(p_server_handle->socket,
                          (struct sockaddr*)&addr,
                          &addrlen);
@@ -155,11 +156,12 @@
       addr.ss_family,
       Seobeo_Get_IP4_Or_IP6((struct sockaddr *)&addr),
       client_inet_addr, sizeof client_inet_addr);
+  if (client_fd == -1) return NULL;
 
-  if (client_fd == -1)
-  {
-    return NULL;
-  }
+  // Set non blocking...
+  int flags = fcntl(client_fd, F_GETFL, 0);
+  if (flags == -1) return NULL;
+  fcntl(client_fd, F_SETFL, flags | O_NONBLOCK);
 
   Seobeo_PHandle p_client_handle        = malloc(sizeof *p_client_handle);