Mercurial
diff seobeo/s_linux_network.c @ 62:ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Tue, 23 Dec 2025 11:48:11 -0800 |
| parents | 84672efec192 |
| children | a0f0ad5e42eb |
line wrap: on
line diff
--- a/seobeo/s_linux_network.c Sat Dec 20 21:07:34 2025 -0500 +++ b/seobeo/s_linux_network.c Tue Dec 23 11:48:11 2025 -0800 @@ -28,7 +28,14 @@ { perror("socket"); continue; } if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) - { perror("setsockopt"); continue; } + { perror("setsockopt SO_REUSEADDR"); continue; } + +#ifdef SO_REUSEPORT + // SO_REUSEPORT allows multiple threads/processes to bind to the same port + // The kernel will distribute incoming connections among them + if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) == -1) + { perror("setsockopt SO_REUSEPORT"); continue; } +#endif if (bind(socket_fd, free_server_info->ai_addr, free_server_info->ai_addrlen) == -1) { perror("v_network: Couldn't make socket non-blocking\n"); continue; } @@ -182,7 +189,11 @@ p_client_handle->write_buffer_len = 0; p_client_handle->write_buffer = malloc(p_client_handle->write_buffer_capacity); - p_client_handle->destroyed = false; + p_client_handle->read_buffer_used = 0; + p_client_handle->file = NULL; + p_client_handle->text_copy = NULL; + p_client_handle->file_name = NULL; + p_client_handle->destroyed = false; return p_client_handle; } @@ -314,15 +325,17 @@ return 0; } - if (!p_handle) { + if (!p_handle) + { printf("[ERROR] p_handle is NULL before memcpy\n"); - return; + return -1; } - if (!p_handle->write_buffer) { + if (!p_handle->write_buffer) + { printf("[ERROR] p_handle->write_buffer is NULL (len=%zu, size=%zu)\n", p_handle->write_buffer_len, data_size); - return; + return -1; } printf("[DEBUG] memcpy -> dest=%p (write_buffer=%p + offset=%zu), src=%p, size=%zu\n",