Debian Codegraph @

src/net.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2013-2022 Joris Vink <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/param.h>
18 #include <sys/socket.h>
19 #include <sys/types.h>
20
21 #if defined(__linux__cxx . . $ `<built-in>:401:9`!)
22 #include <endian.h>
23 #elif defined(__MACH__)
24 #include <libkern/OSByteOrder.h>
25 #define htobe64(x) OSSwapHostToBigInt64(x)
26 #define be64toh(x) OSSwapBigToHostInt64(x)
27 #else
28 #include <sys/endian.h>
29 #endif
30
31 #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/
32
33 struct kore_poolcxx . . $ kore_pool# nb_poolcxx . . $ nb_pool.;
34
35 void
36 net_initcxx . . $ net_init(49f6e7a06ebc5aa8).(void)
37 {
38 u_int32_tcxx . . $ u_int32_t# elm;
39
40 /* Add some overhead so we don't roll over for internal items. */
41 elm = worker_max_connectionscxx . . $ worker_max_connections. + 10;
42 kore_pool_initcxx . . $ kore_pool_init(19b74537ff42c712).(&nb_poolcxx . . $ nb_pool., "nb_pool", sizeof(struct netbufcxx . . $ netbuf#), elm);
43 }
44
45 void
46 net_cleanupcxx . . $ net_cleanup(49f6e7a06ebc5aa8).(void)
47 {
48 kore_pool_cleanupcxx . . $ kore_pool_cleanup(68cee620b8bd445e).(&nb_poolcxx . . $ nb_pool.);
49 }
50
51 struct netbufcxx . . $ netbuf# *
52 net_netbuf_getcxx . . $ net_netbuf_get(ed56b596e63d2b00).(void)
53 {
54 struct netbufcxx . . $ netbuf# *nb;
55
56 nb = kore_pool_getcxx . . $ kore_pool_get(f5c578167d321b17).(&nb_poolcxx . . $ nb_pool.);
57
58 nb->cbcxx . . $ netbuf#cb. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
59 nb->bufcxx . . $ netbuf#buf. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
60 nb->ownercxx . . $ netbuf#owner. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
61 nb->extracxx . . $ netbuf#extra. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
62 nb->file_refcxx . . $ netbuf#file_ref. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
63
64 nb->typecxx . . $ netbuf#type. = 0;
65 nb->s_offcxx . . $ netbuf#s_off. = 0;
66 nb->b_lencxx . . $ netbuf#b_len. = 0;
67 nb->m_lencxx . . $ netbuf#m_len. = 0;
68 nb->flagscxx . . $ netbuf#flags. = 0;
69
70 #if defined(KORE_USE_PLATFORM_SENDFILEcxx . . $ `include/kore/kore.h:56:9`!)
71 nb->fd_offcxx . . $ netbuf#fd_off. = -1;
72 nb->fd_lencxx . . $ netbuf#fd_len. = -1;
73 #endif
74
75 return (nb);
76 }
77
78 void
79 net_send_queuecxx . . $ net_send_queue(afc888e1ea7fb691).(struct connectioncxx . . $ connection# *c, const void *data, size_t len)
80 {
81 const u_int8_tcxx . . $ u_int8_t# *d;
82 struct netbufcxx . . $ netbuf# *nb;
83 size_t avail;
84
85 d = data;
86 nb = TAILQ_LASTcxx . . $ `<external>/2546723208511035544/queue.h:461:9`!(&(c->send_queue), netbuf_head);
87 if (nb != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && !(nb->flagscxx . . $ netbuf#flags. & NETBUF_IS_STREAMcxx . . $ `include/kore/kore.h:118:9`!) &&
88 nb->b_lencxx . . $ netbuf#b_len. < nb->m_lencxx . . $ netbuf#m_len.) {
89 avail = nb->m_lencxx . . $ netbuf#m_len. - nb->b_lencxx . . $ netbuf#b_len.;
90 if (len < avail) {
91 memcpycxx . . $ memcpy(cc817cb175f282d).(nb->bufcxx . . $ netbuf#buf. + nb->b_lencxx . . $ netbuf#b_len., d, len);
92 nb->b_lencxx . . $ netbuf#b_len. += len;
93 return;
94 } else {
95 memcpycxx . . $ memcpy(cc817cb175f282d).(nb->bufcxx . . $ netbuf#buf. + nb->b_lencxx . . $ netbuf#b_len., d, avail);
96 nb->b_lencxx . . $ netbuf#b_len. += avail;
97
98 len -= avail;
99 d += avail;
100 if (len == 0)
101 return;
102 }
103 }
104
105 nb = net_netbuf_getcxx . . $ net_netbuf_get(ed56b596e63d2b00).();
106
107 nb->ownercxx . . $ netbuf#owner. = c;
108 nb->b_lencxx . . $ netbuf#b_len. = len;
109 nb->typecxx . . $ netbuf#type. = NETBUF_SENDcxx . . $ `include/kore/kore.h:108:9`!;
110
111 if (nb->b_lencxx . . $ netbuf#b_len. < NETBUF_SEND_PAYLOAD_MAXcxx . . $ `include/kore/kore.h:109:9`!)
112 nb->m_lencxx . . $ netbuf#m_len. = NETBUF_SEND_PAYLOAD_MAXcxx . . $ `include/kore/kore.h:109:9`!;
113 else
114 nb->m_lencxx . . $ netbuf#m_len. = nb->b_lencxx . . $ netbuf#b_len.;
115
116 nb->bufcxx . . $ netbuf#buf. = kore_malloccxx . . $ kore_malloc(bfcfa4d6b7f7ef64).(nb->m_lencxx . . $ netbuf#m_len.);
117 memcpycxx . . $ memcpy(cc817cb175f282d).(nb->bufcxx . . $ netbuf#buf., d, nb->b_lencxx . . $ netbuf#b_len.);
118
119 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&(c->send_queue), nb, list);
120 }
121
122 void
123 net_send_streamcxx . . $ net_send_stream(d6d8aac503cfaaf3).(struct connectioncxx . . $ connection# *c, void *data, size_t len,
124 int (*cb)(struct netbufcxx . . $ netbuf# *), struct netbufcxx . . $ netbuf# **out)
125 {
126 struct netbufcxx . . $ netbuf# *nb;
127
128 nb = net_netbuf_getcxx . . $ net_netbuf_get(ed56b596e63d2b00).();
129 nb->cbcxx . . $ netbuf#cb. = cb;
130 nb->ownercxx . . $ netbuf#owner. = c;
131 nb->bufcxx . . $ netbuf#buf. = data;
132 nb->b_lencxx . . $ netbuf#b_len. = len;
133 nb->m_lencxx . . $ netbuf#m_len. = nb->b_lencxx . . $ netbuf#b_len.;
134 nb->typecxx . . $ netbuf#type. = NETBUF_SENDcxx . . $ `include/kore/kore.h:108:9`!;
135 nb->flagscxx . . $ netbuf#flags. = NETBUF_IS_STREAMcxx . . $ `include/kore/kore.h:118:9`!;
136
137 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&(c->send_queue), nb, list);
138
139 if (out != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
140 *out = nb;
141 }
142
143 void
144 net_send_filerefcxx . . $ net_send_fileref(ae27ba2f4cacc904).(struct connectioncxx . . $ connection# *c, struct kore_filerefcxx . . $ kore_fileref# *ref)
145 {
146 struct netbufcxx . . $ netbuf# *nb;
147
148 nb = net_netbuf_getcxx . . $ net_netbuf_get(ed56b596e63d2b00).();
149 nb->ownercxx . . $ netbuf#owner. = c;
150 nb->file_refcxx . . $ netbuf#file_ref. = ref;
151 nb->typecxx . . $ netbuf#type. = NETBUF_SENDcxx . . $ `include/kore/kore.h:108:9`!;
152 nb->flagscxx . . $ netbuf#flags. = NETBUF_IS_FILEREFcxx . . $ `include/kore/kore.h:119:9`!;
153
154 #if defined(KORE_USE_PLATFORM_SENDFILEcxx . . $ `include/kore/kore.h:56:9`!)
155 if (c->ownercxx . . $ connection#owner.->servercxx . . $ listener#server.->tlscxx . . $ kore_server#tls. == 0) {
156 nb->fd_offcxx . . $ netbuf#fd_off. = 0;
157 nb->fd_lencxx . . $ netbuf#fd_len. = ref->sizecxx . . $ kore_fileref#size.;
158 } else {
159 nb->bufcxx . . $ netbuf#buf. = ref->basecxx . . $ kore_fileref#base.;
160 nb->b_lencxx . . $ netbuf#b_len. = ref->sizecxx . . $ kore_fileref#size.;
161 nb->m_lencxx . . $ netbuf#m_len. = nb->b_lencxx . . $ netbuf#b_len.;
162 nb->flagscxx . . $ netbuf#flags. |= NETBUF_IS_STREAMcxx . . $ `include/kore/kore.h:118:9`!;
163 }
164 #else
165 nb->buf = ref->base;
166 nb->b_len = ref->size;
167 nb->m_len = nb->b_len;
168 nb->flags |= NETBUF_IS_STREAM;
169 #endif
170
171 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&(c->send_queue), nb, list);
172 }
173
174 void
175 net_recv_resetcxx . . $ net_recv_reset(174c4f3588921332).(struct connectioncxx . . $ connection# *c, size_t len, int (*cb)(struct netbufcxx . . $ netbuf# *))
176 {
177 c->rnbcxx . . $ connection#rnb.->cbcxx . . $ netbuf#cb. = cb;
178 c->rnbcxx . . $ connection#rnb.->s_offcxx . . $ netbuf#s_off. = 0;
179 c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len. = len;
180
181 if (c->rnbcxx . . $ connection#rnb.->bufcxx . . $ netbuf#buf. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len. <= c->rnbcxx . . $ connection#rnb.->m_lencxx . . $ netbuf#m_len. &&
182 c->rnbcxx . . $ connection#rnb.->m_lencxx . . $ netbuf#m_len. < (NETBUF_SEND_PAYLOAD_MAXcxx . . $ `include/kore/kore.h:109:9`! / 2))
183 return;
184
185 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(c->rnbcxx . . $ connection#rnb.->bufcxx . . $ netbuf#buf.);
186 c->rnbcxx . . $ connection#rnb.->m_lencxx . . $ netbuf#m_len. = len;
187 c->rnbcxx . . $ connection#rnb.->bufcxx . . $ netbuf#buf. = kore_malloccxx . . $ kore_malloc(bfcfa4d6b7f7ef64).(c->rnbcxx . . $ connection#rnb.->m_lencxx . . $ netbuf#m_len.);
188 }
189
190 void
191 net_recv_queuecxx . . $ net_recv_queue(8cd27e823268687f).(struct connectioncxx . . $ connection# *c, size_t len, int flags,
192 int (*cb)(struct netbufcxx . . $ netbuf# *))
193 {
194 if (c->rnbcxx . . $ connection#rnb. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
195 fatalcxx . . $ fatal(f6bc48f0426f26ee).("net_recv_queue(): called incorrectly");
196
197 c->rnbcxx . . $ connection#rnb. = net_netbuf_getcxx . . $ net_netbuf_get(ed56b596e63d2b00).();
198 c->rnbcxx . . $ connection#rnb.->cbcxx . . $ netbuf#cb. = cb;
199 c->rnbcxx . . $ connection#rnb.->ownercxx . . $ netbuf#owner. = c;
200 c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len. = len;
201 c->rnbcxx . . $ connection#rnb.->m_lencxx . . $ netbuf#m_len. = len;
202 c->rnbcxx . . $ connection#rnb.->flagscxx . . $ netbuf#flags. = flags;
203 c->rnbcxx . . $ connection#rnb.->typecxx . . $ netbuf#type. = NETBUF_RECVcxx . . $ `include/kore/kore.h:107:9`!;
204 c->rnbcxx . . $ connection#rnb.->bufcxx . . $ netbuf#buf. = kore_malloccxx . . $ kore_malloc(bfcfa4d6b7f7ef64).(c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len.);
205 }
206
207 void
208 net_recv_expandcxx . . $ net_recv_expand(174c4f3588921332).(struct connectioncxx . . $ connection# *c, size_t len, int (*cb)(struct netbufcxx . . $ netbuf# *))
209 {
210 c->rnbcxx . . $ connection#rnb.->cbcxx . . $ netbuf#cb. = cb;
211 c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len. += len;
212 c->rnbcxx . . $ connection#rnb.->m_lencxx . . $ netbuf#m_len. = c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len.;
213 c->rnbcxx . . $ connection#rnb.->bufcxx . . $ netbuf#buf. = kore_realloccxx . . $ kore_realloc(417ab160f6baadc6).(c->rnbcxx . . $ connection#rnb.->bufcxx . . $ netbuf#buf., c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len.);
214 }
215
216 int
217 net_sendcxx . . $ net_send(d3ce87d3c6fa6963).(struct connectioncxx . . $ connection# *c)
218 {
219 size_t r, len, smin;
220
221 c->snbcxx . . $ connection#snb. = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&(c->send_queue));
222
223 #if defined(KORE_USE_PLATFORM_SENDFILEcxx . . $ `include/kore/kore.h:56:9`!)
224 if ((c->snbcxx . . $ connection#snb.->flagscxx . . $ netbuf#flags. & NETBUF_IS_FILEREFcxx . . $ `include/kore/kore.h:119:9`!) &&
225 !(c->snbcxx . . $ connection#snb.->flagscxx . . $ netbuf#flags. & NETBUF_IS_STREAMcxx . . $ `include/kore/kore.h:118:9`!)) {
226 return (kore_platform_sendfilecxx . . $ kore_platform_sendfile(aa82428a214d4f3b).(c, c->snbcxx . . $ connection#snb.));
227 }
228 #endif
229
230 if (c->snbcxx . . $ connection#snb.->b_lencxx . . $ netbuf#b_len. != 0) {
231 smin = c->snbcxx . . $ connection#snb.->b_lencxx . . $ netbuf#b_len. - c->snbcxx . . $ connection#snb.->s_offcxx . . $ netbuf#s_off.;
232 len = MINcxx . . $ `<external>/1231830743887005719/param.h:102:9`!(NETBUF_SEND_PAYLOAD_MAXcxx . . $ `include/kore/kore.h:109:9`!, smin);
233
234 if (!c->writecxx . . $ connection#write.(c, len, &r))
235 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
236 if (!(c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. & KORE_EVENT_WRITEcxx . . $ `include/kore/kore.h:188:9`!))
237 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
238
239 c->snbcxx . . $ connection#snb.->s_offcxx . . $ netbuf#s_off. += r;
240 c->snbcxx . . $ connection#snb.->flagscxx . . $ netbuf#flags. &= ~NETBUF_MUST_RESENDcxx . . $ `include/kore/kore.h:117:9`!;
241 }
242
243 if (c->snbcxx . . $ connection#snb.->s_offcxx . . $ netbuf#s_off. == c->snbcxx . . $ connection#snb.->b_lencxx . . $ netbuf#b_len. ||
244 (c->snbcxx . . $ connection#snb.->flagscxx . . $ netbuf#flags. & NETBUF_FORCE_REMOVEcxx . . $ `include/kore/kore.h:116:9`!)) {
245 net_remove_netbufcxx . . $ net_remove_netbuf(59f25c31eed43fe1).(c, c->snbcxx . . $ connection#snb.);
246 c->snbcxx . . $ connection#snb. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
247 }
248
249 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
250 }
251
252 int
253 net_send_flushcxx . . $ net_send_flush(d3ce87d3c6fa6963).(struct connectioncxx . . $ connection# *c)
254 {
255 while (!TAILQ_EMPTYcxx . . $ `<external>/2546723208511035544/queue.h:457:9`!(&(c->send_queue)) &&
256 (c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. & KORE_EVENT_WRITEcxx . . $ `include/kore/kore.h:188:9`!)) {
257 if (!net_sendcxx . . $ net_send(d3ce87d3c6fa6963).(c))
258 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
259 }
260
261 if ((c->flagscxx . . $ connection#flags. & CONN_CLOSE_EMPTYcxx . . $ `include/kore/kore.h:192:9`!) && TAILQ_EMPTYcxx . . $ `<external>/2546723208511035544/queue.h:457:9`!(&(c->send_queue))) {
262 kore_connection_disconnectcxx . . $ kore_connection_disconnect(8475afdb72fd1ebb).(c);
263 }
264
265 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
266 }
267
268 int
269 net_recv_flushcxx . . $ net_recv_flush(d3ce87d3c6fa6963).(struct connectioncxx . . $ connection# *c)
270 {
271 size_t r;
272
273 if (c->rnbcxx . . $ connection#rnb. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
274 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
275
276 while (c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. & KORE_EVENT_READcxx . . $ `include/kore/kore.h:187:9`!) {
277 if (c->rnbcxx . . $ connection#rnb.->bufcxx . . $ netbuf#buf. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
278 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
279
280 if ((c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len. - c->rnbcxx . . $ connection#rnb.->s_offcxx . . $ netbuf#s_off.) == 0)
281 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
282
283 if (!c->readcxx . . $ connection#read.(c, &r))
284 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
285 if (!(c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. & KORE_EVENT_READcxx . . $ `include/kore/kore.h:187:9`!))
286 break;
287
288 c->rnbcxx . . $ connection#rnb.->s_offcxx . . $ netbuf#s_off. += r;
289 if (c->rnbcxx . . $ connection#rnb.->s_offcxx . . $ netbuf#s_off. == c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len. ||
290 (c->rnbcxx . . $ connection#rnb.->flagscxx . . $ netbuf#flags. & NETBUF_CALL_CB_ALWAYScxx . . $ `include/kore/kore.h:115:9`!)) {
291 r = c->rnbcxx . . $ connection#rnb.->cbcxx . . $ netbuf#cb.(c->rnbcxx . . $ connection#rnb.);
292 if (r != KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!)
293 return (r);
294 }
295 }
296
297 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
298 }
299
300 void
301 net_remove_netbufcxx . . $ net_remove_netbuf(59f25c31eed43fe1).(struct connectioncxx . . $ connection# *c, struct netbufcxx . . $ netbuf# *nb)
302 {
303 if (nb->typecxx . . $ netbuf#type. == NETBUF_RECVcxx . . $ `include/kore/kore.h:107:9`!)
304 fatalcxx . . $ fatal(f6bc48f0426f26ee).("net_remove_netbuf(): cannot remove recv netbuf");
305
306 if (nb->flagscxx . . $ netbuf#flags. & NETBUF_MUST_RESENDcxx . . $ `include/kore/kore.h:117:9`!) {
307 nb->flagscxx . . $ netbuf#flags. |= NETBUF_FORCE_REMOVEcxx . . $ `include/kore/kore.h:116:9`!;
308 return;
309 }
310
311 if (!(nb->flagscxx . . $ netbuf#flags. & NETBUF_IS_STREAMcxx . . $ `include/kore/kore.h:118:9`!)) {
312 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(nb->bufcxx . . $ netbuf#buf.);
313 } else if (nb->cbcxx . . $ netbuf#cb. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
314 (void)nb->cbcxx . . $ netbuf#cb.(nb);
315 }
316
317 if (nb->flagscxx . . $ netbuf#flags. & NETBUF_IS_FILEREFcxx . . $ `include/kore/kore.h:119:9`!)
318 kore_fileref_releasecxx . . $ kore_fileref_release(6512ee26e70dae5b).(nb->file_refcxx . . $ netbuf#file_ref.);
319
320 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&(c->send_queue), nb, list);
321
322 kore_pool_putcxx . . $ kore_pool_put(d9a47b307a51c9d5).(&nb_poolcxx . . $ nb_pool., nb);
323 }
324
325 int
326 net_writecxx . . $ net_write(6baa9a301ab1221c).(struct connectioncxx . . $ connection# *c, size_t len, size_t *written)
327 {
328 ssize_tcxx . . $ ssize_t# r;
329
330 r = sendcxx . . $ send(4e364047dcdcb5ca).(c->fdcxx . . $ connection#fd., (c->snbcxx . . $ connection#snb.->bufcxx . . $ netbuf#buf. + c->snbcxx . . $ connection#snb.->s_offcxx . . $ netbuf#s_off.), len, 0);
331 if (r == -1) {
332 switch (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) {
333 case EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!:
334 *written = 0;
335 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
336 case EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!:
337 c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. &= ~KORE_EVENT_WRITEcxx . . $ `include/kore/kore.h:188:9`!;
338 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
339 default:
340 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
341 }
342 }
343
344 *written = (size_t)r;
345
346 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
347 }
348
349 int
350 net_readcxx . . $ net_read(6a0a663d3dbc77f8).(struct connectioncxx . . $ connection# *c, size_t *bytes)
351 {
352 ssize_tcxx . . $ ssize_t# r;
353
354 r = recvcxx . . $ recv(4136b1fcb15a75da).(c->fdcxx . . $ connection#fd., (c->rnbcxx . . $ connection#rnb.->bufcxx . . $ netbuf#buf. + c->rnbcxx . . $ connection#rnb.->s_offcxx . . $ netbuf#s_off.),
355 (c->rnbcxx . . $ connection#rnb.->b_lencxx . . $ netbuf#b_len. - c->rnbcxx . . $ connection#rnb.->s_offcxx . . $ netbuf#s_off.), 0);
356 if (r == -1) {
357 switch (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) {
358 case EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!:
359 *bytes = 0;
360 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
361 case EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!:
362 c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. &= ~KORE_EVENT_READcxx . . $ `include/kore/kore.h:187:9`!;
363 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
364 default:
365 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
366 }
367 }
368
369 if (r == 0) {
370 kore_connection_disconnectcxx . . $ kore_connection_disconnect(8475afdb72fd1ebb).(c);
371 c->evtcxx . . $ connection#evt..flagscxx . . $ kore_event#flags. &= ~KORE_EVENT_READcxx . . $ `include/kore/kore.h:187:9`!;
372 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
373 }
374
375 *bytes = (size_t)r;
376
377 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
378 }
379
380 u_int16_tcxx . . $ u_int16_t#
381 net_read16cxx . . $ net_read16(e56f59a1c9f445b3).(u_int8_tcxx . . $ u_int8_t# *b)
382 {
383 u_int16_tcxx . . $ u_int16_t# r;
384
385 r = *(u_int16_tcxx . . $ u_int16_t# *)b;
386 return (ntohscxx . . $ `<external>/9581057695539925927/in.h:429:12`!(r));
387 }
388
389 u_int32_tcxx . . $ u_int32_t#
390 net_read32cxx . . $ net_read32(df34ef224e8b6259).(u_int8_tcxx . . $ u_int8_t# *b)
391 {
392 u_int32_tcxx . . $ u_int32_t# r;
393
394 r = *(u_int32_tcxx . . $ u_int32_t# *)b;
395 return (ntohlcxx . . $ `<external>/9581057695539925927/in.h:428:12`!(r));
396 }
397
398 void
399 net_write16cxx . . $ net_write16(5f425e2ac950790c).(u_int8_tcxx . . $ u_int8_t# *p, u_int16_tcxx . . $ u_int16_t# n)
400 {
401 u_int16_tcxx . . $ u_int16_t# r;
402
403 r = htonscxx . . $ `<external>/9581057695539925927/in.h:431:12`!(n);
404 memcpycxx . . $ memcpy(cc817cb175f282d).(p, &r, sizeof(r));
405 }
406
407 void
408 net_write32cxx . . $ net_write32(e1e8b00c42c42532).(u_int8_tcxx . . $ u_int8_t# *p, u_int32_tcxx . . $ u_int32_t# n)
409 {
410 u_int32_tcxx . . $ u_int32_t# r;
411
412 r = htonlcxx . . $ `<external>/9581057695539925927/in.h:430:12`!(n);
413 memcpycxx . . $ memcpy(cc817cb175f282d).(p, &r, sizeof(r));
414 }
415
416 u_int64_tcxx . . $ u_int64_t#
417 net_read64cxx . . $ net_read64(71a4eab05fe48ca1).(u_int8_tcxx . . $ u_int8_t# *b)
418 {
419 u_int64_tcxx . . $ u_int64_t# r;
420
421 r = *(u_int64_tcxx . . $ u_int64_t# *)b;
422 return (be64tohcxx . . $ `<external>/15855202785537844739/endian.h:51:11`!(r));
423 }
424
425 void
426 net_write64cxx . . $ net_write64(6165b45f45ef689c).(u_int8_tcxx . . $ u_int8_t# *p, u_int64_tcxx . . $ u_int64_t# n)
427 {
428 u_int64_tcxx . . $ u_int64_t# r;
429
430 r = htobe64cxx . . $ `<external>/15855202785537844739/endian.h:49:11`!(n);
431 memcpycxx . . $ memcpy(cc817cb175f282d).(p, &r, sizeof(r));
432 }