Mercurial
comparison seobeo/s_linux_network.c @ 66:a0f0ad5e42eb
[Misc] taking out capital P stuff.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 24 Dec 2025 06:34:19 -0800 |
| parents | ea9ef388ab97 |
| children | 6626ec933933 |
comparison
equal
deleted
inserted
replaced
| 65:ecb6ee6a22c3 | 66:a0f0ad5e42eb |
|---|---|
| 1 #include "seobeo/seobeo.h" | 1 #include "seobeo/seobeo.h" |
| 2 | 2 |
| 3 | 3 |
| 4 Seobeo_PHandle Seobeo_Stream_Handle_Server_Create(const char *host, const char* port) | 4 Seobeo_Handle *Seobeo_Stream_Handle_Server_Create(const char *host, const char* port) |
| 5 { | 5 { |
| 6 Seobeo_PHandle p_handle; | 6 Seobeo_Handle *p_handle; |
| 7 struct addrinfo hints, *server_infos, *free_server_info; | 7 struct addrinfo hints, *server_infos, *free_server_info; |
| 8 int32 socket_fd, yes = 1; // Need this for setsockopt | 8 int32 socket_fd, yes = 1; // Need this for setsockopt |
| 9 | 9 |
| 10 memset(&hints, 0, sizeof hints); | 10 memset(&hints, 0, sizeof hints); |
| 11 hints.ai_family = AF_UNSPEC; | 11 hints.ai_family = AF_UNSPEC; |
| 77 | 77 |
| 78 return p_handle; | 78 return p_handle; |
| 79 } | 79 } |
| 80 | 80 |
| 81 | 81 |
| 82 Seobeo_PHandle Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls) | 82 Seobeo_Handle *Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls) |
| 83 { | 83 { |
| 84 Seobeo_PHandle p_handle; | 84 Seobeo_Handle *p_handle; |
| 85 p_handle = malloc(sizeof(*p_handle)); | 85 p_handle = malloc(sizeof(*p_handle)); |
| 86 | 86 |
| 87 struct addrinfo hints, *server_infos; | 87 struct addrinfo hints, *server_infos; |
| 88 int32 socket_fd; // Need this for setsockopt | 88 int32 socket_fd; // Need this for setsockopt |
| 89 | 89 |
| 146 p_handle->destroyed = false; | 146 p_handle->destroyed = false; |
| 147 | 147 |
| 148 return p_handle; | 148 return p_handle; |
| 149 } | 149 } |
| 150 | 150 |
| 151 Seobeo_PHandle Seobeo_Stream_Handle_Server_Accept(Seobeo_PHandle p_server_handle) | 151 Seobeo_Handle *Seobeo_Stream_Handle_Server_Accept(Seobeo_Handle *p_server_handle) |
| 152 { | 152 { |
| 153 struct sockaddr_storage addr; | 153 struct sockaddr_storage addr; |
| 154 socklen_t addrlen = sizeof addr; | 154 socklen_t addrlen = sizeof addr; |
| 155 char client_inet_addr[INET6_ADDRSTRLEN]; | 155 char client_inet_addr[INET6_ADDRSTRLEN]; |
| 156 | 156 |
| 166 // Set non blocking... | 166 // Set non blocking... |
| 167 int flags = fcntl(client_fd, F_GETFL, 0); | 167 int flags = fcntl(client_fd, F_GETFL, 0); |
| 168 if (flags == -1) return NULL; | 168 if (flags == -1) return NULL; |
| 169 fcntl(client_fd, F_SETFL, flags | O_NONBLOCK); | 169 fcntl(client_fd, F_SETFL, flags | O_NONBLOCK); |
| 170 | 170 |
| 171 Seobeo_PHandle p_client_handle = malloc(sizeof *p_client_handle); | 171 Seobeo_Handle *p_client_handle = malloc(sizeof *p_client_handle); |
| 172 | 172 |
| 173 p_client_handle->socket = client_fd; | 173 p_client_handle->socket = client_fd; |
| 174 p_client_handle->type = SEOBEO_STREAM_TYPE_CLIENT; | 174 p_client_handle->type = SEOBEO_STREAM_TYPE_CLIENT; |
| 175 p_client_handle->connected = true; | 175 p_client_handle->connected = true; |
| 176 | 176 |
| 196 p_client_handle->destroyed = false; | 196 p_client_handle->destroyed = false; |
| 197 | 197 |
| 198 return p_client_handle; | 198 return p_client_handle; |
| 199 } | 199 } |
| 200 | 200 |
| 201 void Seobeo_Handle_Destroy(Seobeo_PHandle p_handle) | 201 void Seobeo_Handle_Destroy(Seobeo_Handle *p_handle) |
| 202 { | 202 { |
| 203 if (!p_handle) return; | 203 if (!p_handle) return; |
| 204 | 204 |
| 205 bool expected = false; | 205 bool expected = false; |
| 206 // Need to check | 206 // Need to check |
| 235 | 235 |
| 236 Dowa_Free(p_handle); | 236 Dowa_Free(p_handle); |
| 237 } | 237 } |
| 238 | 238 |
| 239 | 239 |
| 240 int32 Seobeo_Handle_Flush(Seobeo_PHandle p_handle) | 240 int32 Seobeo_Handle_Flush(Seobeo_Handle *p_handle) |
| 241 { | 241 { |
| 242 uint32 total = p_handle->write_buffer_len; | 242 uint32 total = p_handle->write_buffer_len; |
| 243 uint32 sent = 0; | 243 uint32 sent = 0; |
| 244 | 244 |
| 245 printf("Total: %d\n\n", p_handle->write_buffer_len); | 245 printf("Total: %d\n\n", p_handle->write_buffer_len); |
| 280 | 280 |
| 281 p_handle->write_buffer_len = 0; | 281 p_handle->write_buffer_len = 0; |
| 282 return 0; | 282 return 0; |
| 283 } | 283 } |
| 284 | 284 |
| 285 int32 Seobeo_Handle_Queue(Seobeo_PHandle p_handle, const uint8 *data, uint32 data_size) | 285 int32 Seobeo_Handle_Queue(Seobeo_Handle *p_handle, const uint8 *data, uint32 data_size) |
| 286 { | 286 { |
| 287 if (p_handle->write_buffer_len + data_size > p_handle->write_buffer_capacity) | 287 if (p_handle->write_buffer_len + data_size > p_handle->write_buffer_capacity) |
| 288 { | 288 { |
| 289 int32 rc = Seobeo_Handle_Flush(p_handle); | 289 int32 rc = Seobeo_Handle_Flush(p_handle); |
| 290 if (rc < 0) return -1; | 290 if (rc < 0) return -1; |
| 350 data_size); | 350 data_size); |
| 351 p_handle->write_buffer_len += data_size; | 351 p_handle->write_buffer_len += data_size; |
| 352 return 0; | 352 return 0; |
| 353 } | 353 } |
| 354 | 354 |
| 355 int32 Seobeo_Handle_Read(Seobeo_PHandle p_handle) | 355 int32 Seobeo_Handle_Read(Seobeo_Handle *p_handle) |
| 356 { | 356 { |
| 357 int32 read_size; | 357 int32 read_size; |
| 358 if (!p_handle) return -1; | 358 if (!p_handle) return -1; |
| 359 | 359 |
| 360 // How many bytes we can still read into the buffer | 360 // How many bytes we can still read into the buffer |
| 395 | 395 |
| 396 p_handle->read_buffer_len += (uint32)read_size; | 396 p_handle->read_buffer_len += (uint32)read_size; |
| 397 return read_size; | 397 return read_size; |
| 398 } | 398 } |
| 399 | 399 |
| 400 void Seobeo_Handle_Consume(Seobeo_PHandle p_handle, uint32 consumed) | 400 void Seobeo_Handle_Consume(Seobeo_Handle *p_handle, uint32 consumed) |
| 401 { | 401 { |
| 402 if (consumed >= p_handle->read_buffer_len) | 402 if (consumed >= p_handle->read_buffer_len) |
| 403 { | 403 { |
| 404 p_handle->read_buffer_len = 0; | 404 p_handle->read_buffer_len = 0; |
| 405 return; | 405 return; |