Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 61:9df5587cf23b | 62:ea9ef388ab97 |
|---|---|
| 26 if((socket_fd = socket(free_server_info->ai_family, | 26 if((socket_fd = socket(free_server_info->ai_family, |
| 27 free_server_info->ai_socktype, free_server_info->ai_protocol)) == -1) | 27 free_server_info->ai_socktype, free_server_info->ai_protocol)) == -1) |
| 28 { perror("socket"); continue; } | 28 { perror("socket"); continue; } |
| 29 | 29 |
| 30 if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) | 30 if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) |
| 31 { perror("setsockopt"); continue; } | 31 { perror("setsockopt SO_REUSEADDR"); continue; } |
| 32 | |
| 33 #ifdef SO_REUSEPORT | |
| 34 // SO_REUSEPORT allows multiple threads/processes to bind to the same port | |
| 35 // The kernel will distribute incoming connections among them | |
| 36 if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) == -1) | |
| 37 { perror("setsockopt SO_REUSEPORT"); continue; } | |
| 38 #endif | |
| 32 | 39 |
| 33 if (bind(socket_fd, free_server_info->ai_addr, free_server_info->ai_addrlen) == -1) | 40 if (bind(socket_fd, free_server_info->ai_addr, free_server_info->ai_addrlen) == -1) |
| 34 { perror("v_network: Couldn't make socket non-blocking\n"); continue; } | 41 { perror("v_network: Couldn't make socket non-blocking\n"); continue; } |
| 35 | 42 |
| 36 break; | 43 break; |
| 180 | 187 |
| 181 p_client_handle->write_buffer_capacity = p_server_handle->write_buffer_capacity; | 188 p_client_handle->write_buffer_capacity = p_server_handle->write_buffer_capacity; |
| 182 p_client_handle->write_buffer_len = 0; | 189 p_client_handle->write_buffer_len = 0; |
| 183 p_client_handle->write_buffer = malloc(p_client_handle->write_buffer_capacity); | 190 p_client_handle->write_buffer = malloc(p_client_handle->write_buffer_capacity); |
| 184 | 191 |
| 185 p_client_handle->destroyed = false; | 192 p_client_handle->read_buffer_used = 0; |
| 193 p_client_handle->file = NULL; | |
| 194 p_client_handle->text_copy = NULL; | |
| 195 p_client_handle->file_name = NULL; | |
| 196 p_client_handle->destroyed = false; | |
| 186 | 197 |
| 187 return p_client_handle; | 198 return p_client_handle; |
| 188 } | 199 } |
| 189 | 200 |
| 190 void Seobeo_Handle_Destroy(Seobeo_PHandle p_handle) | 201 void Seobeo_Handle_Destroy(Seobeo_PHandle p_handle) |
| 312 // DEBUG | 323 // DEBUG |
| 313 printf("\n\nTotal: %d\n", offset); | 324 printf("\n\nTotal: %d\n", offset); |
| 314 return 0; | 325 return 0; |
| 315 } | 326 } |
| 316 | 327 |
| 317 if (!p_handle) { | 328 if (!p_handle) |
| 329 { | |
| 318 printf("[ERROR] p_handle is NULL before memcpy\n"); | 330 printf("[ERROR] p_handle is NULL before memcpy\n"); |
| 319 return; | 331 return -1; |
| 320 } | 332 } |
| 321 | 333 |
| 322 if (!p_handle->write_buffer) { | 334 if (!p_handle->write_buffer) |
| 335 { | |
| 323 printf("[ERROR] p_handle->write_buffer is NULL (len=%zu, size=%zu)\n", | 336 printf("[ERROR] p_handle->write_buffer is NULL (len=%zu, size=%zu)\n", |
| 324 p_handle->write_buffer_len, data_size); | 337 p_handle->write_buffer_len, data_size); |
| 325 return; | 338 return -1; |
| 326 } | 339 } |
| 327 | 340 |
| 328 printf("[DEBUG] memcpy -> dest=%p (write_buffer=%p + offset=%zu), src=%p, size=%zu\n", | 341 printf("[DEBUG] memcpy -> dest=%p (write_buffer=%p + offset=%zu), src=%p, size=%zu\n", |
| 329 p_handle->write_buffer + p_handle->write_buffer_len, | 342 p_handle->write_buffer + p_handle->write_buffer_len, |
| 330 p_handle->write_buffer, | 343 p_handle->write_buffer, |