Mercurial
comparison seobeo/s_websocket.c @ 121:7b1719fa918c
[Seobeo] Added web socket server.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 08 Jan 2026 06:45:10 -0800 |
| parents | cbbf78b17cfa |
| children | f236c895604e |
comparison
equal
deleted
inserted
replaced
| 120:cbbf78b17cfa | 121:7b1719fa918c |
|---|---|
| 1 #include "seobeo/seobeo.h" | 1 #include "seobeo/seobeo.h" |
| 2 #include <time.h> | 2 #include <time.h> |
| 3 | 3 |
| 4 #define SEOBEO_WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" | 4 #define SEOBEO_WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" |
| 5 #define MAX_INT_16 65536 | |
| 6 #define MAX_INT_64 18446744073709551615 | |
| 7 | 5 |
| 8 static void Seobeo_WebSocket_Parse_Url(const char *url, char **p_host, char **p_port, char **p_path, boolean *p_use_tls, Dowa_Arena *p_arena) | 6 static void Seobeo_WebSocket_Parse_Url(const char *url, char **p_host, char **p_port, char **p_path, boolean *p_use_tls, Dowa_Arena *p_arena) |
| 9 { | 7 { |
| 10 if (!url) | 8 if (!url) |
| 11 return; | 9 return; |
| 254 } | 252 } |
| 255 | 253 |
| 256 return Seobeo_Handle_Flush(p_ws->p_handle); | 254 return Seobeo_Handle_Flush(p_ws->p_handle); |
| 257 } | 255 } |
| 258 | 256 |
| 259 static int32 Seobeo_WebSocket_Send_Fragmented(Seobeo_WebSocket *p_ws, Seobeo_WebSocket_Opcode opcode, const uint8 *payload, size_t total_length) | 257 static int32 Seobeo_WebSocket_Send_Fragmented(Seobeo_WebSocket *p_ws, Seobeo_WebSocket_Opcode opcode, |
| 258 const uint8 *payload, size_t total_length) | |
| 260 { | 259 { |
| 261 if (!payload || total_length == 0) | 260 if (!payload || total_length == 0) |
| 262 return -1; | 261 return -1; |
| 263 | 262 |
| 264 const size_t max_fragment_size = 1024 * 1024; | 263 if (total_length <= MAX_FRAGMENT_SIZE) |
| 265 | |
| 266 if (total_length <= max_fragment_size) | |
| 267 return Seobeo_WebSocket_Send_Frame(p_ws, opcode, payload, total_length, TRUE); | 264 return Seobeo_WebSocket_Send_Frame(p_ws, opcode, payload, total_length, TRUE); |
| 268 | 265 |
| 269 size_t sent = 0; | 266 size_t sent = 0; |
| 270 int32 result; | 267 int32 result; |
| 271 | 268 |
| 272 result = Seobeo_WebSocket_Send_Frame(p_ws, opcode, payload, max_fragment_size, FALSE); | 269 result = Seobeo_WebSocket_Send_Frame(p_ws, opcode, payload, MAX_FRAGMENT_SIZE, FALSE); |
| 273 if (result < 0) | 270 if (result < 0) |
| 274 return result; | 271 return result; |
| 275 | 272 |
| 276 sent += max_fragment_size; | 273 sent += MAX_FRAGMENT_SIZE; |
| 277 | 274 |
| 278 while (sent + max_fragment_size < total_length) | 275 while (sent + MAX_FRAGMENT_SIZE < total_length) |
| 279 { | 276 { |
| 280 result = Seobeo_WebSocket_Send_Frame(p_ws, SEOBEO_WS_OPCODE_CONTINUATION, payload + sent, max_fragment_size, FALSE); | 277 result = Seobeo_WebSocket_Send_Frame(p_ws, SEOBEO_WS_OPCODE_CONTINUATION, payload + sent, MAX_FRAGMENT_SIZE, FALSE); |
| 281 if (result < 0) | 278 if (result < 0) |
| 282 return result; | 279 return result; |
| 283 sent += max_fragment_size; | 280 sent += MAX_FRAGMENT_SIZE; |
| 284 } | 281 } |
| 285 | 282 |
| 286 size_t remaining = total_length - sent; | 283 size_t remaining = total_length - sent; |
| 287 return Seobeo_WebSocket_Send_Frame(p_ws, SEOBEO_WS_OPCODE_CONTINUATION, payload + sent, remaining, TRUE); | 284 return Seobeo_WebSocket_Send_Frame(p_ws, SEOBEO_WS_OPCODE_CONTINUATION, payload + sent, remaining, TRUE); |
| 288 } | 285 } |