comparison seobeo/s_linux_network.c @ 16:fb2cff495a60

[Seobeo] Fixed the problem with edge server.
author June Park <parkjune1995@gmail.com>
date Fri, 03 Oct 2025 09:55:51 -0700
parents 1e61008b9980
children d97ec3ded2ae
comparison
equal deleted inserted replaced
15:2b9e75756825 16:fb2cff495a60
104 p_handle->write_buffer_len = 0; 104 p_handle->write_buffer_len = 0;
105 105
106 p_handle->file = NULL; 106 p_handle->file = NULL;
107 p_handle->text_copy = NULL; 107 p_handle->text_copy = NULL;
108 p_handle->file_name = NULL; 108 p_handle->file_name = NULL;
109 p_handle->destroyed = false;
109 110
110 return p_handle; 111 return p_handle;
111 } 112 }
112 113
113 Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle p_server_handle) 114 Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle p_server_handle)
145 return p_client_handle; 146 return p_client_handle;
146 } 147 }
147 148
148 void Seobeo_Handle_Destroy(Seobeo_PHandle p_handle) 149 void Seobeo_Handle_Destroy(Seobeo_PHandle p_handle)
149 { 150 {
150 close(p_handle->socket); 151 if (!p_handle) return;
151 free(p_handle->host); 152
152 free(p_handle->port); 153 bool expected = false;
153 free(p_handle->read_buffer); 154 if (!atomic_compare_exchange_strong(&p_handle->destroyed, &expected, true))
154 free(p_handle->write_buffer); 155 {
155 free(p_handle->file); 156 // Already destroyed by another thread
156 free(p_handle->text_copy); 157 return;
157 free(p_handle->file_name); 158 }
159
160 if (p_handle->host) free(p_handle->host);
161 if (p_handle->port) free(p_handle->port);
162 if (p_handle->socket) close(p_handle->socket);
163 if (p_handle->read_buffer) free(p_handle->read_buffer);
164 if (p_handle->write_buffer) free(p_handle->write_buffer);
165 if (p_handle->text_copy) free(p_handle->text_copy);
166 if (p_handle->file_name) free(p_handle->file_name);
167
158 free(p_handle); 168 free(p_handle);
159 } 169 }
160 170
161 int Seobeo_Handle_Flush(Seobeo_PHandle p_handle) 171 int Seobeo_Handle_Flush(Seobeo_PHandle p_handle)
162 { 172 {