Mercurial
annotate seobeo/s_network.c @ 253:fdf3816959cb
[ui] Add Sonner-like notification stack
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Tue, 04 Aug 2026 12:21:19 -0700 |
| parents | 117c4d53c9a4 |
| children | 609d3c6aff4e |
| 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 |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
3 static pthread_once_t g_sigpipe_once = PTHREAD_ONCE_INIT; |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
4 |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
5 static void Seobeo_Process_Ignore_Sigpipe(void) |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
6 { |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
7 signal(SIGPIPE, SIG_IGN); |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
8 } |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
9 |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
10 static void Seobeo_Socket_Disable_Sigpipe(int socket_fd) |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
11 { |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
12 #ifdef SO_NOSIGPIPE |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
13 int enabled = 1; |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
14 setsockopt(socket_fd, SOL_SOCKET, SO_NOSIGPIPE, &enabled, sizeof(enabled)); |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
15 #else |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
16 (void)socket_fd; |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
17 #endif |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
18 } |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
19 |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
20 static void Seobeo_Socket_Set_Close_On_Exec(int socket_fd) |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
21 { |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
22 int flags = fcntl(socket_fd, F_GETFD, 0); |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
23 if (flags >= 0) |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
24 fcntl(socket_fd, F_SETFD, flags | FD_CLOEXEC); |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
25 } |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
26 |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
27 static ssize_t Seobeo_Socket_Write( |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
28 int socket_fd, |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
29 const void *buffer, |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
30 size_t length) |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
31 { |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
32 #ifdef MSG_NOSIGNAL |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
33 return send(socket_fd, buffer, length, MSG_NOSIGNAL); |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
34 #else |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
35 return send(socket_fd, buffer, length, 0); |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
36 #endif |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
37 } |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
38 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
39 Seobeo_Handle *Seobeo_Stream_Handle_Server_Create(const char *host, const char* port) |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
40 { |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
41 pthread_once(&g_sigpipe_once, Seobeo_Process_Ignore_Sigpipe); |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
42 Seobeo_Handle *p_handle; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
43 struct addrinfo hints, *server_infos, *free_server_info; |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
44 int32 socket_fd = -1; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
45 int32 yes = 1; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
46 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
47 memset(&hints, 0, sizeof hints); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
48 hints.ai_family = AF_UNSPEC; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
49 hints.ai_socktype = SOCK_STREAM; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
50 hints.ai_protocol = IPPROTO_TCP; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
51 hints.ai_flags = AI_PASSIVE; |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
52 |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
53 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
|
54 { perror("getaddrinfo"); return NULL; } |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
55 |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
56 for |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
57 ( |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
58 free_server_info = server_infos; |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
59 free_server_info != NULL; |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
60 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
|
61 ) |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
62 { |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
63 int socket_type = free_server_info->ai_socktype; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
64 #ifdef SOCK_CLOEXEC |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
65 socket_type |= SOCK_CLOEXEC; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
66 #endif |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
67 if((socket_fd = socket(free_server_info->ai_family, |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
68 socket_type, free_server_info->ai_protocol)) == -1) |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
69 { perror("socket"); continue; } |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
70 Seobeo_Socket_Set_Close_On_Exec(socket_fd); |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
71 Seobeo_Socket_Disable_Sigpipe(socket_fd); |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
72 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
73 if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
74 { |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
75 perror("setsockopt SO_REUSEADDR"); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
76 close(socket_fd); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
77 socket_fd = -1; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
78 continue; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
79 } |
|
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
|
80 |
|
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
|
81 #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
|
82 // 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
|
83 // 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
|
84 if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) == -1) |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
85 { |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
86 perror("setsockopt SO_REUSEPORT"); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
87 close(socket_fd); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
88 socket_fd = -1; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
89 continue; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
90 } |
|
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
|
91 #endif |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
92 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
93 if (bind(socket_fd, free_server_info->ai_addr, free_server_info->ai_addrlen) == -1) |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
94 { |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
95 perror("bind"); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
96 close(socket_fd); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
97 socket_fd = -1; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
98 continue; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
99 } |
| 17 | 100 |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
101 break; |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
102 } |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
103 freeaddrinfo(server_infos); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
104 |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
105 if (socket_fd < 0) |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
106 return NULL; |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
107 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
108 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
|
109 { |
| 96 | 110 Seobeo_Log(SEOBEO_DEBUG, "Closing socket: %d\n", socket_fd); |
|
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
|
111 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
|
112 } |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
113 |
|
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
|
114 int flags = fcntl(socket_fd, F_GETFL, 0); |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
115 if (flags < 0 || |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
116 fcntl(socket_fd, F_SETFL, flags | O_NONBLOCK) != 0) |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
117 { |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
118 perror("fcntl"); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
119 close(socket_fd); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
120 return NULL; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
121 } |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
122 |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
123 p_handle = calloc(1, sizeof(*p_handle)); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
124 if (!p_handle) |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
125 { |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
126 close(socket_fd); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
127 return NULL; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
128 } |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
129 p_handle->socket = socket_fd; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
130 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
|
131 p_handle->connected = FALSE; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
132 |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
133 p_handle->host = strdup(host != NULL ? host : "localhost"); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
134 p_handle->port = strdup(port); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
135 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
136 p_handle->ssl_ctx = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
137 p_handle->ssl = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
138 |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
139 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
144 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
|
145 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
|
146 p_handle->write_buffer_len = 0; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
147 |
| 96 | 148 p_handle->destroyed = FALSE; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
149 |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
150 if (!p_handle->host || |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
151 !p_handle->port || |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
152 !p_handle->read_buffer || |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
153 !p_handle->write_buffer) |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
154 { |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
155 Seobeo_Handle_Destroy(p_handle); |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
156 return NULL; |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
157 } |
|
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
158 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
159 return p_handle; |
|
1
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
160 } |
|
adcfad6e86fb
Updated naming and separated out some logic within seobeo.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
161 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
162 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
163 Seobeo_Handle *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
|
164 { |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
165 pthread_once(&g_sigpipe_once, Seobeo_Process_Ignore_Sigpipe); |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
166 Seobeo_Handle *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
|
167 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
|
168 |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
169 struct addrinfo hints, *server_infos; |
|
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
170 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
|
171 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
172 memset(&hints, 0, sizeof hints); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
173 hints.ai_family = AF_UNSPEC; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
174 hints.ai_socktype = SOCK_STREAM; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
175 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
176 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
|
177 { perror("getaddrinfo"); return NULL; } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
178 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
179 |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
180 int socket_type = server_infos->ai_socktype; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
181 #ifdef SOCK_CLOEXEC |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
182 socket_type |= SOCK_CLOEXEC; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
183 #endif |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
184 if((socket_fd = socket(server_infos->ai_family, |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
185 socket_type, server_infos->ai_protocol)) == -1) |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
186 { perror("socket"); return NULL; } |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
187 Seobeo_Socket_Set_Close_On_Exec(socket_fd); |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
188 Seobeo_Socket_Disable_Sigpipe(socket_fd); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
189 |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
190 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
|
191 { perror("connect"); return NULL; } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
192 freeaddrinfo(server_infos); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
193 |
|
128
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
194 // Set non-blocking |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
195 int flags = fcntl(socket_fd, F_GETFL, 0); |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
196 if (flags == -1 || fcntl(socket_fd, F_SETFL, flags | O_NONBLOCK) != 0) |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
197 { perror("fcntl"); close(socket_fd); free(p_handle); return NULL; } |
|
7eb79fd91c7e
[Misc] Fixed all bazel targets. I should creat a separate scripts for these lol.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
198 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
199 p_handle->socket = socket_fd; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
200 p_handle->type = SEOBEO_STREAM_TYPE_CLIENT; |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
201 |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
202 p_handle->ssl_ctx = NULL; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
203 p_handle->ssl = NULL; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
204 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
205 if (use_tls) |
| 17 | 206 { |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
207 if (Seobeo_SSL_Setup_Client(p_handle, host, socket_fd) != 0) |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
208 { |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
209 free(p_handle); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
210 return NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
211 } |
| 17 | 212 } |
| 96 | 213 p_handle->connected = TRUE; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
214 |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
215 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
|
216 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
|
217 |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 |
| 96 | 226 p_handle->destroyed = FALSE; |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
227 |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
228 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
|
229 } |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
230 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
231 Seobeo_Handle *Seobeo_Stream_Handle_Server_Accept(Seobeo_Handle *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
|
232 { |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
237 int client_fd = accept( |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
238 p_server_handle->socket, |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
239 (struct sockaddr*)&addr, |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
240 &addrlen); |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
241 inet_ntop( |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
242 addr.ss_family, |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
243 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
|
244 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
|
245 if (client_fd == -1) return NULL; |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
223
diff
changeset
|
246 Seobeo_Socket_Set_Close_On_Exec(client_fd); |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
247 Seobeo_Socket_Disable_Sigpipe(client_fd); |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
248 |
|
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
|
249 // 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
|
250 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
|
251 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
|
252 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
|
253 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
254 Seobeo_Handle *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
|
255 |
|
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
|
256 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
|
257 p_client_handle->type = SEOBEO_STREAM_TYPE_CLIENT; |
| 96 | 258 p_client_handle->connected = TRUE; |
|
18
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 // TODO: support SSL in the future. |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
261 p_client_handle->ssl_ctx = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
262 p_client_handle->ssl = NULL; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
263 |
|
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
|
264 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
|
265 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
|
266 |
|
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
|
267 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
|
268 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
|
269 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
|
270 |
|
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
|
271 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
|
272 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
|
273 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
|
274 |
|
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
|
275 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
|
276 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
|
277 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
|
278 p_client_handle->file_name = NULL; |
| 96 | 279 p_client_handle->destroyed = FALSE; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
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 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
|
282 } |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
283 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
284 void Seobeo_Handle_Destroy(Seobeo_Handle *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
|
285 { |
|
16
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
286 if (!p_handle) return; |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
287 |
| 96 | 288 boolean 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
|
289 // Need to check |
| 96 | 290 if (!atomic_compare_exchange_strong(&p_handle->destroyed, &expected, TRUE)) |
|
16
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
291 { |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
292 return; |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
293 } |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
6
diff
changeset
|
294 |
|
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
|
295 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
|
296 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
|
297 |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
298 Seobeo_SSL_Cleanup(p_handle); |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
299 |
|
251
117c4d53c9a4
[ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents:
244
diff
changeset
|
300 if (p_handle->socket >= 0) { |
| 96 | 301 Seobeo_Log(SEOBEO_DEBUG, "Closing handle socket: %d\n", p_handle->socket); |
|
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
|
302 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
|
303 } |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
304 |
|
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
|
305 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
|
306 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
|
307 |
|
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
|
308 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
|
309 } |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
310 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
311 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
312 int32 Seobeo_Handle_Flush(Seobeo_Handle *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
|
313 { |
|
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
|
314 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
|
315 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
|
316 |
| 96 | 317 Seobeo_Log(SEOBEO_DEBUG, "Write buffer total: %d\n", p_handle->write_buffer_len); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
318 |
|
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
|
319 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
|
320 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
321 if (p_handle->ssl) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
322 { |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
323 int n = Seobeo_SSL_Write(p_handle, p_handle->write_buffer + sent, total - sent); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
324 if (n < 0) return -1; |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
325 if (n == 0) return 0; // would block |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
326 sent += (uint32)n; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
327 }else |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
328 { |
| 96 | 329 Seobeo_Log(SEOBEO_DEBUG, "Flushing socket: %d\n", p_handle->socket); |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
330 ssize_t n = Seobeo_Socket_Write( |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
331 p_handle->socket, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
332 p_handle->write_buffer + sent, |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
333 total - sent |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
334 ); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
335 if (n < 0) { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
336 if (errno == EINTR) continue; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
337 if (errno == EAGAIN) return 1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
338 return -1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
339 } |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
340 sent += (uint32)n; |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
341 } |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
342 } |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
343 |
|
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
|
344 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
|
345 return 0; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
346 } |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
347 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
348 int32 Seobeo_Handle_Queue(Seobeo_Handle *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
|
349 { |
|
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
|
350 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
|
351 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 } |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
356 |
|
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
|
357 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
|
358 { |
| 17 | 359 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
|
360 while (offset < data_size) |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
361 { |
|
206
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
362 ssize_t n; |
|
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
363 if (p_handle->ssl) |
|
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
364 { |
|
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
365 n = Seobeo_SSL_Write(p_handle, data + offset, data_size - offset); |
|
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
366 } |
|
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
367 else |
|
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
368 { |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
369 n = Seobeo_Socket_Write( |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
370 p_handle->socket, |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
371 data + offset, |
|
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
206
diff
changeset
|
372 data_size - offset); |
|
206
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
373 } |
|
240337164a80
[Seobeo] SSL should be used for large file as well lol.
MrJuneJune <me@mrjunejune.com>
parents:
144
diff
changeset
|
374 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
375 if (n==0) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
376 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
377 // DEBUG |
| 96 | 378 Seobeo_Log(SEOBEO_DEBUG, "Write offset: %d\n", offset); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
379 break; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
380 } |
|
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
|
381 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
|
382 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
383 if (errno == EINTR || errno == EAGAIN) |
|
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 // 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
|
386 // 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
|
387 continue; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
388 } |
|
4
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
389 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
|
390 return -1; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
391 } |
| 17 | 392 offset += (uint32)n; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
393 // DEBUG |
| 96 | 394 Seobeo_Log(SEOBEO_DEBUG, "Write completed - offset: %d, data_size: %d\n", offset, data_size); |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
395 } |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
396 // DEBUG |
| 96 | 397 Seobeo_Log(SEOBEO_DEBUG, "Total bytes written: %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
|
398 return 0; |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
399 } |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
400 |
|
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
|
401 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
|
402 { |
| 96 | 403 Seobeo_Log(SEOBEO_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
|
404 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
|
405 } |
|
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
|
406 |
|
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
|
407 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
|
408 { |
| 96 | 409 Seobeo_Log(SEOBEO_ERROR, "p_handle->write_buffer is NULL (len=%u, size=%u)\n", |
|
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
|
410 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
|
411 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
|
412 } |
|
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
|
413 |
| 96 | 414 Seobeo_Log(SEOBEO_DEBUG, "memcpy -> dest=%p (write_buffer=%p + offset=%u), src=%p, size=%u\n", |
|
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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 data, |
|
0b3b4f5887bb
[Seobeo] Updated so that it create socket for both server and clients.
June Park <parkjune1995@gmail.com>
parents:
3
diff
changeset
|
422 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
|
423 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
|
424 return 0; |
|
3
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
425 } |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
426 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
427 int32 Seobeo_Handle_Read(Seobeo_Handle *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
|
428 { |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
429 int32 read_size; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
430 if (!p_handle) return -1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
431 |
|
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
|
432 // 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
|
433 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
|
434 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
|
435 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
|
436 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
437 if (p_handle->ssl) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
438 { |
|
67
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
439 read_size = Seobeo_SSL_Read(p_handle, p_handle->read_buffer + p_handle->read_buffer_len, free_space); |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
440 if (read_size < 0) return read_size; // -1 for error, -2 for closed |
|
6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents:
66
diff
changeset
|
441 if (read_size == 0) return 0; // would block |
|
71
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
442 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
443 else |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
444 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
445 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
|
446 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
|
447 free_space); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
448 if (read_size == 0) return -2; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
449 if (read_size < 0) |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
450 { |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
451 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
|
452 return -1; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
453 } |
|
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
|
454 } |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
455 |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
456 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
|
457 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
|
458 } |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
459 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
62
diff
changeset
|
460 void Seobeo_Handle_Consume(Seobeo_Handle *p_handle, uint32 consumed) |
|
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
|
461 { |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
462 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
|
463 { |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
464 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
|
465 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
|
466 } |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
467 |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
468 // 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 ); |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
474 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
|
475 } |
|
1e61008b9980
[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
June Park <parkjune1995@gmail.com>
parents:
4
diff
changeset
|
476 |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
477 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
|
478 { |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
479 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
|
480 { |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
481 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
|
482 } |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
483 |
|
2758f5527d2b
[Seobeo] Working on simple TCP server and client logic.
June Park <parkjune1995@gmail.com>
parents:
1
diff
changeset
|
484 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
|
485 } |