source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netapp/tcp_echo_cli_rcv.c@ 352

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

arm向けASP3版ECNLを追加

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