Mercurial
annotate seobeo/s_linux_network.c @ 64:a30944e5719e
Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Tue, 23 Dec 2025 15:18:46 -0800 |
| parents | ea9ef388ab97 |
| children | a0f0ad5e42eb |
| rev | line source |
|---|---|
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 #include "seobeo/seobeo.h" |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
2 |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
3 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
4 Seobeo_PHandle Seobeo_Stream_Handle_Server_Create(const char *host, const char* port) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
5 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
6 Seobeo_PHandle p_handle; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
7 struct addrinfo hints, *server_infos, *free_server_info; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
8 int32 socket_fd, yes = 1; // Need this for setsockopt |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
9 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
10 memset(&hints, 0, sizeof hints); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
11 hints.ai_family = AF_UNSPEC; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
12 hints.ai_socktype = SOCK_STREAM; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
13 hints.ai_protocol = IPPROTO_TCP; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
14 hints.ai_flags = AI_PASSIVE; |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
15 |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
16 if (getaddrinfo(host, port, &hints, &server_infos) != 0) |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
17 { perror("getaddrinfo"); return NULL; } |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
18 |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
19 for |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
20 ( |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
21 free_server_info = server_infos; |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
22 free_server_info != NULL; |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
23 free_server_info = free_server_info->ai_next |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
24 ) |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
25 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
26 if((socket_fd = socket(free_server_info->ai_family, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
27 free_server_info->ai_socktype, free_server_info->ai_protocol)) == -1) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
28 { perror("socket"); continue; } |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
29 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
30 if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
31 { perror("setsockopt SO_REUSEADDR"); continue; } |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
32 |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
33 #ifdef SO_REUSEPORT |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
34 // SO_REUSEPORT allows multiple threads/processes to bind to the same port |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
35 // The kernel will distribute incoming connections among them |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
36 if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) == -1) |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
37 { perror("setsockopt SO_REUSEPORT"); continue; } |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
38 #endif |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
39 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
40 if (bind(socket_fd, free_server_info->ai_addr, free_server_info->ai_addrlen) == -1) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
41 { perror("v_network: Couldn't make socket non-blocking\n"); continue; } |
| 17 | 42 |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
43 break; |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
44 } |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
45 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
46 if (listen(socket_fd, 16) != 0) |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
47 { |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
48 printf("Closing: %d", socket_fd); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
49 perror("listen"); close(socket_fd); return NULL; |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
50 } |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
51 |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
52 int flags = fcntl(socket_fd, F_GETFL, 0); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
53 if(fcntl(socket_fd, F_SETFL, flags | O_NONBLOCK) != 0) { perror("fcntl"); return NULL; } |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
54 freeaddrinfo(server_infos); |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
55 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
56 p_handle = malloc(sizeof(*p_handle)); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
57 p_handle->socket = socket_fd; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
58 p_handle->type = SEOBEO_STREAM_TYPE_SERVER; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
59 p_handle->connected = FALSE; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
60 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
61 p_handle->host = host != NULL ? strdup(host) : "localhost"; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
62 p_handle->port = strdup(port); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
63 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
64 p_handle->ssl_ctx = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
65 p_handle->ssl = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
66 |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
67 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
68 p_handle->read_buffer = malloc(sizeof(*p_handle->read_buffer) * INITIAL_BUFFER_CAPACITY); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
69 p_handle->read_buffer_capacity = INITIAL_BUFFER_CAPACITY; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
70 p_handle->read_buffer_len = 0; |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
71 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
72 p_handle->write_buffer = malloc(sizeof(*p_handle->read_buffer) * INITIAL_BUFFER_CAPACITY); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
73 p_handle->write_buffer_capacity = INITIAL_BUFFER_CAPACITY; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
74 p_handle->write_buffer_len = 0; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
75 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
76 p_handle->destroyed = false; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
77 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
78 return p_handle; |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
79 } |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
80 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
81 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
82 Seobeo_PHandle Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls) |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
83 { |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
84 Seobeo_PHandle p_handle; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
85 p_handle = malloc(sizeof(*p_handle)); |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
86 |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
87 struct addrinfo hints, *server_infos; |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
88 int32 socket_fd; // Need this for setsockopt |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
89 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
90 memset(&hints, 0, sizeof hints); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
91 hints.ai_family = AF_UNSPEC; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
92 hints.ai_socktype = SOCK_STREAM; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
93 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
94 if (getaddrinfo(host, port, &hints, &server_infos) != 0) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
95 { perror("getaddrinfo"); return NULL; } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
96 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
97 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
98 if((socket_fd = socket(server_infos->ai_family, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
99 server_infos->ai_socktype, server_infos->ai_protocol)) == -1) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
100 { perror("socket"); return NULL; } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
101 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
102 if (connect(socket_fd, server_infos->ai_addr, server_infos->ai_addrlen) != 0) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
103 { perror("connect"); return NULL; } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
104 freeaddrinfo(server_infos); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
105 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
106 p_handle->socket = socket_fd; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
107 p_handle->type = SEOBEO_STREAM_TYPE_CLIENT; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
108 if (use_tls) |
| 17 | 109 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
110 printf("USE SSL\n\n"); |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
111 Seobeo_Web_SSL_Init(); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
112 p_handle->ssl_ctx = SSL_CTX_new(TLS_client_method()); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
113 SSL_CTX_set_default_verify_paths(p_handle->ssl_ctx); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
114 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
115 p_handle->ssl = SSL_new(p_handle->ssl_ctx); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
116 SSL_set_fd(p_handle->ssl, p_handle->socket); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
117 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
118 SSL_set_tlsext_host_name(p_handle->ssl, host); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
119 // Blocking for TSL handshake |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
120 fcntl(socket_fd, F_SETFL, 0); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
121 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
122 if (SSL_connect(p_handle->ssl) != 1) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
123 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
124 fprintf(stderr, "SSL_connect failed\n"); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
125 ERR_print_errors_fp(stderr); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
126 return NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
127 } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
128 }else |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
129 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
130 p_handle->ssl_ctx = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
131 p_handle->ssl = NULL; |
| 17 | 132 } |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
133 p_handle->connected = true; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
134 |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
135 p_handle->host = host != NULL ? strdup(host) : "localhost"; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
136 p_handle->port = strdup(port); |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
137 |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
138 p_handle->read_buffer = malloc(sizeof(*p_handle->read_buffer) * INITIAL_BUFFER_CAPACITY); |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
139 p_handle->read_buffer_capacity = INITIAL_BUFFER_CAPACITY; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
140 p_handle->read_buffer_len = 0; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
141 |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
142 p_handle->write_buffer = malloc(sizeof(*p_handle->read_buffer) * INITIAL_BUFFER_CAPACITY); |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
143 p_handle->write_buffer_capacity = INITIAL_BUFFER_CAPACITY; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
144 p_handle->write_buffer_len = 0; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
145 |
|
16
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
146 p_handle->destroyed = false; |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
147 |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
148 return p_handle; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
149 } |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
150 |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
151 Seobeo_PHandle Seobeo_Stream_Handle_Server_Accept(Seobeo_PHandle p_server_handle) |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
152 { |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
153 struct sockaddr_storage addr; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
154 socklen_t addrlen = sizeof addr; |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
155 char client_inet_addr[INET6_ADDRSTRLEN]; |
|
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.
MrJuneJune <me@mrjunejune.com>
parents:
22
diff
changeset
|
156 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
157 int client_fd = accept(p_server_handle->socket, |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
158 (struct sockaddr*)&addr, |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
159 &addrlen); |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
160 inet_ntop( |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
161 addr.ss_family, |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
162 Seobeo_Get_IP4_Or_IP6((struct sockaddr *)&addr), |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
163 client_inet_addr, sizeof client_inet_addr); |
|
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.
MrJuneJune <me@mrjunejune.com>
parents:
22
diff
changeset
|
164 if (client_fd == -1) return NULL; |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
165 |
|
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.
MrJuneJune <me@mrjunejune.com>
parents:
22
diff
changeset
|
166 // Set non blocking... |
|
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.
MrJuneJune <me@mrjunejune.com>
parents:
22
diff
changeset
|
167 int flags = fcntl(client_fd, F_GETFL, 0); |
|
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.
MrJuneJune <me@mrjunejune.com>
parents:
22
diff
changeset
|
168 if (flags == -1) return NULL; |
|
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.
MrJuneJune <me@mrjunejune.com>
parents:
22
diff
changeset
|
169 fcntl(client_fd, F_SETFL, flags | O_NONBLOCK); |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
170 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
171 Seobeo_PHandle p_client_handle = malloc(sizeof *p_client_handle); |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
172 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
173 p_client_handle->socket = client_fd; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
174 p_client_handle->type = SEOBEO_STREAM_TYPE_CLIENT; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
175 p_client_handle->connected = true; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
176 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
177 // TODO: support SSL in the future. |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
178 p_client_handle->ssl_ctx = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
179 p_client_handle->ssl = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
180 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
181 p_client_handle->host = strdup(client_inet_addr); |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
182 p_client_handle->port = NULL; |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
183 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
184 p_client_handle->read_buffer_capacity = p_server_handle->read_buffer_capacity; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
185 p_client_handle->read_buffer_len = 0; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
186 p_client_handle->read_buffer = malloc(p_client_handle->read_buffer_capacity); |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
187 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
188 p_client_handle->write_buffer_capacity = p_server_handle->write_buffer_capacity; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
189 p_client_handle->write_buffer_len = 0; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
190 p_client_handle->write_buffer = malloc(p_client_handle->write_buffer_capacity); |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
191 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
192 p_client_handle->read_buffer_used = 0; |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
193 p_client_handle->file = NULL; |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
194 p_client_handle->text_copy = NULL; |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
195 p_client_handle->file_name = NULL; |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
196 p_client_handle->destroyed = false; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
197 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
198 return p_client_handle; |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
199 } |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
200 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
201 void Seobeo_Handle_Destroy(Seobeo_PHandle p_handle) |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
202 { |
|
16
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
203 if (!p_handle) return; |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
204 |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
205 bool expected = false; |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
206 // Need to check |
|
16
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
207 if (!atomic_compare_exchange_strong(&p_handle->destroyed, &expected, true)) |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
208 { |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
209 return; |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
210 } |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
211 |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
212 if (p_handle->host) Dowa_Free(p_handle->host); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
213 if (p_handle->port) Dowa_Free(p_handle->port); |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
214 |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
215 if (p_handle->ssl) |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
216 { |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
217 SSL_shutdown(p_handle->ssl); |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
218 SSL_free(p_handle->ssl); |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
219 p_handle->ssl = NULL; |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
220 } |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
221 |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
222 if (p_handle->ssl_ctx) |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
223 { |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
224 SSL_CTX_free(p_handle->ssl_ctx); |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
225 p_handle->ssl_ctx = NULL; |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
226 } |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
227 |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
228 if (p_handle->socket) { |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
229 printf("Closing: %d", p_handle->socket); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
230 close(p_handle->socket); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
231 } |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
232 |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
233 if (p_handle->read_buffer) Dowa_Free(p_handle->read_buffer); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
234 if (p_handle->write_buffer) Dowa_Free(p_handle->write_buffer); |
|
16
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
235 |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
236 Dowa_Free(p_handle); |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
237 } |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
238 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
239 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
240 int32 Seobeo_Handle_Flush(Seobeo_PHandle p_handle) |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
241 { |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
242 uint32 total = p_handle->write_buffer_len; |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
243 uint32 sent = 0; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
244 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
245 printf("Total: %d\n\n", p_handle->write_buffer_len); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
246 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
247 while (sent < total) |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
248 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
249 if (p_handle->ssl) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
250 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
251 int n = SSL_write(p_handle->ssl, p_handle->write_buffer + sent, total - sent); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
252 if (n < 0) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
253 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
254 int err = SSL_get_error(p_handle->ssl, n); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
255 if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
256 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
257 // caller must wait for socket readiness and retry |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
258 return 0; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
259 } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
260 ERR_print_errors_fp(stderr); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
261 return -1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
262 } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
263 sent += (uint32)n; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
264 }else |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
265 { |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
266 printf("socket: %d\n", p_handle->socket); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
267 ssize_t n = write( |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
268 p_handle->socket, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
269 p_handle->write_buffer + sent, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
270 total - sent |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
271 ); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
272 if (n < 0) { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
273 if (errno == EINTR) continue; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
274 if (errno == EAGAIN) return 1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
275 return -1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
276 } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
277 sent += (uint32)n; |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
278 } |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
279 } |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
280 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
281 p_handle->write_buffer_len = 0; |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
282 return 0; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
283 } |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
284 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
285 int32 Seobeo_Handle_Queue(Seobeo_PHandle p_handle, const uint8 *data, uint32 data_size) |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
286 { |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
287 if (p_handle->write_buffer_len + data_size > p_handle->write_buffer_capacity) |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
288 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
289 int32 rc = Seobeo_Handle_Flush(p_handle); |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
290 if (rc < 0) return -1; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
291 if (rc > 0) return 1; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
292 } |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
293 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
294 if (data_size > p_handle->write_buffer_capacity) |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
295 { |
| 17 | 296 uint32 offset = 0; |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
297 while (offset < data_size) |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
298 { |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
299 ssize_t n = write(p_handle->socket, |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
300 data + offset, |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
301 data_size - offset); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
302 if (n==0) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
303 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
304 // DEBUG |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
305 printf("NONE %d\n", offset); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
306 break; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
307 } |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
308 if (n < 0) |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
309 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
310 if (errno == EINTR || errno == EAGAIN) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
311 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
312 // DEBUG |
|
22
947b81010aba
[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents:
19
diff
changeset
|
313 // printf("Partial write, returning early (offset=%d)\n", offset); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
314 continue; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
315 } |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
316 if (errno == EAGAIN) return 1; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
317 return -1; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
318 } |
| 17 | 319 offset += (uint32)n; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
320 // DEBUG |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
321 printf("\n\noffset: %d data_size: %d\n\n", offset, data_size); |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
322 } |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
323 // DEBUG |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
324 printf("\n\nTotal: %d\n", offset); |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
325 return 0; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
326 } |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
327 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
328 if (!p_handle) |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
329 { |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
330 printf("[ERROR] p_handle is NULL before memcpy\n"); |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
331 return -1; |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
332 } |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
333 |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
334 if (!p_handle->write_buffer) |
|
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
335 { |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
336 printf("[ERROR] p_handle->write_buffer is NULL (len=%zu, size=%zu)\n", |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
337 p_handle->write_buffer_len, data_size); |
|
62
ea9ef388ab97
[Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents:
36
diff
changeset
|
338 return -1; |
|
36
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
339 } |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
340 |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
341 printf("[DEBUG] memcpy -> dest=%p (write_buffer=%p + offset=%zu), src=%p, size=%zu\n", |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
342 p_handle->write_buffer + p_handle->write_buffer_len, |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
343 p_handle->write_buffer, |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
344 p_handle->write_buffer_len, |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
345 data, |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
346 data_size); |
|
84672efec192
[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
347 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
348 memcpy(p_handle->write_buffer + p_handle->write_buffer_len, |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
349 data, |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
350 data_size); |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
351 p_handle->write_buffer_len += data_size; |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
352 return 0; |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
353 } |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
354 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
355 int32 Seobeo_Handle_Read(Seobeo_PHandle p_handle) |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
356 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
357 int32 read_size; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
358 if (!p_handle) return -1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
359 |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
360 // How many bytes we can still read into the buffer |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
361 uint32 free_space = p_handle->read_buffer_capacity - p_handle->read_buffer_len; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
362 if (free_space == 0) |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
363 return -1; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
364 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
365 if (p_handle->ssl) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
366 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
367 read_size = (int32)SSL_read(p_handle->ssl, p_handle->read_buffer, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
368 free_space); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
369 if (read_size <= 0) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
370 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
371 int err = SSL_get_error(p_handle->ssl, read_size); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
372 switch (err) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
373 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
374 case SSL_ERROR_WANT_READ: |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
375 case SSL_ERROR_WANT_WRITE: |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
376 return 0; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
377 case SSL_ERROR_ZERO_RETURN: |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
378 default: |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
379 // TODO: Handle these errors |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
380 return -2; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
381 } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
382 } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
383 }else |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
384 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
385 read_size = (int32)read(p_handle->socket, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
386 p_handle->read_buffer + p_handle->read_buffer_len, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
387 free_space); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
388 if (read_size == 0) return -2; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
389 if (read_size < 0) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
390 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
391 if (errno == EAGAIN || errno == EWOULDBLOCK) return 0; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
392 return -1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
393 } |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
394 } |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
395 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
396 p_handle->read_buffer_len += (uint32)read_size; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
397 return read_size; |
|
6
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
398 } |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
399 |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
400 void Seobeo_Handle_Consume(Seobeo_PHandle p_handle, uint32 consumed) |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
401 { |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
402 if (consumed >= p_handle->read_buffer_len) |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
403 { |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
404 p_handle->read_buffer_len = 0; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
405 return; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
406 } |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
407 |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
408 // Slide remaining bytes to the front |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
409 memmove( |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
410 p_handle->read_buffer, |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
411 p_handle->read_buffer + consumed, |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
412 p_handle->read_buffer_len - consumed |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
413 ); |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
414 p_handle->read_buffer_len -= consumed; |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
415 } |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
416 |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
417 void *Seobeo_Get_IP4_Or_IP6(struct sockaddr *sa) |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
418 { |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
419 if (sa->sa_family == AF_INET) |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
420 { |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
421 return &(((struct sockaddr_in*)sa)->sin_addr); |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
422 } |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
423 |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
424 return &(((struct sockaddr_in6*)sa)->sin6_addr); |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
425 } |