Changeset 331 for EcnlProtoTool/trunk/asp3_dcre/tinet/netapp/tcp_echo_cli.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/asp3_dcre/tinet/netapp/tcp_echo_cli.c
r321 r331 2 2 * TINET (TCP/IP Protocol Stack) 3 3 * 4 * Copyright (C) 2001-20 09by Dep. of Computer Science and Engineering4 * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering 5 5 * Tomakomai National College of Technology, JAPAN 6 6 * … … 50 50 #include <t_syslog.h> 51 51 #include "kernel_cfg.h" 52 #include "tinet_cfg.h" 52 53 53 54 #endif /* of #ifdef TARGET_KERNEL_ASP */ … … 57 58 #include <t_services.h> 58 59 #include "kernel_id.h" 60 #include "tinet_id.h" 59 61 60 62 #endif /* of #ifdef TARGET_KERNEL_JSP */ 61 62 #include <tinet_defs.h>63 #include <tinet_config.h>64 65 #include <net/if.h>66 #include <net/if_ppp.h>67 #include <net/if_loop.h>68 #include <net/net.h>69 #include <net/ethernet.h>70 #include <net/net_var.h>71 #include <net/net_timer.h>72 63 73 64 #include <netinet/in.h> 74 65 #include <netinet/in_itron.h> 75 #include <netinet/ip.h>76 #include <netinet/ip6.h>77 #include <netinet/tcp.h>78 66 79 67 #include <netapp/netapp.h> 80 68 #include <netapp/netapp_var.h> 81 #include <netapp/ echo.h>69 #include <netapp/tcp_echo_cli.h> 82 70 83 71 #ifdef USE_TCP_ECHO_CLI … … 96 84 #endif /* of #ifdef USE_TCP_EXTENTIONS */ 97 85 98 /* 表示 */99 100 //#define SHOW_RCV_RANGE101 102 /* タイムアウト */103 104 #define CON_TMO TMO_FEVR105 //#define CON_TMO (60*SYSTIM_HZ)106 //#define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */107 #define CLS_TMO (70*SYSTIM_HZ+(net_rand()%SYSTIM_HZ)*10)108 //#define RCV_TMO TMO_FEVR109 #define RCV_TMO (40*SYSTIM_HZ+(net_rand()%SYSTIM_HZ)*20)110 //#define SND_TMO TMO_FEVR111 #define SND_TMO (30*SYSTIM_HZ+(net_rand()%SYSTIM_HZ)*30)112 113 86 /* 送信間隔 */ 114 87 115 //#define SND_DLY ULONG_C(500) 116 #define SND_ITV (5*SYSTM_HZ) 88 #ifdef TOPPERS_S810_CLG3_85 89 90 //#define SND_DLY (500) 91 #define START_DLY (10*SYSTIM_HZ) 92 #define SND_ITV (5*SYSTIM_HZ) 93 #define SLP_ITV (30*SYSTIM_HZ) 94 95 #else /* of #ifdef TOPPERS_S810_CLG3_85 */ 96 97 //#define SND_DLY (500) 98 #define START_DLY (10*SYSTIM_HZ) 99 #define SND_ITV (5*SYSTIM_HZ) 117 100 #define SLP_ITV (60*SYSTIM_HZ) 118 101 102 #endif /* of #ifdef TOPPERS_S810_CLG3_85 */ 103 119 104 /* 自動実行 */ 120 105 106 #if defined(TCP_ECHO_CLI_AUTO_RUN_STR) 107 #else 121 108 #if 0 122 109 #if defined(SUPPORT_INET6) 123 #define AUTO_RUN_STR "fe80::211:2fff:fe8a:e8c0- 0"124 #else 125 #define AUTO_RUN_STR "172.25.193.140 - 0"126 #endif 127 #endif 128 129 /* 130 * バッファサイズの定義 131 */ 132 133 # define NUM_ECHO 20134 #define NUM_REP_PAT 20135 # define PAT_BEGIN ' '136 # define PAT_END '~'137 #define SND_BUF_SIZE ((PAT_END - PAT_BEGIN + 1) * NUM_REP_PAT)138 # define RCV_BUF_SIZE (SND_BUF_SIZE*15/10)110 #define TCP_ECHO_CLI_AUTO_RUN_STR "fd90:cce5:25f6:ff81:201:2ff:fe81:e7c9 - 0" 111 #else 112 #define TCP_ECHO_CLI_AUTO_RUN_STR "172.25.129.140 - 0" 113 #endif 114 #endif 115 #endif 116 117 #if defined(SUPPORT_INET6) 118 #if defined(SUPPORT_INET4) 119 #define API_PROTO 'n' 120 #else 121 #define API_PROTO '6' 122 #endif 123 #else 124 #define API_PROTO '4' 125 #endif 139 126 140 127 /* … … 142 129 */ 143 130 144 bool_t tcp_echo_cli_valid; 131 bool_t tcp_echo_cli_valid; 132 uint_t tcp_echo_cli_scount; 145 133 146 134 /* TCP 送受信ウィンドバッファ */ … … 154 142 #endif 155 143 156 /*157 * 変数158 */159 160 static uint_t scount;161 static uint_t rcount;162 163 144 #ifdef USE_TCP_NON_BLOCKING 164 145 165 static T_IPEP nblk_src = { 166 IP_ADDRANY, 167 TCP_PORTANY, 168 }; 169 static T_IPEP nblk_dst; 170 static ER_UINT nblk_error; 146 /* 147 * 全域変数 148 */ 149 150 ER_UINT tcp_echo_cli_nblk_error; 171 151 172 152 /* … … 179 159 ER error = E_OK; 180 160 181 nblk_error = *(ER*)p_parblk;161 tcp_echo_cli_nblk_error = *(ER*)p_parblk; 182 162 183 163 switch (fncd) { … … 188 168 189 169 case TFN_TCP_RCV_BUF: 190 if (nblk_error < 0) 191 syslog(LOG_NOTICE, "[TEC:%02d CBN] rcv buf error: %s", cepid, itron_strerror(nblk_error)); 170 if (tcp_echo_cli_nblk_error < 0) 171 syslog(LOG_NOTICE, "[TEC%c:%02u CBN] error: %s", 172 API_PROTO, cepid, itron_strerror(tcp_echo_cli_nblk_error)); 192 173 syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY)); 193 174 break; 194 175 195 176 case TFN_TCP_CLS_CEP: 196 if (nblk_error < 0) 197 syslog(LOG_NOTICE, "[TEC:%02d CBN] close error: %s", cepid, itron_strerror(nblk_error)); 177 if (tcp_echo_cli_nblk_error < 0) 178 syslog(LOG_NOTICE, "[TEC%c:%02u CBN] error: %s", 179 API_PROTO, cepid, itron_strerror(tcp_echo_cli_nblk_error)); 198 180 syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY)); 199 181 break; 200 182 201 183 case TFN_TCP_RCV_DAT: 202 if (nblk_error < 0) 203 syslog(LOG_NOTICE, "[TEC:%02d CBN] rcv dat error: %s", cepid, itron_strerror(nblk_error)); 184 if (tcp_echo_cli_nblk_error < 0) 185 syslog(LOG_NOTICE, "[TEC%c:%02u CBN] error: %s", 186 API_PROTO, cepid, itron_strerror(tcp_echo_cli_nblk_error)); 204 187 syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY)); 205 188 break; 206 189 207 190 case TFN_TCP_SND_OOB: 208 if (nblk_error > 0) 209 syslog(LOG_NOTICE, "[TEC:%02d CBN] snd urg: %4d", cepid, nblk_error); 191 if (tcp_echo_cli_nblk_error > 0) 192 syslog(LOG_NOTICE, "[TEC%c:%02u CBN] snd urg: %4u", 193 API_PROTO, cepid, tcp_echo_cli_nblk_error); 210 194 else 211 syslog(LOG_NOTICE, "[TEC:%02d CBN] snd urg error: %s", cepid, itron_strerror(nblk_error)); 195 syslog(LOG_NOTICE, "[TEC%c:%02u CBN] error: %s", 196 API_PROTO, cepid, itron_strerror(tcp_echo_cli_nblk_error)); 212 197 break; 213 198 … … 222 207 } 223 208 224 /*225 * send_tcp_echo -- ECHO/TCP サーバにメッセージを送信する。226 */227 228 static ER229 send_tcp_echo (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)230 {231 static char smsg[SND_BUF_SIZE];232 233 ER_UINT slen;234 ER error;235 SYSTIM time;236 uint32_t total;237 uint16_t soff, echo, rep;238 char *p, pat;239 240 #ifdef SND_URG_DATA_SIZE241 int_t urg = SND_URG_COUNT;242 #endif243 244 nblk_dst.ipaddr = *ipaddr;245 nblk_dst.portno = portno;246 247 p = smsg;248 for (rep = NUM_REP_PAT; rep -- > 0; )249 for (pat = PAT_BEGIN; pat <= PAT_END; pat ++)250 *p ++ = pat;251 252 if ((error = TCP_CON_CEP(cepid, &nblk_src, &nblk_dst, TMO_NBLK)) != E_WBLK) {253 syslog(LOG_NOTICE, "[TEC:%02d SND] connect error: %s", cepid, itron_strerror(error));254 return error;255 }256 257 /* 接続が完了するまで待つ。*/258 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));259 260 if (nblk_error != E_OK)261 syslog(LOG_NOTICE, "[TEC:%02d SND] connect error: %s", cepid, itron_strerror(nblk_error));262 else {263 get_tim(&time);264 syslog(LOG_NOTICE, "[TEC:%02d SND] connecting: %6lu, to: %s.%u",265 cepid, time / SYSTIM_HZ, IP2STR(NULL, ipaddr), nblk_dst.portno);266 267 if ((error = psnd_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t)cepid)) != E_OK) {268 syslog(LOG_NOTICE, "[TEC:%02d SND] sync error: %s", cepid, itron_strerror(error));269 goto cls_ret;270 }271 272 scount = total = 0;273 for (echo = NUM_ECHO; echo -- > 0; ) {274 soff = 0;275 while (soff < SND_BUF_SIZE) {276 if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, SND_TMO)) < 0) {277 syslog(LOG_NOTICE, "[TEC:%02d SND] snd dat error: %s",278 cepid, itron_strerror(slen));279 goto cls_ret;280 }281 soff += (uint16_t)slen;282 total += slen;283 scount ++;284 #ifdef SHOW_RCV_RANGE285 syslog(LOG_NOTICE, "[TEC:%02d SND] send cnt: %2d, len: %4d, off: %4d",286 cepid, scount, (uint16_t)slen, soff);287 #endif /* of #ifdef SHOW_RCV_RANGE */288 289 #ifdef SND_URG_DATA_SIZE290 if (urg) {291 if (urg == 1) {292 if ((error = tcp_snd_oob(cepid, smsg, SND_URG_DATA_SIZE, TMO_NBLK)) != E_WBLK)293 syslog(LOG_NOTICE, "[TEC:%02d SND] snd urg error: %s",294 cepid, itron_strerror(error));295 }296 urg --;297 }298 #endif /* of #ifdef SND_URG_DATA_SIZE */299 300 #if SND_DLY > 0301 syscall(dly_tsk(SND_DLY + net_rand() % SYSTIM_HZ));302 #endif303 }304 }305 306 cls_ret:307 if ((error = tcp_sht_cep(cepid)) < 0)308 syslog(LOG_NOTICE, "[TEC:%02d SND] shutdown error: %s", cepid, itron_strerror(error));309 310 /* 受信が完了するまで待つ。*/311 syscall(slp_tsk());312 }313 314 return error;315 }316 317 /*318 * TCP ECHO クライアント受信タスク319 */320 321 #ifdef USE_COPYSAVE_API322 323 void324 tcp_echo_cli_rcv_task (intptr_t exinf)325 {326 ID tskid, cepid;327 ER error;328 SYSTIM time;329 uint32_t total;330 uint16_t roff, rlen;331 char *rmsg, head, tail;332 333 get_tid(&tskid);334 syslog(LOG_NOTICE, "[TCP ECHO CLI (NBLK,CS) RCV:%d] started.", tskid);335 while (true) {336 if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {337 syslog(LOG_NOTICE, "[TEC:%02d RCV] sync error: %s",338 cepid, itron_strerror(error));339 }340 else {341 roff = rcount = total = 0;342 while (true) {343 if ((error = tcp_rcv_buf(cepid, (void**)&rmsg, TMO_NBLK)) != E_WBLK) {344 syslog(LOG_NOTICE, "[TEC:%02d RCV] rcv buf error: %s", cepid, itron_strerror(error));345 break;346 }347 348 /* 受信バッファの獲得が完了するまで待つ。*/349 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));350 if (nblk_error < 0)351 break;352 353 rlen = nblk_error;354 head = *rmsg;355 tail = *(rmsg + rlen - 1);356 if (rlen > 0) {357 roff += rlen;358 total += rlen;359 rcount ++;360 #ifdef SHOW_RCV_RANGE361 syslog(LOG_NOTICE, "[TEC:%02d RCV] "362 "recv cnt: %2d, len: %4d, off: %4d, data: %02x -> %02x",363 cepid, rcount, rlen, roff, head, tail);364 #endif /* of #ifdef SHOW_RCV_RANGE */365 }366 else367 break;368 369 if ((error = tcp_rel_buf(cepid, rlen)) != E_OK)370 syslog(LOG_NOTICE, "[TEC:%02d RCV] rel buf error: %s",371 cepid, itron_strerror(error));372 }373 374 if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK && error != E_OK)375 syslog(LOG_NOTICE, "[TEC:%02d SND] close error: %s", cepid, itron_strerror(error));376 377 /* 切断が完了するまで待つ。*/378 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));379 380 get_tim(&time);381 syslog(LOG_NOTICE, "[TEC:%02u RCV] finished: %6lu, snd: %4u, rcv: %4u, len: %u",382 cepid, time / SYSTIM_HZ, scount, rcount, total);383 }384 385 syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));386 }387 }388 389 #else /* of #ifdef USE_COPYSAVE_API */390 391 void392 tcp_echo_cli_rcv_task (intptr_t exinf)393 {394 static char rmsg[RCV_BUF_SIZE];395 396 ID tskid, cepid;397 ER error;398 SYSTIM time;399 uint32_t total;400 uint16_t roff, rlen;401 char head, tail;402 403 get_tid(&tskid);404 syslog(LOG_NOTICE, "[TCP ECHO CLI (NBLK) RCV:%d] started.", tskid);405 while (true) {406 if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {407 syslog(LOG_NOTICE, "[TEC:%02d RCV] sync error: %s",408 cepid, itron_strerror(error));409 }410 else {411 roff = rcount = total = 0;412 while (true) {413 if ((error = tcp_rcv_dat(cepid, rmsg, sizeof(rmsg), TMO_NBLK)) != E_WBLK) {414 syslog(LOG_NOTICE, "[TEC:%02d RCV] rcv error: %s", cepid, itron_strerror(error));415 break;416 }417 418 /* 受信が完了するまで待つ。*/419 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));420 if (nblk_error < 0)421 break;422 423 rlen = nblk_error;424 head = *rmsg;425 tail = *(rmsg + rlen - 1);426 rcount ++;427 if (rlen > 0) {428 roff += rlen;429 total += rlen;430 #ifdef SHOW_RCV_RANGE431 syslog(LOG_NOTICE, "[TEC:%02d RCV] "432 "recv cnt: %2d, len: %4d, off: %4d, data: %02x -> %02x",433 cepid, rcount, rlen, roff, head, tail);434 #endif /* of #ifdef SHOW_RCV_RANGE */435 }436 else437 break;438 }439 440 if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK && error != E_OK)441 syslog(LOG_NOTICE, "[TEC:%02d SND] close error: %s", cepid, itron_strerror(error));442 443 /* 切断が完了するまで待つ。*/444 syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));445 446 get_tim(&time);447 syslog(LOG_NOTICE, "[TEC:%02u RCV] finished: %6lu, snd: %4u, rcv: %4u, len: %u",448 cepid, time / SYSTIM_HZ, scount, rcount, total);449 }450 451 syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));452 }453 }454 455 #endif /* of #ifdef USE_COPYSAVE_API */456 457 #else /* of #ifdef USE_TCP_NON_BLOCKING */458 459 /*460 * send_tcp_echo -- ECHO/TCP サーバにメッセージを送信する。461 */462 463 static ER464 send_tcp_echo (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)465 {466 static char smsg[SND_BUF_SIZE];467 static T_IPEP src = {468 IP_ADDRANY,469 TCP_PORTANY,470 };471 472 T_IPEP dst;473 ER_UINT slen;474 ER error;475 SYSTIM time;476 uint32_t total;477 uint16_t soff, echo, rep;478 char pat, *p;479 480 #ifdef SND_URG_DATA_SIZE481 int_t urg = SND_URG_COUNT;482 #endif483 484 dst.ipaddr = *ipaddr;485 dst.portno = portno;486 487 p = smsg;488 for (rep = NUM_REP_PAT; rep -- > 0; )489 for (pat = PAT_BEGIN; pat <= PAT_END; pat ++)490 *p ++ = pat;491 492 if ((error = TCP_CON_CEP(cepid, &src, &dst, CON_TMO)) != E_OK) {493 syslog(LOG_NOTICE, "[TEC:%02d SND] connect error: %s", cepid, itron_strerror(error));494 return error;495 }496 497 get_tim(&time);498 syslog(LOG_NOTICE, "[TEC:%02u SND] connecting: %6lu, to: %s.%u",499 cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);500 501 if ((error = psnd_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t)cepid)) != E_OK) {502 syslog(LOG_NOTICE, "[TEC:%02d SND] sync error: %s", cepid, itron_strerror(error));503 goto cls_ret;504 }505 506 scount = total = 0;507 for (echo = NUM_ECHO; echo -- > 0; ) {508 soff = 0;509 while (soff < SND_BUF_SIZE) {510 if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, SND_TMO)) < 0) {511 syslog(LOG_NOTICE, "[TEC:%02d SND] snd dat error: %s", cepid, itron_strerror(slen));512 goto cls_ret;513 }514 soff += (uint16_t)slen;515 total += slen;516 scount ++;517 #ifdef SHOW_RCV_RANGE518 syslog(LOG_NOTICE, "[TEC:%02d SND] send count: %3d, len: %4d, offset: %4d",519 cepid, scount, (uint16_t)slen, soff);520 #endif /* of #ifdef SHOW_RCV_RANGE */521 522 #ifdef SND_URG_DATA_SIZE523 if (urg > 0) {524 if (urg == 1) {525 if ((slen = tcp_snd_oob(cepid, smsg, SND_URG_DATA_SIZE, SND_TMO)) >= 0)526 syslog(LOG_NOTICE, "[TEC:%02d SND] snd urg: %4d",527 cepid, (uint16_6)slen);528 else529 syslog(LOG_NOTICE, "[TEC:%02d SND] snd urg error: %s",530 cepid, itron_strerror(slen));531 }532 urg --;533 }534 #endif /* of #ifdef SND_URG_DATA_SIZE */535 536 #if SND_DLY > 0537 syscall(dly_tsk(SND_DLY + net_rand() % SYSTIM_HZ));538 #endif539 }540 }541 542 cls_ret:543 if ((error = tcp_sht_cep(cepid)) < 0)544 syslog(LOG_NOTICE, "[TEC:%02d SND] shutdown error: %s", cepid, itron_strerror(error));545 546 /* 受信が完了するまで待つ。*/547 syscall(slp_tsk());548 549 return error;550 }551 552 /*553 * TCP ECHO クライアント受信タスク554 */555 556 #ifdef USE_COPYSAVE_API557 558 void559 tcp_echo_cli_rcv_task (intptr_t exinf)560 {561 ID tskid, cepid;562 ER_UINT rlen;563 ER error;564 SYSTIM time;565 uint32_t total;566 uint16_t roff;567 char *rmsg;568 569 get_tid(&tskid);570 syslog(LOG_NOTICE, "[TCP ECHO CLI (CS) RCV:%d] started.", tskid);571 while (true) {572 if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {573 syslog(LOG_NOTICE, "[TEC:%02d RCV] sync error: %s",574 cepid, itron_strerror(error));575 }576 else {577 roff = rcount = total = 0;578 while (true) {579 if ((rlen = tcp_rcv_buf(cepid, (void**)&rmsg, RCV_TMO)) < 0) {580 syslog(LOG_NOTICE, "[TEC:%02d RCV] rcv buf error: %s",581 cepid, itron_strerror(rlen));582 break;583 }584 else if (rlen > 0) {585 roff += (uint16_t)rlen;586 total += rlen;587 rcount ++;588 #ifdef SHOW_RCV_RANGE589 syslog(LOG_NOTICE, "[TEC:%02d RCV] recv count: %3d, len: %4d, data: %02x -> %02x",590 cepid, rcount, (uint16_t)rlen, *rmsg, *(rmsg + rlen - 1));591 #endif /* of #ifdef SHOW_RCV_RANGE */592 }593 else594 break;595 if ((error = tcp_rel_buf(cepid, rlen)) != E_OK)596 syslog(LOG_NOTICE, "[TEC:%02d RCV] rel buf error: %s", cepid, itron_strerror(error));597 }598 599 if ((error = tcp_cls_cep(cepid, CLS_TMO)) < 0)600 syslog(LOG_NOTICE, "[TEC:%02d RCV] close error: %s", cepid, itron_strerror(error));601 602 get_tim(&time);603 syslog(LOG_NOTICE, "[TEC:%02u RCV] finished: %6lu, snd: %4u, rcv: %4u, len: %u",604 cepid, time / SYSTIM_HZ, scount, rcount, total);605 }606 607 syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));608 }609 }610 611 #else /* of #ifdef USE_COPYSAVE_API */612 613 void614 tcp_echo_cli_rcv_task (intptr_t exinf)615 {616 static char rmsg[RCV_BUF_SIZE];617 618 ID tskid, cepid;619 ER_UINT rlen;620 ER error;621 SYSTIM time;622 uint32_t total;623 uint16_t roff;624 625 get_tid(&tskid);626 syslog(LOG_NOTICE, "[TCP ECHO CLI RCV:%d] started.", tskid);627 while (true) {628 if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {629 syslog(LOG_NOTICE, "[TEC:%02d RCV] sync error: %s",630 cepid, itron_strerror(error));631 }632 else {633 roff = rcount = total = 0;634 while (true) {635 if ((rlen = tcp_rcv_dat(cepid, rmsg, sizeof(rmsg), RCV_TMO)) < 0) {636 syslog(LOG_NOTICE, "[TEC:%02d RCV] rcv dat error: %s", cepid, itron_strerror(rlen));637 tcp_can_cep(cepid, TFN_TCP_ALL);638 break;639 }640 else if (rlen > 0) {641 roff += (uint16_t)rlen;642 total += rlen;643 rcount ++;644 #ifdef SHOW_RCV_RANGE645 syslog(LOG_NOTICE, "[TEC:%02d RCV] recv count: %3d, len: %4d, data: %02x -> %02x",646 cepid, rcount, (uint16_t)rlen, *rmsg, *(rmsg + rlen - 1));647 #endif /* of #ifdef SHOW_RCV_RANGE */648 }649 else650 break;651 }652 653 if ((error = tcp_cls_cep(cepid, CLS_TMO)) < 0)654 syslog(LOG_NOTICE, "[TEC:%02d RCV] close error: %s", cepid, itron_strerror(error));655 656 get_tim(&time);657 syslog(LOG_NOTICE, "[TEC:%02u RCV] received: %6lu, snd: %4u, rcv: %4u, len: %u",658 cepid, time / SYSTIM_HZ, scount, rcount, total);659 }660 661 syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));662 }663 }664 665 #endif /* of #ifdef USE_COPYSAVE_API */666 667 209 #endif /* of #ifdef USE_TCP_NON_BLOCKING */ 668 210 … … 671 213 */ 672 214 673 #ifdef AUTO_RUN_STR215 #ifdef TCP_ECHO_CLI_AUTO_RUN_STR 674 216 675 217 static char * 676 getcomd (ID cepid )218 getcomd (ID cepid, bool_t retry, char *apip) 677 219 { 678 220 ER error; 679 221 char *line = NULL; 680 static char auto_run_str[] = AUTO_RUN_STR;222 static char auto_run_str[] = TCP_ECHO_CLI_AUTO_RUN_STR; 681 223 static int_t count = 0; 682 224 683 if ( count == 0) {225 if (retry || (count == 0)) { 684 226 line = auto_run_str; 685 227 dly_tsk(3 * 1000); … … 687 229 else { 688 230 while ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_SND, (intptr_t*)&line)) != E_OK) { 689 syslog(LOG_NOTICE, "[TEC :%02d TSK] error: %s", cepid, itron_strerror(error));231 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", API_PROTO, cepid, itron_strerror(error)); 690 232 dly_tsk(SLP_ITV); 691 233 } … … 696 238 } 697 239 698 #else /* of #ifdef AUTO_RUN_STR */240 #else /* of #ifdef TCP_ECHO_CLI_AUTO_RUN_STR */ 699 241 700 242 static char * 701 getcomd (ID cepid )243 getcomd (ID cepid, bool_t retry, char *apip) 702 244 { 703 245 ER error; … … 705 247 706 248 while ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_SND, (intptr_t*)&line)) != E_OK) { 707 syslog(LOG_NOTICE, "[TEC :%02d TSK] error: %s", cepid, itron_strerror(error));249 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", API_PROTO, cepid, itron_strerror(error)); 708 250 dly_tsk(SLP_ITV); 709 251 } 252 253 #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) 254 255 if (*line == '6') { 256 line ++; 257 *apip = API_PROTO_IPV6; 258 } 259 else if (*line == '4') { 260 line ++; 261 *apip = API_PROTO_IPV4; 262 } 263 else { 264 *apip= DEFAULT_API_PROTO; 265 if (*line && *line != ' ') 266 line ++; 267 } 268 269 #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */ 270 271 *apip= DEFAULT_API_PROTO; 272 if (*line && *line != ' ') 273 line ++; 274 275 #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */ 276 710 277 return line; 711 278 } 712 279 713 #endif /* of #ifdef AUTO_RUN_STR */280 #endif /* of #ifdef TCP_ECHO_CLI_AUTO_RUN_STR */ 714 281 715 282 /* 716 283 * TCP ECHO クライアント送信タスク 717 284 */ 285 286 /* 287 * IP アドレスの指定 288 */ 289 290 #define ADDR_IPVn 'n' 291 #define ADDR_IPV6 '6' 292 #define ADDR_IPV4 '4' 718 293 719 294 void … … 723 298 ER error; 724 299 T_IN_ADDR addr; 300 char *line; 301 int_t rep, count; 302 bool_t retry = false; 725 303 uint16_t portno; 726 int_t rep, count; 727 char *line; 304 char apip; 728 305 729 306 #ifdef USE_TCP_EXTENTIONS … … 733 310 #endif /* of #ifdef USE_TCP_EXTENTIONS */ 734 311 312 #ifdef TCP_ECHO_CLI_AUTO_RUN_STR 313 dly_tsk(START_DLY); 314 #endif 735 315 get_tid(&tskid); 736 syslog(LOG_NOTICE, "[TCP ECHO CLI SND:%d,%d] started.", tskid, (ID)exinf);316 syslog(LOG_NOTICE, "[TCP%c ECHO CLI SND:%d,%d] started.", DEFAULT_API_PROTO, tskid, (ID)exinf); 737 317 while (true) { 738 line = getcomd((ID)exinf); 739 line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line))); /* IP Address */ 740 741 if ('0' <= *line && *line <= '9') { /* Port No */ 318 line = skip_blanks(getcomd((ID)exinf, retry, &apip)); 319 320 #if defined(SUPPORT_INET6) && !defined(SUPPORT_INET4) && !defined(API_CFG_IP4MAPPED_ADDR) 321 322 if (apip == API_PROTO_IPV4) { 323 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: E_PAR", API_PROTO, (ID)exinf); 324 retry = true; 325 continue; 326 } 327 328 #endif /* of #if defined(SUPPORT_INET6) && !defined(SUPPORT_INET4) && !defined(API_CFG_IP4MAPPED_ADDR) */ 329 330 if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) { 331 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] sleep %d.%03u[s], unknown host.", 332 API_PROTO, (ID)exinf, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ); 333 dly_tsk(SLP_ITV); 334 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] resume.", API_PROTO, (ID)exinf); 335 retry = true; 336 continue; 337 } 338 else 339 retry = false; 340 341 #if defined(SUPPORT_INET6) 342 343 #if defined(USE_TCP4_ECHO_CLI) 344 345 #else /* of #if defined(USE_TCP4_ECHO_CLI) */ 346 347 if (in6_is_addr_ipv4mapped(&addr)) 348 apip = API_PROTO_IPV4; 349 else 350 apip = API_PROTO_IPV6; 351 352 #endif /* of #if defined(USE_TCP4_ECHO_CLI) */ 353 354 #else /* of #if defined(SUPPORT_INET6) */ 355 356 if (apip == API_PROTO_IPV6) { 357 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: E_PAR", API_PROTO, (ID)exinf); 358 retry = true; 359 continue; 360 } 361 362 #endif /* of #if defined(SUPPORT_INET6) */ 363 364 line = skip_blanks(line); 365 if ('0' <= *line && *line <= '9') { /* Port No */ 742 366 line = get_int(&rep, line); 743 367 portno = (uint16_t)rep; … … 749 373 750 374 line = skip_blanks(line); 751 if ('0' <= *line && *line <= '9') 375 if ('0' <= *line && *line <= '9') /* Repeat */ 752 376 line = get_int(&rep, line); 753 else 377 else { 378 line ++; 754 379 rep = 1; 380 } 755 381 756 382 #ifdef USE_TCP_EXTENTIONS … … 776 402 #endif 777 403 778 if ((error = alloc_tcp_cep(&cepid, tskid, &ccep)) != E_OK) { 779 syslog(LOG_NOTICE, "[TEC:%02d TSK] CEP create error: %s", cepid, itron_strerror(error)); 404 #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) 405 406 if (apip == API_PROTO_IPV6) { 407 if ((error = alloc_tcp6_cep(&cepid, tskid, &ccep)) != E_OK) { 408 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", apip, cepid, itron_strerror(error)); 409 continue; 410 } 411 } 412 else { 413 if ((error = alloc_tcp4_cep(&cepid, tskid, &ccep)) != E_OK) { 414 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", apip, cepid, itron_strerror(error)); 415 continue; 416 } 417 } 418 419 #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */ 420 421 if ((error = ALLOC_TCP_CEP(&cepid, tskid, &ccep)) != E_OK) { 422 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", apip, cepid, itron_strerror(error)); 780 423 continue; 781 424 } 782 425 426 #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */ 427 783 428 #else /* of #ifdef USE_TCP_EXTENTIONS */ 784 429 430 #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) 431 432 if (apip == API_PROTO_IPV6) 433 cepid = (ID)exinf; 434 else 435 cepid = TCP4_ECHO_CLI_CEPID; 436 437 #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */ 438 785 439 cepid = (ID)exinf; 440 441 #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */ 786 442 787 443 #endif /* of #ifdef USE_TCP_EXTENTIONS */ … … 791 447 while (rep == 0 || count < rep) { 792 448 if (!tcp_echo_cli_valid) { 793 syslog(LOG_NOTICE, "[TEC :%02d TSK] canceled.", cepid);449 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] canceled.", apip, cepid); 794 450 break; 795 451 } … … 797 453 count ++; 798 454 if (rep == 0) { 799 syslog(LOG_NOTICE, "[TEC :%02d TSK] start: repeat: %d", cepid, count);800 error = send_tcp_echo(cepid, &addr, portno);801 syslog(LOG_NOTICE, "[TEC :%02d TSK] finished: repeat: %d", cepid, count);455 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] start: repeat: %d", apip, cepid, count); 456 error = tcp_echo_cli_snd(cepid, &addr, portno, apip); 457 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] finsh: repeat: %d", apip, cepid, count); 802 458 } 803 459 else { 804 syslog(LOG_NOTICE, "[TEC :%02d TSK] start: repeat: %d/%d", cepid, count, rep);805 error = send_tcp_echo(cepid, &addr, portno);806 syslog(LOG_NOTICE, "[TEC :%02d TSK] finished: repeat: %d/%d", cepid, count, rep);460 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] start: repeat: %d/%d", apip, cepid, count, rep); 461 error = tcp_echo_cli_snd(cepid, &addr, portno, apip); 462 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] finsh: repeat: %d/%d", apip, cepid, count, rep); 807 463 } 808 464 809 465 if (error != E_OK) { 810 syslog(LOG_NOTICE, "[TEC :%02d TSK] sleep %d[ms], error: %s",811 cepid, SLP_ITV, itron_strerror(error));466 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] sleep %d.%03u[s], error: %s", 467 apip, cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ, itron_strerror(error)); 812 468 tslp_tsk(SLP_ITV); 813 syslog(LOG_NOTICE, "[TEC :%02d TSK] resume.", cepid);469 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] resume.", apip, cepid); 814 470 } 815 471 816 472 #if defined(SND_ITV) 817 473 #if SND_ITV > 0 818 if (count > 0) {474 if (count < rep) { 819 475 uint_t itv; 820 476 821 477 itv = SND_ITV; 822 syslog(LOG_NOTICE, "[TEC :%02d TSK] interval: %d[ms].", cepid, itv);478 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] interval: %d[s].", apip, cepid, itv / SYSTIM_HZ); 823 479 syscall(dly_tsk(SND_ITV)); 824 480 } … … 829 485 #ifdef USE_TCP_EXTENTIONS 830 486 831 if ((error = free_tcp_cep(cepid)) != E_OK)832 syslog(LOG_NOTICE, "[TEC :%02d TSK] CEP delete error: %s", cepid, itron_strerror(error));487 if ((error = FREE_TCP_CEP(cepid)) != E_OK) 488 syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", apip, cepid, itron_strerror(error)); 833 489 834 490 #endif /* of #ifdef USE_TCP_EXTENTIONS */
Note:
See TracChangeset
for help on using the changeset viewer.