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 | * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
|
---|
8 | * によって公表されている GNU General Public License の Version 2 に記
|
---|
9 | * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
|
---|
10 | * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
|
---|
11 | * 利用と呼ぶ)することを無償で許諾する.
|
---|
12 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
13 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
14 | * スコード中に含まれていること.
|
---|
15 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
16 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
17 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
18 | * の無保証規定を掲載すること.
|
---|
19 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
20 | * 用できない形で再配布する場合には,次の条件を満たすこと.
|
---|
21 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
22 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
25 | *
|
---|
26 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
27 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
|
---|
28 | * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
|
---|
29 | * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
|
---|
30 | *
|
---|
31 | * @(#) $Id$
|
---|
32 | */
|
---|
33 |
|
---|
34 | /*
|
---|
35 | * TCP ECHO サーバ #1
|
---|
36 | *
|
---|
37 | * ・送受信タスク同一型
|
---|
38 | * ・ノンブロッキングコール
|
---|
39 | * ・省コピー API
|
---|
40 | * ・IPv4/IPv6
|
---|
41 | * ・緊急データの受信
|
---|
42 | */
|
---|
43 |
|
---|
44 | #include <string.h>
|
---|
45 |
|
---|
46 | #ifdef TARGET_KERNEL_ASP
|
---|
47 |
|
---|
48 | #include <kernel.h>
|
---|
49 | #include <sil.h>
|
---|
50 | #include <t_syslog.h>
|
---|
51 | #include "kernel_cfg.h"
|
---|
52 | #include "tinet_cfg.h"
|
---|
53 |
|
---|
54 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
55 |
|
---|
56 | #ifdef TARGET_KERNEL_JSP
|
---|
57 |
|
---|
58 | #include <t_services.h>
|
---|
59 | #include "kernel_id.h"
|
---|
60 | #include "tinet_id.h"
|
---|
61 |
|
---|
62 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
63 |
|
---|
64 | #include <netinet/in.h>
|
---|
65 | #include <netinet/in_itron.h>
|
---|
66 |
|
---|
67 | #include <netapp/netapp.h>
|
---|
68 | #include <netapp/netapp_var.h>
|
---|
69 | #include <netapp/tcp_echo_srv1.h>
|
---|
70 | #include <netapp/tcp_echo_srv1_var.h>
|
---|
71 |
|
---|
72 | #if defined(_NET_CFG_BYTE_ORDER)
|
---|
73 | #error "net/net.h included."
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #ifdef USE_TCP_ECHO_SRV1
|
---|
77 |
|
---|
78 | /*
|
---|
79 | * 表示
|
---|
80 | */
|
---|
81 |
|
---|
82 | //#define SHOW_RCV_RANGE
|
---|
83 |
|
---|
84 | /*
|
---|
85 | * コネクション切断方法の指定
|
---|
86 | */
|
---|
87 |
|
---|
88 | #define USE_TCP_SHT_CEP
|
---|
89 |
|
---|
90 | /*
|
---|
91 | * タイムアウト
|
---|
92 | */
|
---|
93 |
|
---|
94 | #ifdef TOPPERS_S810_CLG3_85
|
---|
95 |
|
---|
96 | #define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */
|
---|
97 | //#define RCV_TMO TMO_FEVR
|
---|
98 | #define RCV_TMO (30*SYSTIM_HZ)
|
---|
99 | //#define SND_TMO TMO_FEVR
|
---|
100 | #define SND_TMO (30*SYSTIM_HZ)
|
---|
101 |
|
---|
102 | #else /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
103 |
|
---|
104 | //#define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */
|
---|
105 | #define CLS_TMO (70*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*10)
|
---|
106 | //#define RCV_TMO TMO_FEVR
|
---|
107 | #define RCV_TMO (30*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*30)
|
---|
108 | //#define SND_TMO TMO_FEVR
|
---|
109 | #define SND_TMO (40*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*20)
|
---|
110 |
|
---|
111 | #endif /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
112 |
|
---|
113 | /*
|
---|
114 | * 全域変数
|
---|
115 | */
|
---|
116 |
|
---|
117 | /* TCP 送受信ウィンドバッファ */
|
---|
118 |
|
---|
119 | #ifndef TCP_CFG_SWBUF_CSAVE
|
---|
120 | uint8_t tcp_echo_srv_swbuf[NUM_TCP_ECHO_SRV_TASKS][TCP_ECHO_SRV_SWBUF_SIZE];
|
---|
121 | #endif
|
---|
122 |
|
---|
123 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
124 | uint8_t tcp_echo_srv_rwbuf[NUM_TCP_ECHO_SRV_TASKS][TCP_ECHO_SRV_RWBUF_SIZE];
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | #ifndef USE_TCP_NON_BLOCKING
|
---|
128 |
|
---|
129 | /*
|
---|
130 | * 変数
|
---|
131 | */
|
---|
132 |
|
---|
133 | #ifdef USE_TCP_EXTENTIONS
|
---|
134 |
|
---|
135 | T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[NUM_TCP_ECHO_SRV_TASKS];
|
---|
136 |
|
---|
137 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
138 |
|
---|
139 | T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[] = {
|
---|
140 |
|
---|
141 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV)
|
---|
142 |
|
---|
143 | { TCP4_ECHO_SRV_CEPID1, TCP4_ECHO_SRV_REPID },
|
---|
144 |
|
---|
145 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
146 |
|
---|
147 | { TCP_ECHO_SRV_CEPID1, TCP_ECHO_SRV_REPID },
|
---|
148 |
|
---|
149 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
150 |
|
---|
151 | #if NUM_TCP_ECHO_SRV_TASKS >= 2
|
---|
152 | { TCP_ECHO_SRV_CEPID2, TCP_ECHO_SRV_REPID },
|
---|
153 | #endif
|
---|
154 | #if NUM_TCP_ECHO_SRV_TASKS >= 3
|
---|
155 | { TCP_ECHO_SRV_CEPID3, TCP_ECHO_SRV_REPID },
|
---|
156 | #endif
|
---|
157 | #if NUM_TCP_ECHO_SRV_TASKS >= 4
|
---|
158 | { TCP_ECHO_SRV_CEPID4, TCP_ECHO_SRV_REPID },
|
---|
159 | #endif
|
---|
160 | #if NUM_TCP_ECHO_SRV_TASKS >= 5
|
---|
161 | { TCP_ECHO_SRV_CEPID5, TCP_ECHO_SRV_REPID },
|
---|
162 | #endif
|
---|
163 | #if NUM_TCP_ECHO_SRV_TASKS >= 6
|
---|
164 | { TCP_ECHO_SRV_CEPID6, TCP_ECHO_SRV_REPID },
|
---|
165 | #endif
|
---|
166 | #if NUM_TCP_ECHO_SRV_TASKS >= 7
|
---|
167 | { TCP_ECHO_SRV_CEPID7, TCP_ECHO_SRV_REPID },
|
---|
168 | #endif
|
---|
169 | #if NUM_TCP_ECHO_SRV_TASKS >= 8
|
---|
170 | { TCP_ECHO_SRV_CEPID8, TCP_ECHO_SRV_REPID },
|
---|
171 | #endif
|
---|
172 |
|
---|
173 | };
|
---|
174 |
|
---|
175 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
176 |
|
---|
177 | /*
|
---|
178 | * tcp_passive_open -- 受動オープンを実行する。
|
---|
179 | *
|
---|
180 | * USE_TCP_NON_BLOCKING OFF
|
---|
181 | */
|
---|
182 |
|
---|
183 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
184 |
|
---|
185 | static ER
|
---|
186 | tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
|
---|
187 | {
|
---|
188 | ER error = E_OK;
|
---|
189 |
|
---|
190 | #if TNUM_TCP4_REPID > 0
|
---|
191 | T_IPV4EP dst4;
|
---|
192 | #endif
|
---|
193 |
|
---|
194 | if (apip == API_PROTO_IPV6) {
|
---|
195 |
|
---|
196 | #if TNUM_TCP6_REPID > 0
|
---|
197 |
|
---|
198 | /* 受付口は IPv6 */
|
---|
199 | if ((error = tcp6_acp_cep(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
|
---|
200 | return error;
|
---|
201 |
|
---|
202 | #ifdef USE_TCP_EXTENTIONS
|
---|
203 | if ((error = free_tcp6_rep(info->repid, true)) != E_OK)
|
---|
204 | return error;
|
---|
205 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
206 |
|
---|
207 | #endif /* of #if TNUM_TCP6_REPID > 0 */
|
---|
208 |
|
---|
209 | }
|
---|
210 | else {
|
---|
211 |
|
---|
212 | #if TNUM_TCP4_REPID > 0
|
---|
213 |
|
---|
214 | /* 受付口は IPv4 */
|
---|
215 | if ((error = tcp_acp_cep(info->cepid, info->repid, &dst4, TMO_FEVR)) != E_OK)
|
---|
216 | return error;
|
---|
217 | in6_make_ipv4mapped (&info->dst.ipaddr, dst4.ipaddr);
|
---|
218 | info->dst.portno = dst4.portno;
|
---|
219 |
|
---|
220 | #ifdef USE_TCP_EXTENTIONS
|
---|
221 | if ((error = free_tcp4_rep(info->repid, true)) != E_OK)
|
---|
222 | return error;
|
---|
223 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
224 |
|
---|
225 | #endif /* of #if TNUM_TCP4_REPID > 0 */
|
---|
226 |
|
---|
227 | }
|
---|
228 |
|
---|
229 | return error;
|
---|
230 | }
|
---|
231 |
|
---|
232 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
233 |
|
---|
234 | /*
|
---|
235 | * tcp_passive_open -- 受動オープンを実行する。
|
---|
236 | *
|
---|
237 | * USE_TCP_NON_BLOCKING OFF
|
---|
238 | */
|
---|
239 |
|
---|
240 | static ER
|
---|
241 | tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
|
---|
242 | {
|
---|
243 | ER error = E_OK;
|
---|
244 |
|
---|
245 | if ((error = TCP_ACP_CEP(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
|
---|
246 | return error;
|
---|
247 |
|
---|
248 | #ifdef USE_TCP_EXTENTIONS
|
---|
249 | if ((error = FREE_TCP_REP(info->repid, true)) != E_OK)
|
---|
250 | return error;
|
---|
251 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
252 |
|
---|
253 | return error;
|
---|
254 | }
|
---|
255 |
|
---|
256 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
257 |
|
---|
258 | #ifdef USE_COPYSAVE_API
|
---|
259 |
|
---|
260 | /*
|
---|
261 | * tcp_echo_srv -- TCP エコーサーバ
|
---|
262 | *
|
---|
263 | * USE_TCP_NON_BLOCKING OFF
|
---|
264 | * USE_COPYSAVE_API ON
|
---|
265 | */
|
---|
266 |
|
---|
267 | ER
|
---|
268 | tcp_echo_srv (uint_t six, char apip)
|
---|
269 | {
|
---|
270 | ER error = E_OK;
|
---|
271 | ER_UINT rblen, sblen;
|
---|
272 | SYSTIM now;
|
---|
273 | uint32_t total;
|
---|
274 | uint16_t rlen, slen, soff, scount, rcount;
|
---|
275 | char *rbuf, *sbuf;
|
---|
276 |
|
---|
277 | #ifdef SHOW_RCV_RANGE
|
---|
278 | char head, tail;
|
---|
279 | #endif
|
---|
280 |
|
---|
281 | if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK) {
|
---|
282 | syslog(LOG_NOTICE, "[TES%c:%02u OPN] error: %s",
|
---|
283 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
284 | return error;
|
---|
285 | }
|
---|
286 |
|
---|
287 | syscall(get_tim(&now));
|
---|
288 |
|
---|
289 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
290 |
|
---|
291 | if (apip == API_PROTO_IPV6)
|
---|
292 | syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
293 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
294 | ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
295 | tcp_echo_srv_info[six].dst.portno);
|
---|
296 | else {
|
---|
297 | T_IN4_ADDR addr;
|
---|
298 |
|
---|
299 | addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
|
---|
300 | syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
301 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
302 | ip2str(NULL, &addr), tcp_echo_srv_info[six].dst.portno);
|
---|
303 | }
|
---|
304 |
|
---|
305 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
306 |
|
---|
307 | syslog(LOG_NOTICE, "[TES%c:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
308 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
309 | IP2STR(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
310 | tcp_echo_srv_info[six].dst.portno);
|
---|
311 |
|
---|
312 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
313 |
|
---|
314 | scount = rcount = total = 0;
|
---|
315 | while (true) {
|
---|
316 | if ((rblen = tcp_rcv_buf(tcp_echo_srv_info[six].cepid, (void**)&rbuf, RCV_TMO)) <= 0) {
|
---|
317 | if (rblen != E_OK)
|
---|
318 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
319 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(rblen));
|
---|
320 | break;
|
---|
321 | }
|
---|
322 |
|
---|
323 | rcount ++;
|
---|
324 |
|
---|
325 | #ifdef SHOW_RCV_RANGE
|
---|
326 | head = *rbuf;
|
---|
327 | tail = *(rbuf + rblen - 1);
|
---|
328 |
|
---|
329 | //syslog(LOG_NOTICE, "[TES%c:%02u RCV] len: %7lu",
|
---|
330 | // apip, tcp_echo_srv_info[six].cepid, (uint16_t)rblen);
|
---|
331 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] rcount: %7lu, len: %6lu, data %02x -> %02x",
|
---|
332 | apip, tcp_echo_srv_info[six].cepid, rcount, (uint16_t)rblen, head, tail);
|
---|
333 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
334 |
|
---|
335 | rlen = (uint16_t)rblen;
|
---|
336 | total += rblen;
|
---|
337 | soff = 0;
|
---|
338 | while (rlen > 0) {
|
---|
339 |
|
---|
340 | if ((sblen = tcp_get_buf(tcp_echo_srv_info[six].cepid, (void**)&sbuf, SND_TMO)) < 0) {
|
---|
341 | syslog(LOG_NOTICE, "[TES%c:%02u GET] error: %s",
|
---|
342 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(sblen));
|
---|
343 | goto err_fin;
|
---|
344 | }
|
---|
345 |
|
---|
346 | //syslog(LOG_NOTICE, "[TES%c:%02u SND] len: %7lu",
|
---|
347 | // apip, tcp_echo_srv_info[six].cepid, (uint16_t)sblen);
|
---|
348 | scount ++;
|
---|
349 | slen = rlen < (uint16_t)sblen ? rlen : (uint16_t)sblen;
|
---|
350 | memcpy(sbuf, rbuf + soff, slen);
|
---|
351 | if ((error = tcp_snd_buf(tcp_echo_srv_info[six].cepid, slen)) != E_OK) {
|
---|
352 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
353 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
354 | goto err_fin;
|
---|
355 | }
|
---|
356 | #ifdef SHOW_RCV_RANGE
|
---|
357 | syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %4u, len: %4u",
|
---|
358 | apip, tcp_echo_srv_info[six].cepid, scount, slen);
|
---|
359 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
360 |
|
---|
361 | rlen -= slen;
|
---|
362 | soff += slen;
|
---|
363 | }
|
---|
364 |
|
---|
365 | if ((error = tcp_rel_buf(tcp_echo_srv_info[six].cepid, rblen)) < 0) {
|
---|
366 | syslog(LOG_NOTICE, "[TES%c:%02u REL] error: %s",
|
---|
367 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
368 | break;
|
---|
369 | }
|
---|
370 | }
|
---|
371 | err_fin:
|
---|
372 |
|
---|
373 | #ifdef USE_TCP_SHT_CEP
|
---|
374 | if ((error = tcp_sht_cep(tcp_echo_srv_info[six].cepid)) != E_OK)
|
---|
375 | syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
|
---|
376 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
377 | #endif /* of #ifdef USE_TCP_SHT_CEP */
|
---|
378 |
|
---|
379 | if ((error = tcp_cls_cep(tcp_echo_srv_info[six].cepid, CLS_TMO)) != E_OK)
|
---|
380 | syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
|
---|
381 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
382 |
|
---|
383 | syscall(get_tim(&now));
|
---|
384 | #if 1
|
---|
385 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
|
---|
386 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total);
|
---|
387 | #else
|
---|
388 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu, error: %s",
|
---|
389 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total, itron_strerror(error));
|
---|
390 | #endif
|
---|
391 |
|
---|
392 | return error;
|
---|
393 | }
|
---|
394 |
|
---|
395 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
396 |
|
---|
397 | /*
|
---|
398 | * tcp_echo_srv -- TCP エコーサーバ
|
---|
399 | *
|
---|
400 | * USE_TCP_NON_BLOCKING OFF
|
---|
401 | * USE_COPYSAVE_API OFF
|
---|
402 | */
|
---|
403 |
|
---|
404 | ER
|
---|
405 | tcp_echo_srv (uint_t six, char apip)
|
---|
406 | {
|
---|
407 | ID cepid;
|
---|
408 | ER error = E_OK;
|
---|
409 | ER_UINT rlen, slen;
|
---|
410 | SYSTIM now;
|
---|
411 | uint32_t total;
|
---|
412 | uint16_t soff, scount, rcount;
|
---|
413 |
|
---|
414 | if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK) {
|
---|
415 | syslog(LOG_NOTICE, "[TES%c:%02u OPN] error: %s",
|
---|
416 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
417 | return error;
|
---|
418 | }
|
---|
419 |
|
---|
420 | syscall(get_tim(&now));
|
---|
421 |
|
---|
422 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
423 |
|
---|
424 | if (apip == API_PROTO_IPV6)
|
---|
425 | syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
426 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
427 | ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
428 | tcp_echo_srv_info[six].dst.portno);
|
---|
429 | else {
|
---|
430 | T_IN4_ADDR addr;
|
---|
431 |
|
---|
432 | addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
|
---|
433 | syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
434 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
435 | ip2str(NULL, &addr), tcp_echo_srv_info[six].dst.portno);
|
---|
436 | }
|
---|
437 |
|
---|
438 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
439 |
|
---|
440 | syslog(LOG_NOTICE, "[TES%c:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
441 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
442 | IP2STR(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
443 | tcp_echo_srv_info[six].dst.portno);
|
---|
444 |
|
---|
445 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
446 |
|
---|
447 | cepid = tcp_echo_srv_info[six].cepid;
|
---|
448 | scount = rcount = total = 0;
|
---|
449 | while (true) {
|
---|
450 | if ((rlen = tcp_rcv_dat(cepid, tcp_echo_srv_info[six].buffer, BUF_SIZE - 1, RCV_TMO)) <= 0) {
|
---|
451 | if (rlen != E_OK)
|
---|
452 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
453 | apip, cepid, itron_strerror(rlen));
|
---|
454 | break;
|
---|
455 | }
|
---|
456 |
|
---|
457 | rcount ++;
|
---|
458 | #ifdef SHOW_RCV_RANGE
|
---|
459 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] rcount: %4u, len: %4u, data %02x -> %02x",
|
---|
460 | apip, cepid, rcount,
|
---|
461 | (uint16_t)rlen, * tcp_echo_srv_info[six].tcp_echo_srv_info[six].buffer,
|
---|
462 | *(tcp_echo_srv_info[six].tcp_echo_srv_info[six].buffer + rlen - 1));
|
---|
463 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
464 |
|
---|
465 | total += rlen;
|
---|
466 | soff = 0;
|
---|
467 | while (rlen > 0) {
|
---|
468 | scount ++;
|
---|
469 | if ((slen = tcp_snd_dat(cepid, &tcp_echo_srv_info[six].buffer[soff], rlen, SND_TMO)) < 0) {
|
---|
470 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
471 | apip, cepid, itron_strerror(slen));
|
---|
472 | goto err_fin;
|
---|
473 | }
|
---|
474 | #ifdef SHOW_RCV_RANGE
|
---|
475 | syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %4u, len: %4u",
|
---|
476 | apip, cepid, scount, (uint16_t)slen);
|
---|
477 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
478 |
|
---|
479 | rlen -= slen;
|
---|
480 | soff += slen;
|
---|
481 | }
|
---|
482 | }
|
---|
483 | err_fin:
|
---|
484 |
|
---|
485 | #ifdef USE_TCP_SHT_CEP
|
---|
486 | if ((error = tcp_sht_cep(cepid)) != E_OK)
|
---|
487 | syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
|
---|
488 | apip, cepid, itron_strerror(error));
|
---|
489 | #endif /* of #ifdef USE_TCP_SHT_CEP */
|
---|
490 |
|
---|
491 | if ((error = tcp_cls_cep(cepid, CLS_TMO)) != E_OK)
|
---|
492 | syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
|
---|
493 | apip, cepid, itron_strerror(error));
|
---|
494 |
|
---|
495 | syscall(get_tim(&now));
|
---|
496 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
|
---|
497 | apip, cepid, now / SYSTIM_HZ, total);
|
---|
498 |
|
---|
499 | return error;
|
---|
500 | }
|
---|
501 |
|
---|
502 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
503 |
|
---|
504 | #endif /* of #ifndef USE_TCP_NON_BLOCKING */
|
---|
505 |
|
---|
506 | #ifndef USE_TCP_EXTENTIONS
|
---|
507 |
|
---|
508 | /*
|
---|
509 | * tcp_echo_srv_task -- TCP エコーサーバタスク
|
---|
510 | */
|
---|
511 |
|
---|
512 | void
|
---|
513 | tcp_echo_srv_task(intptr_t exinf)
|
---|
514 | {
|
---|
515 | ID tskid, cepid;
|
---|
516 | ER error;
|
---|
517 | uint_t six;
|
---|
518 | char apip;
|
---|
519 |
|
---|
520 | six = INDEX_SRV_INFO((ID)exinf);
|
---|
521 |
|
---|
522 | #if defined(SUPPORT_INET6)
|
---|
523 |
|
---|
524 | #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV)
|
---|
525 |
|
---|
526 | if (six >= NUM_TCP4_ECHO_SRV_TASKS)
|
---|
527 | apip = API_PROTO_IPV6;
|
---|
528 | else
|
---|
529 | apip = API_PROTO_IPV4;
|
---|
530 |
|
---|
531 | #else /* of #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
532 |
|
---|
533 | apip = API_PROTO_IPV6;
|
---|
534 |
|
---|
535 | #endif /* of #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
536 |
|
---|
537 | #else /* of #if defined(SUPPORT_INET6) */
|
---|
538 |
|
---|
539 | apip = API_PROTO_IPV4;
|
---|
540 |
|
---|
541 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
542 |
|
---|
543 | syscall(get_tid(&tskid));
|
---|
544 | cepid = tcp_echo_srv_info[six].cepid;
|
---|
545 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV:%d,%d] started.", apip, tskid, cepid);
|
---|
546 |
|
---|
547 | while (true) {
|
---|
548 | while ((error = tcp_echo_srv(six, apip)) == E_OK)
|
---|
549 | ;
|
---|
550 | syslog(LOG_NOTICE, "[TES%c:%02u TSK] sleep 60[s], error: %s", apip, cepid, itron_strerror(error));
|
---|
551 | tslp_tsk(60 * 1000 * 1000);
|
---|
552 | syslog(LOG_NOTICE, "[TES%c:%02u TSK] resume.", apip, cepid);
|
---|
553 | }
|
---|
554 | }
|
---|
555 |
|
---|
556 | #endif /* of #ifndef USE_TCP_EXTENTIONS */
|
---|
557 |
|
---|
558 | #endif /* of #ifdef USE_TCP_ECHO_SRV1 */
|
---|