1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * ä¸è¨èä½æ¨©è
|
---|
8 | ã¯ï¼ä»¥ä¸ã® (1)ï½(4) ã®æ¡ä»¶ãï¼Free Software Foundation
|
---|
9 | * ã«ãã£ã¦å
|
---|
10 | ¬è¡¨ããã¦ãã GNU General Public License ã® Version 2 ã«è¨
|
---|
11 | * è¿°ããã¦ããæ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§ã¢ï¼æ¬ã½ããã¦ã§ã¢
|
---|
12 | * ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼
|
---|
14 | * å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
15 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
16 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
17 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
18 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
19 | * ç¨ã§ããå½¢ã§åé
|
---|
20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
22 | * è
|
---|
23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
24 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
25 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
26 | * ç¨ã§ããªãå½¢ã§åé
|
---|
27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®æ¡ä»¶ãæºãããã¨ï¼
|
---|
28 | * (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
33 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
34 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
35 | 責ãããã¨ï¼
|
---|
36 | *
|
---|
37 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ã
|
---|
39 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ãã®é©ç¨å¯è½æ§ã
|
---|
40 | * å«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´
|
---|
41 | * æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ãã®è²¬ä»»ãè² ããªãï¼
|
---|
42 | *
|
---|
43 | * @(#) $Id: tcp_echo_srv1_nblk.c 388 2019-05-22 11:25:18Z coas-nagasima $
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * TCP ECHO ãµã¼ã #1
|
---|
48 | *
|
---|
49 | * ã»éåä¿¡ã¿ã¹ã¯åä¸å
|
---|
50 | * ã»ãã³ããããã³ã°ã³ã¼ã«
|
---|
51 | * ã»çã³ãã¼ API
|
---|
52 | * ã»IPv4/IPv6
|
---|
53 | * ã»ç·æ¥ãã¼ã¿ã®åä¿¡
|
---|
54 | */
|
---|
55 |
|
---|
56 | #include <string.h>
|
---|
57 |
|
---|
58 | #ifdef TARGET_KERNEL_ASP
|
---|
59 |
|
---|
60 | #include <kernel.h>
|
---|
61 | #include <sil.h>
|
---|
62 | #include <t_syslog.h>
|
---|
63 | #include "kernel_cfg.h"
|
---|
64 | #include "tinet_cfg.h"
|
---|
65 |
|
---|
66 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
67 |
|
---|
68 | #ifdef TARGET_KERNEL_JSP
|
---|
69 |
|
---|
70 | #include <t_services.h>
|
---|
71 | #include "kernel_id.h"
|
---|
72 | #include "tinet_id.h"
|
---|
73 |
|
---|
74 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
75 |
|
---|
76 | #include <netinet/in.h>
|
---|
77 | #include <netinet/in_itron.h>
|
---|
78 |
|
---|
79 | #include <netapp/netapp.h>
|
---|
80 | #include <netapp/netapp_var.h>
|
---|
81 | #include <netapp/tcp_echo_srv1.h>
|
---|
82 | #include <netapp/tcp_echo_srv1_var.h>
|
---|
83 |
|
---|
84 | #ifdef USE_TCP_ECHO_SRV1
|
---|
85 |
|
---|
86 | /*
|
---|
87 | * 表示
|
---|
88 | */
|
---|
89 |
|
---|
90 | //#define SHOW_RCV_RANGE
|
---|
91 |
|
---|
92 | /*
|
---|
93 | * ã³ãã¯ã·ã§ã³åææ¹æ³ã®æå®
|
---|
94 | */
|
---|
95 |
|
---|
96 | #define USE_TCP_SHT_CEP
|
---|
97 |
|
---|
98 | /*
|
---|
99 | * ã¿ã¤ã ã¢ã¦ã
|
---|
100 | */
|
---|
101 |
|
---|
102 | #ifdef TOPPERS_S810_CLG3_85
|
---|
103 |
|
---|
104 | #define CLS_TMO TMO_FEVR /* Close Wait ã¯æ¨æºã§ 60ç§ */
|
---|
105 | //#define RCV_TMO TMO_FEVR
|
---|
106 | #define RCV_TMO (30*SYSTIM_HZ)
|
---|
107 | //#define SND_TMO TMO_FEVR
|
---|
108 | #define SND_TMO (30*SYSTIM_HZ)
|
---|
109 |
|
---|
110 | #else /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
111 |
|
---|
112 | //#define CLS_TMO TMO_FEVR /* Close Wait ã¯æ¨æºã§ 60ç§ */
|
---|
113 | #define CLS_TMO (70*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*10)
|
---|
114 | //#define RCV_TMO TMO_FEVR
|
---|
115 | #define RCV_TMO (30*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*30)
|
---|
116 | //#define SND_TMO TMO_FEVR
|
---|
117 | #define SND_TMO (40*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*20)
|
---|
118 |
|
---|
119 | #endif /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
120 |
|
---|
121 | #ifdef USE_TCP_NON_BLOCKING
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * å¤æ°
|
---|
125 | */
|
---|
126 |
|
---|
127 | #ifdef USE_TCP_EXTENTIONS
|
---|
128 |
|
---|
129 | T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[] = {
|
---|
130 |
|
---|
131 | { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY1 },
|
---|
132 |
|
---|
133 | #if NUM_TCP_ECHO_SRV_TASKS >= 2
|
---|
134 | { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY2 },
|
---|
135 | #endif
|
---|
136 | #if NUM_TCP_ECHO_SRV_TASKS >= 3
|
---|
137 | { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY3 },
|
---|
138 | #endif
|
---|
139 | #if NUM_TCP_ECHO_SRV_TASKS >= 4
|
---|
140 | { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY4 },
|
---|
141 | #endif
|
---|
142 | #if NUM_TCP_ECHO_SRV_TASKS >= 5
|
---|
143 | { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY5 },
|
---|
144 | #endif
|
---|
145 | #if NUM_TCP_ECHO_SRV_TASKS >= 6
|
---|
146 | { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY6 },
|
---|
147 | #endif
|
---|
148 | #if NUM_TCP_ECHO_SRV_TASKS >= 7
|
---|
149 | { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY7 },
|
---|
150 | #endif
|
---|
151 | #if NUM_TCP_ECHO_SRV_TASKS >= 8
|
---|
152 | { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY8 },
|
---|
153 | #endif
|
---|
154 |
|
---|
155 | };
|
---|
156 |
|
---|
157 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
158 |
|
---|
159 | T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[] = {
|
---|
160 |
|
---|
161 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV)
|
---|
162 |
|
---|
163 | { TCP4_ECHO_SRV_CEPID1, TCP4_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY1 },
|
---|
164 |
|
---|
165 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
166 |
|
---|
167 | { TCP_ECHO_SRV_CEPID1, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY1 },
|
---|
168 |
|
---|
169 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
170 |
|
---|
171 | #if NUM_TCP_ECHO_SRV_TASKS >= 2
|
---|
172 | { TCP_ECHO_SRV_CEPID2, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY2 },
|
---|
173 | #endif
|
---|
174 | #if NUM_TCP_ECHO_SRV_TASKS >= 3
|
---|
175 | { TCP_ECHO_SRV_CEPID3, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY3 },
|
---|
176 | #endif
|
---|
177 | #if NUM_TCP_ECHO_SRV_TASKS >= 4
|
---|
178 | { TCP_ECHO_SRV_CEPID4, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY4 },
|
---|
179 | #endif
|
---|
180 | #if NUM_TCP_ECHO_SRV_TASKS >= 5
|
---|
181 | { TCP_ECHO_SRV_CEPID5, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY5 },
|
---|
182 | #endif
|
---|
183 | #if NUM_TCP_ECHO_SRV_TASKS >= 6
|
---|
184 | { TCP_ECHO_SRV_CEPID6, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY6 },
|
---|
185 | #endif
|
---|
186 | #if NUM_TCP_ECHO_SRV_TASKS >= 7
|
---|
187 | { TCP_ECHO_SRV_CEPID7, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY7 },
|
---|
188 | #endif
|
---|
189 | #if NUM_TCP_ECHO_SRV_TASKS >= 8
|
---|
190 | { TCP_ECHO_SRV_CEPID8, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY8 },
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | };
|
---|
194 |
|
---|
195 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
196 |
|
---|
197 | /*
|
---|
198 | * find_srv_info -- æ¥ç¶ç¸æã®æ
|
---|
199 | å ±æ§é ä½ãæ¢ç´¢ããã
|
---|
200 | */
|
---|
201 |
|
---|
202 | static
|
---|
203 | T_TCP_ECHO_SRV_INFO *find_srv_info (ID cepid)
|
---|
204 | {
|
---|
205 | T_TCP_ECHO_SRV_INFO *ri;
|
---|
206 |
|
---|
207 | for (ri = &tcp_echo_srv_info[sizeof(tcp_echo_srv_info) / sizeof(T_TCP_ECHO_SRV_INFO)]; ri --; )
|
---|
208 | if (ri->cepid == cepid)
|
---|
209 | return ri;
|
---|
210 | return NULL;
|
---|
211 | }
|
---|
212 |
|
---|
213 | /*
|
---|
214 | * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ°
|
---|
215 | */
|
---|
216 |
|
---|
217 | ER
|
---|
218 | callback_nblk_tcp_echo_srv (ID cepid, FN fncd, void *p_parblk)
|
---|
219 | {
|
---|
220 | ER error = E_OK;
|
---|
221 | T_TCP_ECHO_SRV_INFO *ri;
|
---|
222 |
|
---|
223 | if ((ri = find_srv_info(cepid)) == NULL) {
|
---|
224 | syslog(LOG_NOTICE, "[TESn:%02u CBN] CEPID not found", cepid);
|
---|
225 | return E_PAR;
|
---|
226 | }
|
---|
227 |
|
---|
228 | switch (fncd) {
|
---|
229 |
|
---|
230 | case TFN_TCP_ACP_CEP:
|
---|
231 | ri->error = *(ER*)p_parblk;
|
---|
232 | syscall(sig_sem(ri->semid));
|
---|
233 | break;
|
---|
234 |
|
---|
235 | case TFN_TCP_RCV_DAT:
|
---|
236 | if ((ri->rlen = *(ER*)p_parblk) < 0)
|
---|
237 | syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->rlen));
|
---|
238 | syscall(sig_sem(ri->semid));
|
---|
239 | break;
|
---|
240 |
|
---|
241 | case TFN_TCP_SND_DAT:
|
---|
242 | if ((ri->slen = *(ER*)p_parblk) < 0)
|
---|
243 | syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->slen));
|
---|
244 | syscall(sig_sem(ri->semid));
|
---|
245 | break;
|
---|
246 |
|
---|
247 | case TFN_TCP_CLS_CEP:
|
---|
248 | if ((ri->error = *(ER*)p_parblk) < 0)
|
---|
249 | syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->error));
|
---|
250 | syscall(sig_sem(ri->semid));
|
---|
251 | break;
|
---|
252 |
|
---|
253 | case TFN_TCP_RCV_BUF:
|
---|
254 | if ((ri->rlen = *(ER*)p_parblk) < 0)
|
---|
255 | syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->rlen));
|
---|
256 | syscall(sig_sem(ri->semid));
|
---|
257 | break;
|
---|
258 |
|
---|
259 | case TFN_TCP_GET_BUF:
|
---|
260 | if ((ri->slen = *(ER*)p_parblk) < 0)
|
---|
261 | syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->slen));
|
---|
262 | syscall(sig_sem(ri->semid));
|
---|
263 | break;
|
---|
264 |
|
---|
265 | #ifdef USE_TCP_EXTENTIONS
|
---|
266 |
|
---|
267 | case TEV_TCP_RCV_OOB:
|
---|
268 | if ((ri->rlen = *(ER*)p_parblk) < 0)
|
---|
269 | syslog(LOG_NOTICE, "[TESn:%02u OOB] error: %s", cepid, itron_strerror(ri->rlen));
|
---|
270 | else if (ri->rlen > 0) {
|
---|
271 | char ch;
|
---|
272 |
|
---|
273 | if ((ri->rlen = tcp_rcv_oob(cepid, &ch, sizeof(ch))) > 0)
|
---|
274 | syslog(LOG_NOTICE, "[TESn:%02u OOB] recv oob: 0x%02x", cepid, ch);
|
---|
275 | else if (ri->rlen < 0)
|
---|
276 | syslog(LOG_NOTICE, "[TESn:%02u OOB] error: %s", cepid, itron_strerror(ri->rlen));
|
---|
277 | }
|
---|
278 | break;
|
---|
279 |
|
---|
280 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
281 |
|
---|
282 | case TFN_TCP_CON_CEP:
|
---|
283 | case TFN_TCP_SND_OOB:
|
---|
284 | default:
|
---|
285 | error = E_PAR;
|
---|
286 | break;
|
---|
287 | }
|
---|
288 | return error;
|
---|
289 | }
|
---|
290 |
|
---|
291 | /*
|
---|
292 | * tcp_passive_open -- ååãªã¼ãã³ãå®è¡ããã
|
---|
293 | *
|
---|
294 | * USE_TCP_NON_BLOCKING ON
|
---|
295 | */
|
---|
296 |
|
---|
297 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
298 |
|
---|
299 | static ER
|
---|
300 | tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
|
---|
301 | {
|
---|
302 | ER error;
|
---|
303 | T_IPV4EP dst4;
|
---|
304 |
|
---|
305 | if (apip == API_PROTO_IPV6) {
|
---|
306 | /* åä»å£ã¯ IPv6 */
|
---|
307 | if ((error = tcp6_acp_cep(info->cepid, info->repid, &info->dst, TMO_NBLK)) != E_WBLK)
|
---|
308 | return error;
|
---|
309 |
|
---|
310 | /* ç¸æããæ¥ç¶ãããã¾ã§å¾
|
---|
311 | ã¤ã*/
|
---|
312 | syscall(wai_sem(info->semid));
|
---|
313 |
|
---|
314 | if (info->error != E_OK)
|
---|
315 | return info->error;
|
---|
316 |
|
---|
317 | #ifdef USE_TCP_EXTENTIONS
|
---|
318 | if ((error = free_tcp6_rep(info->repid, true)) != E_OK)
|
---|
319 | return error;
|
---|
320 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
321 |
|
---|
322 | }
|
---|
323 | else {
|
---|
324 | /* åä»å£ã¯ IPv4 */
|
---|
325 | if ((error = tcp_acp_cep(info->cepid, info->repid, &dst4, TMO_NBLK)) != E_WBLK)
|
---|
326 | return error;
|
---|
327 |
|
---|
328 | /* ç¸æããæ¥ç¶ãããã¾ã§å¾
|
---|
329 | ã¤ã*/
|
---|
330 | syscall(wai_sem(info->semid));
|
---|
331 |
|
---|
332 | if (info->error != E_OK)
|
---|
333 | return info->error;
|
---|
334 |
|
---|
335 | #ifdef USE_TCP_EXTENTIONS
|
---|
336 | if ((error = free_tcp4_rep(info->repid, true)) != E_OK)
|
---|
337 | return error;
|
---|
338 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
339 |
|
---|
340 | in6_make_ipv4mapped (&info->dst.ipaddr, dst4.ipaddr);
|
---|
341 | info->dst.portno = dst4.portno;
|
---|
342 |
|
---|
343 | }
|
---|
344 |
|
---|
345 | return E_OK;
|
---|
346 | }
|
---|
347 |
|
---|
348 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
349 |
|
---|
350 | static ER
|
---|
351 | tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
|
---|
352 | {
|
---|
353 | ER error;
|
---|
354 |
|
---|
355 | if ((error = TCP_ACP_CEP(info->cepid, info->repid, &info->dst, TMO_NBLK)) != E_WBLK)
|
---|
356 | return error;
|
---|
357 |
|
---|
358 | /* ç¸æããæ¥ç¶ãããã¾ã§å¾
|
---|
359 | ã¤ã*/
|
---|
360 | syscall(wai_sem(info->semid));
|
---|
361 |
|
---|
362 | if (info->error != E_OK)
|
---|
363 | return info->error;
|
---|
364 |
|
---|
365 | #ifdef USE_TCP_EXTENTIONS
|
---|
366 | if ((error = FREE_TCP_REP(info->repid, true)) != E_OK)
|
---|
367 | return error;
|
---|
368 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
369 |
|
---|
370 | return E_OK;
|
---|
371 | }
|
---|
372 |
|
---|
373 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
374 |
|
---|
375 | #ifdef USE_COPYSAVE_API
|
---|
376 |
|
---|
377 | /*
|
---|
378 | * tcp_echo_srv -- TCP ã¨ã³ã¼ãµã¼ã
|
---|
379 | *
|
---|
380 | * USE_TCP_NON_BLOCKING ON
|
---|
381 | * USE_COPYSAVE_API ON
|
---|
382 | */
|
---|
383 |
|
---|
384 | ER
|
---|
385 | tcp_echo_srv (uint_t six, char apip)
|
---|
386 | {
|
---|
387 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
388 | T_IN4_ADDR ipv4addr;
|
---|
389 | #endif
|
---|
390 | ER error;
|
---|
391 | SYSTIM now;
|
---|
392 | uint32_t total;
|
---|
393 | uint16_t rblen, sblen, rlen, slen, soff, scount, rcount;
|
---|
394 | char *rbuf, *sbuf, head, tail;
|
---|
395 |
|
---|
396 | if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK)
|
---|
397 | return error;
|
---|
398 |
|
---|
399 | syscall(get_tim(&now));
|
---|
400 |
|
---|
401 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
402 |
|
---|
403 | if (apip == API_PROTO_IPV6)
|
---|
404 | syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
405 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
406 | ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
407 | tcp_echo_srv_info[six].dst.portno);
|
---|
408 | else {
|
---|
409 | ipv4addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
|
---|
410 | syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
411 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
412 | ip2str(NULL, &ipv4addr),
|
---|
413 | tcp_echo_srv_info[six].dst.portno);
|
---|
414 | }
|
---|
415 |
|
---|
416 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
417 |
|
---|
418 | syslog(LOG_NOTICE, "[TES%c:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
419 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
420 | IP2STR(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
421 | tcp_echo_srv_info[six].dst.portno);
|
---|
422 |
|
---|
423 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
424 |
|
---|
425 | rlen = scount = rcount = total = 0;
|
---|
426 | while (true) {
|
---|
427 | if ((error = tcp_rcv_buf(tcp_echo_srv_info[six].cepid, (void**)&rbuf, TMO_NBLK)) != E_WBLK) {
|
---|
428 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
429 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
430 | break;
|
---|
431 | }
|
---|
432 |
|
---|
433 | /* åä¿¡ããã¾ã§å¾
|
---|
434 | ã¤ã*/
|
---|
435 | syscall(wai_sem(tcp_echo_srv_info[six].semid));
|
---|
436 |
|
---|
437 | if (tcp_echo_srv_info[six].rlen < 0) { /* ã¨ã©ã¼ */
|
---|
438 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
439 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(tcp_echo_srv_info[six].rlen));
|
---|
440 | break;
|
---|
441 | }
|
---|
442 | else if (tcp_echo_srv_info[six].rlen == 0) /* åä¿¡çµäº */
|
---|
443 | break;
|
---|
444 |
|
---|
445 | rblen = tcp_echo_srv_info[six].rlen;
|
---|
446 |
|
---|
447 | /* ãããã¡ã®æ®ãã«ãããåä¿¡é·ã調æ´ããã*/
|
---|
448 | if (rblen > BUF_SIZE - rlen)
|
---|
449 | rblen = BUF_SIZE - rlen;
|
---|
450 | total += rblen;
|
---|
451 | rlen = rblen;
|
---|
452 |
|
---|
453 | head = *rbuf;
|
---|
454 | tail = *(rbuf + rblen - 1);
|
---|
455 | rcount ++;
|
---|
456 |
|
---|
457 | #ifdef SHOW_RCV_RANGE
|
---|
458 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] "
|
---|
459 | "rcount: %7lu, len: %6lu, data %02x -> %02x",
|
---|
460 | apip, tcp_echo_srv_info[six].cepid, rcount, rblen, head, tail);
|
---|
461 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
462 |
|
---|
463 | memcpy(tcp_echo_srv_info[six].buffer, rbuf, rblen);
|
---|
464 |
|
---|
465 | if ((error = tcp_rel_buf(tcp_echo_srv_info[six].cepid, rlen)) < 0) {
|
---|
466 | syslog(LOG_NOTICE, "[TES%c:%02u REL] error: %s",
|
---|
467 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
468 | break;
|
---|
469 | }
|
---|
470 |
|
---|
471 | soff = 0;
|
---|
472 | while (rlen > 0) {
|
---|
473 |
|
---|
474 | if ((error = tcp_get_buf(tcp_echo_srv_info[six].cepid, (void**)&sbuf, TMO_NBLK)) != E_WBLK) {
|
---|
475 | syslog(LOG_NOTICE, "[TES%c:%02u GET] error: %s",
|
---|
476 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
477 | goto err_fin;
|
---|
478 | }
|
---|
479 |
|
---|
480 | /* éä¿¡ãããã¡ã®ç²å¾ãå®äºããã¾ã§å¾
|
---|
481 | ã¤ã*/
|
---|
482 | syscall(wai_sem(tcp_echo_srv_info[six].semid));
|
---|
483 |
|
---|
484 | if (tcp_echo_srv_info[six].slen < 0) {
|
---|
485 | syslog(LOG_NOTICE, "[TES%c:%02u GET] error: %s",
|
---|
486 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(tcp_echo_srv_info[six].slen));
|
---|
487 | goto err_fin;
|
---|
488 | }
|
---|
489 |
|
---|
490 | sblen = tcp_echo_srv_info[six].slen;
|
---|
491 | scount ++;
|
---|
492 | slen = sblen < rlen ? sblen : rlen;
|
---|
493 | memcpy(sbuf, tcp_echo_srv_info[six].buffer + soff, slen);
|
---|
494 |
|
---|
495 | if ((error = tcp_snd_buf(tcp_echo_srv_info[six].cepid, slen)) != E_OK) {
|
---|
496 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
497 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
498 | goto err_fin;
|
---|
499 | }
|
---|
500 | #ifdef SHOW_RCV_RANGE
|
---|
501 | syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %7lu, len: %4u",
|
---|
502 | apip, cepid, scount, slen);
|
---|
503 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
504 |
|
---|
505 | rlen -= slen;
|
---|
506 | soff += slen;
|
---|
507 | }
|
---|
508 | }
|
---|
509 | err_fin:
|
---|
510 |
|
---|
511 | #ifdef USE_TCP_SHT_CEP
|
---|
512 | if ((error = tcp_sht_cep(tcp_echo_srv_info[six].cepid)) != E_OK)
|
---|
513 | syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
|
---|
514 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
515 | #endif /* of #ifdef USE_TCP_SHT_CEP */
|
---|
516 |
|
---|
517 | if ((error = tcp_cls_cep(tcp_echo_srv_info[six].cepid, TMO_NBLK)) != E_WBLK)
|
---|
518 | syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
|
---|
519 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
520 |
|
---|
521 | /* éæ¾ãå®äºããã¾ã§å¾
|
---|
522 | ã¤ã*/
|
---|
523 | syscall(wai_sem(tcp_echo_srv_info[six].semid));
|
---|
524 |
|
---|
525 | syscall(get_tim(&now));
|
---|
526 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
|
---|
527 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total);
|
---|
528 |
|
---|
529 | return error == E_WBLK ? E_OK : error;
|
---|
530 | }
|
---|
531 |
|
---|
532 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
533 |
|
---|
534 | /*
|
---|
535 | * tcp_echo_srv -- TCP ã¨ã³ã¼ãµã¼ã
|
---|
536 | *
|
---|
537 | * USE_TCP_NON_BLOCKING ON
|
---|
538 | * USE_COPYSAVE_API OFF
|
---|
539 | */
|
---|
540 |
|
---|
541 | ER
|
---|
542 | tcp_echo_srv (uint_t six, char apip)
|
---|
543 | {
|
---|
544 | T_IN4_ADDR ipv4addr;
|
---|
545 | ER error;
|
---|
546 | SYSTIM now;
|
---|
547 | uint32_t total;
|
---|
548 | uint16_t rlen, slen, soff, scount, rcount;
|
---|
549 | char head, tail;
|
---|
550 |
|
---|
551 | if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK)
|
---|
552 | return error;
|
---|
553 |
|
---|
554 | syscall(get_tim(&now));
|
---|
555 | if (apip == API_PROTO_IPV6)
|
---|
556 | syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
557 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
558 | ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
559 | tcp_echo_srv_info[six].dst.portno);
|
---|
560 | else {
|
---|
561 | ipv4addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
|
---|
562 | syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
563 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
564 | ip2str(NULL, &ipv4addr),
|
---|
565 | tcp_echo_srv_info[six].dst.portno);
|
---|
566 | }
|
---|
567 |
|
---|
568 | scount = rcount = total = 0;
|
---|
569 | while (true) {
|
---|
570 | if ((error = tcp_rcv_dat(tcp_echo_srv_info[six].cepid, tcp_echo_srv_info[six].buffer, BUF_SIZE - 1, TMO_NBLK)) != E_WBLK) {
|
---|
571 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
572 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
573 | break;
|
---|
574 | }
|
---|
575 |
|
---|
576 | /* åä¿¡å®äºã¾ã§å¾
|
---|
577 | ã¤ã*/
|
---|
578 | syscall(wai_sem(tcp_echo_srv_info[six].semid));
|
---|
579 |
|
---|
580 | if (tcp_echo_srv_info[six].rlen < 0) {
|
---|
581 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
582 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(tcp_echo_srv_info[six].rlen));
|
---|
583 | break;
|
---|
584 | }
|
---|
585 | else if (tcp_echo_srv_info[six].rlen == 0)
|
---|
586 | break;
|
---|
587 |
|
---|
588 | rlen = tcp_echo_srv_info[six].rlen;
|
---|
589 | head = * tcp_echo_srv_info[six].buffer;
|
---|
590 | tail = *(tcp_echo_srv_info[six].buffer + rlen - 1);
|
---|
591 | rcount ++;
|
---|
592 |
|
---|
593 | #ifdef SHOW_RCV_RANGE
|
---|
594 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] rcount: %4u, len: %4u, data %02x -> %02x",
|
---|
595 | apip, tcp_echo_srv_info[six].cepid, rcount, rlen, head, tail);
|
---|
596 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
597 |
|
---|
598 | total += rlen;
|
---|
599 | soff = 0;
|
---|
600 | while (rlen > 0) {
|
---|
601 | scount ++;
|
---|
602 | if ((error = tcp_snd_dat(tcp_echo_srv_info[six].cepid, &tcp_echo_srv_info[six].buffer[soff], rlen, TMO_NBLK)) != E_WBLK) {
|
---|
603 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
604 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
605 | goto err_fin;
|
---|
606 | }
|
---|
607 |
|
---|
608 | /* éä¿¡å®äºã¾ã§å¾
|
---|
609 | ã¤ã*/
|
---|
610 | syscall(wai_sem(tcp_echo_srv_info[six].semid));
|
---|
611 |
|
---|
612 | if (tcp_echo_srv_info[six].slen < 0) {
|
---|
613 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
614 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(tcp_echo_srv_info[six].slen));
|
---|
615 | goto err_fin;
|
---|
616 | }
|
---|
617 |
|
---|
618 | slen = tcp_echo_srv_info[six].slen;
|
---|
619 |
|
---|
620 | #ifdef SHOW_RCV_RANGE
|
---|
621 | syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %4u, len: %4u",
|
---|
622 | apip, tcp_echo_srv_info[six].cepid, scount, slen);
|
---|
623 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
624 |
|
---|
625 | rlen -= slen;
|
---|
626 | soff += slen;
|
---|
627 | }
|
---|
628 | }
|
---|
629 | err_fin:
|
---|
630 |
|
---|
631 | #ifdef USE_TCP_SHT_CEP
|
---|
632 | if ((error = tcp_sht_cep(tcp_echo_srv_info[six].cepid)) != E_OK)
|
---|
633 | syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
|
---|
634 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
635 | #endif /* of #ifdef USE_TCP_SHT_CEP */
|
---|
636 |
|
---|
637 | if ((error = tcp_cls_cep(tcp_echo_srv_info[six].cepid, TMO_NBLK)) != E_WBLK)
|
---|
638 | syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
|
---|
639 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
640 |
|
---|
641 | /* éæ¾ãå®äºããã¾ã§å¾
|
---|
642 | ã¤ã*/
|
---|
643 | syscall(wai_sem(tcp_echo_srv_info[six].semid));
|
---|
644 |
|
---|
645 | syscall(get_tim(&now));
|
---|
646 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
|
---|
647 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total);
|
---|
648 |
|
---|
649 | return error == E_WBLK ? E_OK : error;
|
---|
650 | }
|
---|
651 |
|
---|
652 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
653 |
|
---|
654 | #endif /* of #ifdef USE_TCP_NON_BLOCKING */
|
---|
655 |
|
---|
656 | #endif /* of #ifdef USE_TCP_ECHO_SRV1 */
|
---|