[388] | 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_cli.c 388 2019-05-22 11:25:18Z coas-nagasima $
|
---|
| 44 | */
|
---|
| 45 |
|
---|
| 46 | /*
|
---|
| 47 | * TCP ECHO ã¯ã©ã¤ã¢ã³ã
|
---|
| 48 | *
|
---|
| 49 | * ã»éåä¿¡ã¿ã¹ã¯åé¢å
|
---|
| 50 | * ã»ãã³ããããã³ã°ã³ã¼ã«
|
---|
| 51 | * ã»çã³ãã¼ API
|
---|
| 52 | * ã»IPv4
|
---|
| 53 | * ã»IPv6
|
---|
| 54 | */
|
---|
| 55 |
|
---|
| 56 | #include <stdlib.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_cli.h>
|
---|
| 82 |
|
---|
| 83 | #ifdef USE_TCP_ECHO_CLI
|
---|
| 84 |
|
---|
| 85 | /* echo ãµã¼ãã®ãã¼ãçªå· */
|
---|
| 86 |
|
---|
| 87 | #define ECHO_SRV_PORTNO UINT_C(7)
|
---|
| 88 |
|
---|
| 89 | /* ç·æ¥ãã¼ã¿ã®éä¿¡ */
|
---|
| 90 |
|
---|
| 91 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 92 |
|
---|
| 93 | //#define SND_URG_DATA_SIZE 4
|
---|
| 94 | #define SND_URG_COUNT 10
|
---|
| 95 |
|
---|
| 96 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 97 |
|
---|
| 98 | /* éä¿¡éé */
|
---|
| 99 |
|
---|
| 100 | #ifdef TOPPERS_S810_CLG3_85
|
---|
| 101 |
|
---|
| 102 | //#define SND_DLY (500)
|
---|
| 103 | #define START_DLY (10*SYSTIM_HZ)
|
---|
| 104 | #define SND_ITV (5*SYSTIM_HZ)
|
---|
| 105 | #define SLP_ITV (30*SYSTIM_HZ)
|
---|
| 106 |
|
---|
| 107 | #else /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 108 |
|
---|
| 109 | //#define SND_DLY (500)
|
---|
| 110 | #define START_DLY (10*SYSTIM_HZ)
|
---|
| 111 | #define SND_ITV (5*SYSTIM_HZ)
|
---|
| 112 | #define SLP_ITV (60*SYSTIM_HZ)
|
---|
| 113 |
|
---|
| 114 | #endif /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 115 |
|
---|
| 116 | /* èªåå®è¡ */
|
---|
| 117 |
|
---|
| 118 | #if defined(TCP_ECHO_CLI_AUTO_RUN_STR)
|
---|
| 119 | #else
|
---|
| 120 | #if 0
|
---|
| 121 | #if defined(SUPPORT_INET6)
|
---|
| 122 | #define TCP_ECHO_CLI_AUTO_RUN_STR "fd90:cce5:25f6:ff81:201:2ff:fe81:e7c9 - 0"
|
---|
| 123 | #else
|
---|
| 124 | #define TCP_ECHO_CLI_AUTO_RUN_STR "172.25.129.140 - 0"
|
---|
| 125 | #endif
|
---|
| 126 | #endif
|
---|
| 127 | #endif
|
---|
| 128 |
|
---|
| 129 | #if defined(SUPPORT_INET6)
|
---|
| 130 | #if defined(SUPPORT_INET4)
|
---|
| 131 | #define API_PROTO 'n'
|
---|
| 132 | #else
|
---|
| 133 | #define API_PROTO '6'
|
---|
| 134 | #endif
|
---|
| 135 | #else
|
---|
| 136 | #define API_PROTO '4'
|
---|
| 137 | #endif
|
---|
| 138 |
|
---|
| 139 | /*
|
---|
| 140 | * å
|
---|
| 141 | ¨åå¤æ°
|
---|
| 142 | */
|
---|
| 143 |
|
---|
| 144 | bool_t tcp_echo_cli_valid;
|
---|
| 145 | uint_t tcp_echo_cli_scount;
|
---|
| 146 |
|
---|
| 147 | /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */
|
---|
| 148 |
|
---|
| 149 | #ifndef TCP_CFG_SWBUF_CSAVE
|
---|
| 150 | uint8_t tcp_echo_cli_swbuf[TCP_ECHO_CLI_SWBUF_SIZE];
|
---|
| 151 | #endif
|
---|
| 152 |
|
---|
| 153 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
| 154 | uint8_t tcp_echo_cli_rwbuf[TCP_ECHO_CLI_RWBUF_SIZE];
|
---|
| 155 | #endif
|
---|
| 156 |
|
---|
| 157 | #ifdef USE_TCP_NON_BLOCKING
|
---|
| 158 |
|
---|
| 159 | /*
|
---|
| 160 | * å
|
---|
| 161 | ¨åå¤æ°
|
---|
| 162 | */
|
---|
| 163 |
|
---|
| 164 | ER_UINT tcp_echo_cli_nblk_error;
|
---|
| 165 |
|
---|
| 166 | /*
|
---|
| 167 | * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ°
|
---|
| 168 | */
|
---|
| 169 |
|
---|
| 170 | ER
|
---|
| 171 | callback_nblk_tcp_echo_cli (ID cepid, FN fncd, void *p_parblk)
|
---|
| 172 | {
|
---|
| 173 | ER error = E_OK;
|
---|
| 174 |
|
---|
| 175 | tcp_echo_cli_nblk_error = *(ER*)p_parblk;
|
---|
| 176 |
|
---|
| 177 | switch (fncd) {
|
---|
| 178 |
|
---|
| 179 | case TFN_TCP_CON_CEP:
|
---|
| 180 | syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 181 | break;
|
---|
| 182 |
|
---|
| 183 | case TFN_TCP_RCV_BUF:
|
---|
| 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));
|
---|
| 187 | syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 188 | break;
|
---|
| 189 |
|
---|
| 190 | case TFN_TCP_CLS_CEP:
|
---|
| 191 | if (tcp_echo_cli_nblk_error < 0)
|
---|
| 192 | syslog(LOG_NOTICE, "[TEC%c:%02u CBN] error: %s",
|
---|
| 193 | API_PROTO, cepid, itron_strerror(tcp_echo_cli_nblk_error));
|
---|
| 194 | syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 195 | break;
|
---|
| 196 |
|
---|
| 197 | case TFN_TCP_RCV_DAT:
|
---|
| 198 | if (tcp_echo_cli_nblk_error < 0)
|
---|
| 199 | syslog(LOG_NOTICE, "[TEC%c:%02u CBN] error: %s",
|
---|
| 200 | API_PROTO, cepid, itron_strerror(tcp_echo_cli_nblk_error));
|
---|
| 201 | syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 202 | break;
|
---|
| 203 |
|
---|
| 204 | case TFN_TCP_SND_OOB:
|
---|
| 205 | if (tcp_echo_cli_nblk_error > 0)
|
---|
| 206 | syslog(LOG_NOTICE, "[TEC%c:%02u CBN] snd urg: %4u",
|
---|
| 207 | API_PROTO, cepid, tcp_echo_cli_nblk_error);
|
---|
| 208 | else
|
---|
| 209 | syslog(LOG_NOTICE, "[TEC%c:%02u CBN] error: %s",
|
---|
| 210 | API_PROTO, cepid, itron_strerror(tcp_echo_cli_nblk_error));
|
---|
| 211 | break;
|
---|
| 212 |
|
---|
| 213 | case TFN_TCP_ACP_CEP:
|
---|
| 214 | case TFN_TCP_SND_DAT:
|
---|
| 215 | case TFN_TCP_GET_BUF:
|
---|
| 216 | default:
|
---|
| 217 | error = E_PAR;
|
---|
| 218 | break;
|
---|
| 219 | }
|
---|
| 220 | return error;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | #endif /* of #ifdef USE_TCP_NON_BLOCKING */
|
---|
| 224 |
|
---|
| 225 | /*
|
---|
| 226 | * getcomd -- ã³ãã³ããå¾ãã
|
---|
| 227 | */
|
---|
| 228 |
|
---|
| 229 | #ifdef TCP_ECHO_CLI_AUTO_RUN_STR
|
---|
| 230 |
|
---|
| 231 | static char *
|
---|
| 232 | getcomd (ID cepid, bool_t retry, char *apip)
|
---|
| 233 | {
|
---|
| 234 | ER error;
|
---|
| 235 | char *line = NULL;
|
---|
| 236 | static char auto_run_str[] = TCP_ECHO_CLI_AUTO_RUN_STR;
|
---|
| 237 | static int_t count = 0;
|
---|
| 238 |
|
---|
| 239 | if (retry || (count == 0)) {
|
---|
| 240 | line = auto_run_str;
|
---|
| 241 | dly_tsk(3 * 1000);
|
---|
| 242 | }
|
---|
| 243 | else {
|
---|
| 244 | while ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_SND, (intptr_t*)&line)) != E_OK) {
|
---|
| 245 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", API_PROTO, cepid, itron_strerror(error));
|
---|
| 246 | dly_tsk(SLP_ITV);
|
---|
| 247 | }
|
---|
| 248 | }
|
---|
| 249 |
|
---|
| 250 | count ++;
|
---|
| 251 | return line;
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | #else /* of #ifdef TCP_ECHO_CLI_AUTO_RUN_STR */
|
---|
| 255 |
|
---|
| 256 | static char *
|
---|
| 257 | getcomd (ID cepid, bool_t retry, char *apip)
|
---|
| 258 | {
|
---|
| 259 | ER error;
|
---|
| 260 | char *line = NULL;
|
---|
| 261 |
|
---|
| 262 | while ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_SND, (intptr_t*)&line)) != E_OK) {
|
---|
| 263 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", API_PROTO, cepid, itron_strerror(error));
|
---|
| 264 | dly_tsk(SLP_ITV);
|
---|
| 265 | }
|
---|
| 266 |
|
---|
| 267 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
|
---|
| 268 |
|
---|
| 269 | if (*line == '6') {
|
---|
| 270 | line ++;
|
---|
| 271 | *apip = API_PROTO_IPV6;
|
---|
| 272 | }
|
---|
| 273 | else if (*line == '4') {
|
---|
| 274 | line ++;
|
---|
| 275 | *apip = API_PROTO_IPV4;
|
---|
| 276 | }
|
---|
| 277 | else {
|
---|
| 278 | *apip= DEFAULT_API_PROTO;
|
---|
| 279 | if (*line && *line != ' ')
|
---|
| 280 | line ++;
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 284 |
|
---|
| 285 | *apip= DEFAULT_API_PROTO;
|
---|
| 286 | if (*line && *line != ' ')
|
---|
| 287 | line ++;
|
---|
| 288 |
|
---|
| 289 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 290 |
|
---|
| 291 | return line;
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | #endif /* of #ifdef TCP_ECHO_CLI_AUTO_RUN_STR */
|
---|
| 295 |
|
---|
| 296 | /*
|
---|
| 297 | * TCP ECHO ã¯ã©ã¤ã¢ã³ãéä¿¡ã¿ã¹ã¯
|
---|
| 298 | */
|
---|
| 299 |
|
---|
| 300 | /*
|
---|
| 301 | * IP ã¢ãã¬ã¹ã®æå®
|
---|
| 302 | */
|
---|
| 303 |
|
---|
| 304 | #define ADDR_IPVn 'n'
|
---|
| 305 | #define ADDR_IPV6 '6'
|
---|
| 306 | #define ADDR_IPV4 '4'
|
---|
| 307 |
|
---|
| 308 | void
|
---|
| 309 | tcp_echo_cli_snd_task (intptr_t exinf)
|
---|
| 310 | {
|
---|
| 311 | ID tskid, cepid;
|
---|
| 312 | ER error;
|
---|
| 313 | T_IN_ADDR addr;
|
---|
| 314 | char *line;
|
---|
| 315 | int_t rep, count;
|
---|
| 316 | bool_t retry = false;
|
---|
| 317 | uint16_t portno;
|
---|
| 318 | char apip;
|
---|
| 319 |
|
---|
| 320 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 321 |
|
---|
| 322 | T_TCP_CCEP ccep;
|
---|
| 323 |
|
---|
| 324 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 325 |
|
---|
| 326 | #ifdef TCP_ECHO_CLI_AUTO_RUN_STR
|
---|
| 327 | dly_tsk(START_DLY);
|
---|
| 328 | #endif
|
---|
| 329 | get_tid(&tskid);
|
---|
| 330 | syslog(LOG_NOTICE, "[TCP%c ECHO CLI SND:%d,%d] started.", DEFAULT_API_PROTO, tskid, (ID)exinf);
|
---|
| 331 | while (true) {
|
---|
| 332 | line = skip_blanks(getcomd((ID)exinf, retry, &apip));
|
---|
| 333 |
|
---|
| 334 | #if defined(SUPPORT_INET6) && !defined(SUPPORT_INET4) && !defined(API_CFG_IP4MAPPED_ADDR)
|
---|
| 335 |
|
---|
| 336 | if (apip == API_PROTO_IPV4) {
|
---|
| 337 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: E_PAR", API_PROTO, (ID)exinf);
|
---|
| 338 | retry = true;
|
---|
| 339 | continue;
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | #endif /* of #if defined(SUPPORT_INET6) && !defined(SUPPORT_INET4) && !defined(API_CFG_IP4MAPPED_ADDR) */
|
---|
| 343 |
|
---|
| 344 | if ((line = lookup_ipaddr(&addr, line, apip)) == NULL) {
|
---|
| 345 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] sleep %d.%03u[s], unknown host.",
|
---|
| 346 | API_PROTO, (ID)exinf, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
|
---|
| 347 | dly_tsk(SLP_ITV);
|
---|
| 348 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] resume.", API_PROTO, (ID)exinf);
|
---|
| 349 | retry = true;
|
---|
| 350 | continue;
|
---|
| 351 | }
|
---|
| 352 | else
|
---|
| 353 | retry = false;
|
---|
| 354 |
|
---|
| 355 | #if defined(SUPPORT_INET6)
|
---|
| 356 |
|
---|
| 357 | #if defined(USE_TCP4_ECHO_CLI)
|
---|
| 358 |
|
---|
| 359 | #else /* of #if defined(USE_TCP4_ECHO_CLI) */
|
---|
| 360 |
|
---|
| 361 | if (in6_is_addr_ipv4mapped(&addr))
|
---|
| 362 | apip = API_PROTO_IPV4;
|
---|
| 363 | else
|
---|
| 364 | apip = API_PROTO_IPV6;
|
---|
| 365 |
|
---|
| 366 | #endif /* of #if defined(USE_TCP4_ECHO_CLI) */
|
---|
| 367 |
|
---|
| 368 | #else /* of #if defined(SUPPORT_INET6) */
|
---|
| 369 |
|
---|
| 370 | if (apip == API_PROTO_IPV6) {
|
---|
| 371 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: E_PAR", API_PROTO, (ID)exinf);
|
---|
| 372 | retry = true;
|
---|
| 373 | continue;
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
| 377 |
|
---|
| 378 | line = skip_blanks(line);
|
---|
| 379 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
| 380 | line = get_int(&rep, line);
|
---|
| 381 | portno = (uint16_t)rep;
|
---|
| 382 | }
|
---|
| 383 | else {
|
---|
| 384 | line ++;
|
---|
| 385 | portno = ECHO_SRV_PORTNO;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | line = skip_blanks(line);
|
---|
| 389 | if ('0' <= *line && *line <= '9') /* Repeat */
|
---|
| 390 | line = get_int(&rep, line);
|
---|
| 391 | else {
|
---|
| 392 | line ++;
|
---|
| 393 | rep = 1;
|
---|
| 394 | }
|
---|
| 395 |
|
---|
| 396 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 397 |
|
---|
| 398 | ccep.cepatr = 0;
|
---|
| 399 | ccep.sbufsz = TCP_ECHO_CLI_SWBUF_SIZE;
|
---|
| 400 | ccep.rbufsz = TCP_ECHO_CLI_RWBUF_SIZE;
|
---|
| 401 |
|
---|
| 402 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
| 403 | ccep.sbuf = NADR;
|
---|
| 404 | #else
|
---|
| 405 | ccep.sbuf = tcp_echo_cli_swbuf;
|
---|
| 406 | #endif
|
---|
| 407 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
| 408 | ccep.rbuf = NADR;
|
---|
| 409 | #else
|
---|
| 410 | ccep.rbuf = tcp_echo_cli_rwbuf;
|
---|
| 411 | #endif
|
---|
| 412 | #ifdef USE_TCP_NON_BLOCKING
|
---|
| 413 | ccep.callback = (FP)callback_nblk_tcp_echo_cli;
|
---|
| 414 | #else
|
---|
| 415 | ccep.callback = NULL;
|
---|
| 416 | #endif
|
---|
| 417 |
|
---|
| 418 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
|
---|
| 419 |
|
---|
| 420 | if (apip == API_PROTO_IPV6) {
|
---|
| 421 | if ((error = alloc_tcp6_cep(&cepid, tskid, &ccep)) != E_OK) {
|
---|
| 422 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 423 | continue;
|
---|
| 424 | }
|
---|
| 425 | }
|
---|
| 426 | else {
|
---|
| 427 | if ((error = alloc_tcp4_cep(&cepid, tskid, &ccep)) != E_OK) {
|
---|
| 428 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 429 | continue;
|
---|
| 430 | }
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 434 |
|
---|
| 435 | if ((error = ALLOC_TCP_CEP(&cepid, tskid, &ccep)) != E_OK) {
|
---|
| 436 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 437 | continue;
|
---|
| 438 | }
|
---|
| 439 |
|
---|
| 440 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 441 |
|
---|
| 442 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 443 |
|
---|
| 444 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
|
---|
| 445 |
|
---|
| 446 | if (apip == API_PROTO_IPV6)
|
---|
| 447 | cepid = (ID)exinf;
|
---|
| 448 | else
|
---|
| 449 | cepid = TCP4_ECHO_CLI_CEPID;
|
---|
| 450 |
|
---|
| 451 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 452 |
|
---|
| 453 | cepid = (ID)exinf;
|
---|
| 454 |
|
---|
| 455 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 456 |
|
---|
| 457 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 458 |
|
---|
| 459 | tcp_echo_cli_valid = true;
|
---|
| 460 | count = 0;
|
---|
| 461 | while (rep == 0 || count < rep) {
|
---|
| 462 | if (!tcp_echo_cli_valid) {
|
---|
| 463 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] canceled.", apip, cepid);
|
---|
| 464 | break;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
| 467 | count ++;
|
---|
| 468 | if (rep == 0) {
|
---|
| 469 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] start: repeat: %d", apip, cepid, count);
|
---|
| 470 | error = tcp_echo_cli_snd(cepid, &addr, portno, apip);
|
---|
| 471 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] finsh: repeat: %d", apip, cepid, count);
|
---|
| 472 | }
|
---|
| 473 | else {
|
---|
| 474 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] start: repeat: %d/%d", apip, cepid, count, rep);
|
---|
| 475 | error = tcp_echo_cli_snd(cepid, &addr, portno, apip);
|
---|
| 476 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] finsh: repeat: %d/%d", apip, cepid, count, rep);
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | if (error != E_OK) {
|
---|
| 480 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] sleep %d.%03u[s], error: %s",
|
---|
| 481 | apip, cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ, itron_strerror(error));
|
---|
| 482 | tslp_tsk(SLP_ITV);
|
---|
| 483 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] resume.", apip, cepid);
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | #if defined(SND_ITV)
|
---|
| 487 | #if SND_ITV > 0
|
---|
| 488 | if (count < rep) {
|
---|
| 489 | uint_t itv;
|
---|
| 490 |
|
---|
| 491 | itv = SND_ITV;
|
---|
| 492 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] interval: %d[s].", apip, cepid, itv / SYSTIM_HZ);
|
---|
| 493 | syscall(dly_tsk(SND_ITV));
|
---|
| 494 | }
|
---|
| 495 | #endif
|
---|
| 496 | #endif
|
---|
| 497 | }
|
---|
| 498 |
|
---|
| 499 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 500 |
|
---|
| 501 | if ((error = FREE_TCP_CEP(cepid)) != E_OK)
|
---|
| 502 | syslog(LOG_NOTICE, "[TEC%c:%02u TSK] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 503 |
|
---|
| 504 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 505 |
|
---|
| 506 | }
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | #endif /* of #ifdef USE_TCP_ECHO_CLI */
|
---|