source: EcnlProtoTool/trunk/asp3_dcre/tinet/netapp/tcp_echo_cli_rcv.c@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc
File size: 12.9 KB
Line 
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$
44 */
45
46/*
47 * TCP ECHO クライアント受信タスク
48 */
49
50#include <stdlib.h>
51
52#ifdef TARGET_KERNEL_ASP
53
54#include <kernel.h>
55#include <sil.h>
56#include <t_syslog.h>
57#include "kernel_cfg.h"
58#include "tinet_cfg.h"
59
60#endif /* of #ifdef TARGET_KERNEL_ASP */
61
62#ifdef TARGET_KERNEL_JSP
63
64#include <t_services.h>
65#include "kernel_id.h"
66#include "tinet_id.h"
67
68#endif /* of #ifdef TARGET_KERNEL_JSP */
69
70#include <netinet/in.h>
71#include <netinet/in_itron.h>
72
73#include <netapp/netapp.h>
74#include <netapp/netapp_var.h>
75#include <netapp/tcp_echo_cli.h>
76
77#ifdef USE_TCP_ECHO_CLI
78
79/* 表示 */
80
81//#define SHOW_TIME_OUT
82//#define SHOW_RCV_RANGE
83
84/* タイムアウト */
85
86#ifdef TOPPERS_S810_CLG3_85
87
88#define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */
89//#define RCV_TMO TMO_FEVR
90#define RCV_TMO (30*SYSTIM_HZ)
91
92#else /* of #ifdef TOPPERS_S810_CLG3_85 */
93
94//#define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */
95#define CLS_TMO (70*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*10)
96//#define RCV_TMO TMO_FEVR
97#define RCV_TMO (40*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*20)
98
99#endif /* of #ifdef TOPPERS_S810_CLG3_85 */
100
101/*
102 * API IPプロトコルの指定
103 */
104
105#undef DEFAULT_API_PROTO
106
107#if defined(SUPPORT_INET6)
108#if defined(SUPPORT_INET4)
109#define DEFAULT_API_PROTO API_PROTO_IPVn
110#else
111#define DEFAULT_API_PROTO API_PROTO_IPV6
112#endif
113#else
114#define DEFAULT_API_PROTO API_PROTO_IPV4
115#endif
116
117/*
118 * TCP ECHO クライアント受信タスク
119 */
120
121#ifdef USE_TCP_NON_BLOCKING
122
123#ifdef USE_COPYSAVE_API
124
125void
126tcp_echo_cli_rcv_task (intptr_t exinf)
127{
128 ID tskid, cepid;
129 ER error;
130 SYSTIM time;
131 uint32_t total, rcount;
132 uint16_t roff, rlen;
133 char *rmsg, head, tail, apip = DEFAULT_API_PROTO;
134
135 get_tid(&tskid);
136 syslog(LOG_NOTICE, "[TCP%c ECHO CLI (NBLK,CS) RCV:%d] started.", DEFAULT_API_PROTO, tskid);
137 while (true) {
138 if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {
139 syslog(LOG_NOTICE, "[TEC%c:%02u DTQ] error: %s",
140 DEFAULT_API_PROTO, cepid, itron_strerror(error));
141 }
142 else {
143
144#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
145
146#ifdef USE_TCP_EXTENTIONS
147
148 apip = API_PROTO_IPVn;
149
150#else /* of #ifdef USE_TCP_EXTENTIONS */
151
152 if (cepid == TCP4_ECHO_CLI_CEPID)
153 apip = API_PROTO_IPV4;
154 else
155 apip = API_PROTO_IPV6;
156
157#endif /* of #ifdef USE_TCP_EXTENTIONS */
158
159#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
160
161 roff = rcount = total = 0;
162 while (true) {
163 if ((error = tcp_rcv_buf(cepid, (void**)&rmsg, TMO_NBLK)) != E_WBLK) {
164 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] error: %s", apip, cepid, itron_strerror(error));
165 break;
166 }
167
168 /* 受信バッファの獲得が完了するまで待
169つ。*/
170 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
171 if (tcp_echo_cli_nblk_error < 0)
172 break;
173
174 rlen = tcp_echo_cli_nblk_error;
175 head = *rmsg;
176 tail = *(rmsg + rlen - 1);
177 if (rlen > 0) {
178 roff += rlen;
179 total += rlen;
180 rcount ++;
181#ifdef SHOW_RCV_RANGE
182 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] "
183 "count: %7lu, len: %4u, off: %4u, data: %02x -> %02x",
184 apip, cepid, rcount, rlen, roff, head, tail);
185#endif /* of #ifdef SHOW_RCV_RANGE */
186 }
187 else
188 break;
189
190 if ((error = tcp_rel_buf(cepid, rlen)) != E_OK)
191 syslog(LOG_NOTICE, "[TEC%c:%02u REL] error: %s",
192 apip, cepid, itron_strerror(error));
193 }
194
195 if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK && error != E_OK)
196 syslog(LOG_NOTICE, "[TEC%c:%02u CLS] error: %s", apip, cepid, itron_strerror(error));
197
198 /* 切断が完了するまで待
199つ。*/
200 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
201
202 get_tim(&time);
203 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] finsh: %7lu, ttl: %lu",
204 apip, cepid, time / SYSTIM_HZ, total);
205 }
206
207 syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));
208 }
209 }
210
211#else /* of #ifdef USE_COPYSAVE_API */
212
213void
214tcp_echo_cli_rcv_task (intptr_t exinf)
215{
216 static char rmsg[RCV_BUF_SIZE];
217
218 ID tskid, cepid;
219 ER error;
220 SYSTIM time;
221 uint32_t total, rcount;
222 uint16_t roff, rlen;
223 char head, tail, apip = DEFAULT_API_PROTO;
224
225 get_tid(&tskid);
226 syslog(LOG_NOTICE, "[TCP%c ECHO CLI (NBLK) RCV:%d] started.", DEFAULT_API_PROTO, tskid);
227 while (true) {
228 if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {
229 syslog(LOG_NOTICE, "[TEC%c:%02u DTQ] error: %s",
230 DEFAULT_API_PROTO, cepid, itron_strerror(error));
231 }
232 else {
233
234#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
235
236 if (cepid == TCP4_ECHO_CLI_CEPID)
237 apip = API_PROTO_IPV4;
238 else
239 apip = API_PROTO_IPV6;
240
241#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
242
243 roff = rcount = total = 0;
244 while (true) {
245 if ((error = tcp_rcv_dat(cepid, rmsg, sizeof(rmsg), TMO_NBLK)) != E_WBLK) {
246 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] error: %s", apip, cepid, itron_strerror(error));
247 break;
248 }
249
250 /* 受信が完了するまで待
251つ。*/
252 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
253 if (tcp_echo_cli_nblk_error < 0)
254 break;
255
256 rlen = tcp_echo_cli_nblk_error;
257 head = *rmsg;
258 tail = *(rmsg + rlen - 1);
259 rcount ++;
260 if (rlen > 0) {
261 roff += rlen;
262 total += rlen;
263#ifdef SHOW_RCV_RANGE
264 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] "
265 "count: %7lu, len: %4u, off: %4u, data: %02x -> %02x",
266 apip, cepid, rcount, rlen, roff, head, tail);
267#endif /* of #ifdef SHOW_RCV_RANGE */
268 }
269 else
270 break;
271 }
272
273 if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK && error != E_OK)
274 syslog(LOG_NOTICE, "[TEC%c:%02u CLS] error: %s", apip, cepid, itron_strerror(error));
275
276 /* 切断が完了するまで待
277つ。*/
278 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
279
280 get_tim(&time);
281 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] finsh: %7lu, ttl: %lu",
282 apip, cepid, time / SYSTIM_HZ, total);
283 }
284
285 syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));
286 }
287 }
288
289#endif /* of #ifdef USE_COPYSAVE_API */
290
291#else /* of #ifdef USE_TCP_NON_BLOCKING */
292
293#ifdef USE_COPYSAVE_API
294
295void
296tcp_echo_cli_rcv_task (intptr_t exinf)
297{
298 ID tskid, cepid;
299 ER_UINT rlen;
300 ER error;
301 SYSTIM time, tmo;
302 uint32_t total = 0, rcount;
303 uint16_t roff;
304 char *rmsg, apip = DEFAULT_API_PROTO;
305
306 get_tid(&tskid);
307 syslog(LOG_NOTICE, "[TCP%c ECHO CLI (CS) RCV:%d] started.", DEFAULT_API_PROTO, tskid);
308 while (true) {
309 if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {
310 syslog(LOG_NOTICE, "[TEC%c:%02u DTQ] error: %s",
311 DEFAULT_API_PROTO, cepid, itron_strerror(error));
312
313#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
314
315#ifdef USE_TCP_EXTENTIONS
316
317 if (tcp6_is_cepid(cepid))
318 apip = API_PROTO_IPV6;
319 else
320 apip = API_PROTO_IPV4;
321
322#else /* of #ifdef USE_TCP_EXTENTIONS */
323
324 if (cepid == TCP4_ECHO_CLI_CEPID)
325 apip = API_PROTO_IPV4;
326 else
327 apip = API_PROTO_IPV6;
328
329#endif /* of #ifdef USE_TCP_EXTENTIONS */
330
331#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
332
333 }
334 else {
335 roff = rcount = total = 0;
336 while (true) {
337 tmo = RCV_TMO;
338#ifdef SHOW_TIME_OUT
339 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] tmo: %7lu", apip, cepid, tmo);;
340#endif /* of #ifdef SHOW_TIME_OUT */
341 if ((rlen = tcp_rcv_buf(cepid, (void**)&rmsg, tmo)) < 0) {
342 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] error: %s",
343 apip, cepid, itron_strerror(rlen));
344 break;
345 }
346 else if (rlen > 0) {
347 roff += (uint16_t)rlen;
348 total += rlen;
349 rcount ++;
350#ifdef SHOW_RCV_RANGE
351 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] count: %7lu, len: %4u, data: %02x -> %02x",
352 apip, cepid, rcount, (uint16_t)rlen, *rmsg, *(rmsg + rlen - 1));
353#endif /* of #ifdef SHOW_RCV_RANGE */
354 }
355 else
356 break;
357 if ((error = tcp_rel_buf(cepid, rlen)) != E_OK)
358 syslog(LOG_NOTICE, "[TEC%c:%02u REL] error: %s", apip, cepid, itron_strerror(error));
359 }
360
361 tmo = CLS_TMO;
362#ifdef SHOW_TIME_OUT
363 syslog(LOG_NOTICE, "[TEC%c:%02u CLS] tmo: %7lu", apip, cepid, tmo);;
364#endif /* of #ifdef SHOW_TIME_OUT */
365 if ((error = tcp_cls_cep(cepid, tmo)) < 0)
366 syslog(LOG_NOTICE, "[TEC%c:%02u CLS] error: %s", apip, cepid, itron_strerror(error));
367
368 get_tim(&time);
369 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] finsh: %7lu, ttl: %lu",
370 apip, cepid, time / SYSTIM_HZ, total);
371 }
372
373 syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));
374 }
375 }
376
377#else /* of #ifdef USE_COPYSAVE_API */
378
379void
380tcp_echo_cli_rcv_task (intptr_t exinf)
381{
382 static char rmsg[RCV_BUF_SIZE];
383
384 ID tskid, cepid;
385 ER_UINT rlen;
386 ER error;
387 SYSTIM time, tmo;
388 uint32_t total, rcount;
389 uint16_t roff;
390 char apip = DEFAULT_API_PROTO;
391
392 get_tid(&tskid);
393 syslog(LOG_NOTICE, "[TCP%c ECHO CLI RCV:%d] started.", DEFAULT_API_PROTO, tskid);
394 while (true) {
395 if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {
396 syslog(LOG_NOTICE, "[TEC%c:%02u DTQ] error: %s",
397 DEFAULT_API_PROTO, cepid, itron_strerror(error));
398 }
399 else {
400
401#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
402
403 if (cepid == TCP4_ECHO_CLI_CEPID)
404 apip = API_PROTO_IPV4;
405 else
406 apip = API_PROTO_IPV6;
407
408#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
409
410 roff = rcount = total = 0;
411 while (true) {
412#ifdef SHOW_TIME_OUT
413 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] tmo: %7lu", apip, cepid, tmo);;
414#endif /* of #ifdef SHOW_TIME_OUT */
415 tmo = RCV_TMO;
416 if ((rlen = tcp_rcv_dat(cepid, rmsg, sizeof(rmsg), tmo)) < 0) {
417 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] error: %s", apip, cepid, itron_strerror(rlen));
418 tcp_can_cep(cepid, TFN_TCP_ALL);
419 break;
420 }
421 else if (rlen > 0) {
422 roff += (uint16_t)rlen;
423 total += rlen;
424 rcount ++;
425#ifdef SHOW_RCV_RANGE
426 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] count: %7lu, len: %4u, data: %02x -> %02x",
427 apip, cepid, rcount, (uint16_t)rlen, *rmsg, *(rmsg + rlen - 1));
428#endif /* of #ifdef SHOW_RCV_RANGE */
429 }
430 else
431 break;
432 }
433
434#ifdef SHOW_TIME_OUT
435 syslog(LOG_NOTICE, "[TEC%c:%02u CLS] tmo: %7lu", apip, cepid, tmo);;
436#endif /* of #ifdef SHOW_TIME_OUT */
437 tmo = CLS_TMO;
438 if ((error = tcp_cls_cep(cepid, tmo)) < 0)
439 syslog(LOG_NOTICE, "[TEC%c:%02u CLS] error: %s", apip, cepid, itron_strerror(error));
440
441 get_tim(&time);
442 syslog(LOG_NOTICE, "[TEC%c:%02u RCV] finsh: %7lu, ttl: %lu",
443 apip, cepid, time / SYSTIM_HZ, total);
444 }
445
446 syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));
447 }
448 }
449
450#endif /* of #ifdef USE_COPYSAVE_API */
451
452#endif /* of #ifdef USE_TCP_NON_BLOCKING */
453
454#endif /* of #ifdef USE_TCP_ECHO_CLI */
Note: See TracBrowser for help on using the repository browser.