Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 32:08a465eec50b | 33:c0f6c8c7829f |
|---|---|
| 146 Seobeo_PHandle Seobeo_Stream_Handle_Server_Accept(Seobeo_PHandle p_server_handle) | 146 Seobeo_PHandle Seobeo_Stream_Handle_Server_Accept(Seobeo_PHandle p_server_handle) |
| 147 { | 147 { |
| 148 struct sockaddr_storage addr; | 148 struct sockaddr_storage addr; |
| 149 socklen_t addrlen = sizeof addr; | 149 socklen_t addrlen = sizeof addr; |
| 150 char client_inet_addr[INET6_ADDRSTRLEN]; | 150 char client_inet_addr[INET6_ADDRSTRLEN]; |
| 151 | |
| 151 int client_fd = accept(p_server_handle->socket, | 152 int client_fd = accept(p_server_handle->socket, |
| 152 (struct sockaddr*)&addr, | 153 (struct sockaddr*)&addr, |
| 153 &addrlen); | 154 &addrlen); |
| 154 inet_ntop( | 155 inet_ntop( |
| 155 addr.ss_family, | 156 addr.ss_family, |
| 156 Seobeo_Get_IP4_Or_IP6((struct sockaddr *)&addr), | 157 Seobeo_Get_IP4_Or_IP6((struct sockaddr *)&addr), |
| 157 client_inet_addr, sizeof client_inet_addr); | 158 client_inet_addr, sizeof client_inet_addr); |
| 158 | 159 if (client_fd == -1) return NULL; |
| 159 if (client_fd == -1) | 160 |
| 160 { | 161 // Set non blocking... |
| 161 return NULL; | 162 int flags = fcntl(client_fd, F_GETFL, 0); |
| 162 } | 163 if (flags == -1) return NULL; |
| 164 fcntl(client_fd, F_SETFL, flags | O_NONBLOCK); | |
| 163 | 165 |
| 164 Seobeo_PHandle p_client_handle = malloc(sizeof *p_client_handle); | 166 Seobeo_PHandle p_client_handle = malloc(sizeof *p_client_handle); |
| 165 | 167 |
| 166 p_client_handle->socket = client_fd; | 168 p_client_handle->socket = client_fd; |
| 167 p_client_handle->type = SEOBEO_STREAM_TYPE_CLIENT; | 169 p_client_handle->type = SEOBEO_STREAM_TYPE_CLIENT; |