[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2001-2009 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 270 2017-02-09 04:03:47Z 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 |
|
---|
| 65 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 66 |
|
---|
| 67 | #ifdef TARGET_KERNEL_JSP
|
---|
| 68 |
|
---|
| 69 | #include <t_services.h>
|
---|
| 70 | #include "kernel_id.h"
|
---|
| 71 |
|
---|
| 72 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 73 |
|
---|
| 74 | #include <tinet_defs.h>
|
---|
| 75 | #include <tinet_config.h>
|
---|
| 76 |
|
---|
| 77 | #include <net/if.h>
|
---|
| 78 | #include <net/if_ppp.h>
|
---|
| 79 | #include <net/if_loop.h>
|
---|
| 80 | #include <net/net.h>
|
---|
| 81 | #include <net/ethernet.h>
|
---|
| 82 | #include <net/net_var.h>
|
---|
| 83 | #include <net/net_timer.h>
|
---|
| 84 |
|
---|
| 85 | #include <netinet/in.h>
|
---|
| 86 | #include <netinet/in_itron.h>
|
---|
| 87 | #include <netinet/ip.h>
|
---|
| 88 | #include <netinet/ip6.h>
|
---|
| 89 | #include <netinet/tcp.h>
|
---|
| 90 |
|
---|
| 91 | #include <netapp/netapp.h>
|
---|
| 92 | #include <netapp/netapp_var.h>
|
---|
| 93 | #include <netapp/echo.h>
|
---|
| 94 |
|
---|
| 95 | #ifdef USE_TCP_ECHO_CLI
|
---|
| 96 |
|
---|
| 97 | /* echo ãµã¼ãã®ãã¼ãçªå· */
|
---|
| 98 |
|
---|
| 99 | #define ECHO_SRV_PORTNO UINT_C(7)
|
---|
| 100 |
|
---|
| 101 | /* ç·æ¥ãã¼ã¿ã®éä¿¡ */
|
---|
| 102 |
|
---|
| 103 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 104 |
|
---|
| 105 | //#define SND_URG_DATA_SIZE 4
|
---|
| 106 | #define SND_URG_COUNT 10
|
---|
| 107 |
|
---|
| 108 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 109 |
|
---|
| 110 | /* 表示 */
|
---|
| 111 |
|
---|
| 112 | //#define SHOW_RCV_RANGE
|
---|
| 113 |
|
---|
| 114 | /* ã¿ã¤ã ã¢ã¦ã */
|
---|
| 115 |
|
---|
| 116 | #define CON_TMO TMO_FEVR
|
---|
| 117 | //#define CON_TMO (60*SYSTIM_HZ)
|
---|
| 118 | //#define CLS_TMO TMO_FEVR /* Close Wait ã¯æ¨æºã§ 60ç§ */
|
---|
| 119 | #define CLS_TMO (70*SYSTIM_HZ+(net_rand()%SYSTIM_HZ)*10)
|
---|
| 120 | //#define RCV_TMO TMO_FEVR
|
---|
| 121 | #define RCV_TMO (40*SYSTIM_HZ+(net_rand()%SYSTIM_HZ)*20)
|
---|
| 122 | //#define SND_TMO TMO_FEVR
|
---|
| 123 | #define SND_TMO (30*SYSTIM_HZ+(net_rand()%SYSTIM_HZ)*30)
|
---|
| 124 |
|
---|
| 125 | /* éä¿¡éé */
|
---|
| 126 |
|
---|
| 127 | //#define SND_DLY ULONG_C(500)
|
---|
| 128 | #define SND_ITV (5*SYSTM_HZ)
|
---|
| 129 | #define SLP_ITV (60*SYSTIM_HZ)
|
---|
| 130 |
|
---|
| 131 | /* èªåå®è¡ */
|
---|
| 132 |
|
---|
| 133 | #if 0
|
---|
| 134 | #if defined(SUPPORT_INET6)
|
---|
| 135 | #define AUTO_RUN_STR "fe80::211:2fff:fe8a:e8c0 - 0"
|
---|
| 136 | #else
|
---|
| 137 | #define AUTO_RUN_STR "172.25.193.140 - 0"
|
---|
| 138 | #endif
|
---|
| 139 | #endif
|
---|
| 140 |
|
---|
| 141 | /*
|
---|
| 142 | * ãããã¡ãµã¤ãºã®å®ç¾©
|
---|
| 143 | */
|
---|
| 144 |
|
---|
| 145 | #define NUM_ECHO 20
|
---|
| 146 | #define NUM_REP_PAT 20
|
---|
| 147 | #define PAT_BEGIN ' '
|
---|
| 148 | #define PAT_END '~'
|
---|
| 149 | #define SND_BUF_SIZE ((PAT_END - PAT_BEGIN + 1) * NUM_REP_PAT)
|
---|
| 150 | #define RCV_BUF_SIZE (SND_BUF_SIZE*15/10)
|
---|
| 151 |
|
---|
| 152 | /*
|
---|
| 153 | * å
|
---|
| 154 | ¨åå¤æ°
|
---|
| 155 | */
|
---|
| 156 |
|
---|
| 157 | bool_t tcp_echo_cli_valid;
|
---|
| 158 |
|
---|
| 159 | /* TCP éåä¿¡ã¦ã£ã³ããããã¡ */
|
---|
| 160 |
|
---|
| 161 | #ifndef TCP_CFG_SWBUF_CSAVE
|
---|
| 162 | uint8_t tcp_echo_cli_swbuf[TCP_ECHO_CLI_SWBUF_SIZE];
|
---|
| 163 | #endif
|
---|
| 164 |
|
---|
| 165 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
| 166 | uint8_t tcp_echo_cli_rwbuf[TCP_ECHO_CLI_RWBUF_SIZE];
|
---|
| 167 | #endif
|
---|
| 168 |
|
---|
| 169 | /*
|
---|
| 170 | * å¤æ°
|
---|
| 171 | */
|
---|
| 172 |
|
---|
| 173 | static uint_t scount;
|
---|
| 174 | static uint_t rcount;
|
---|
| 175 |
|
---|
| 176 | #ifdef USE_TCP_NON_BLOCKING
|
---|
| 177 |
|
---|
| 178 | static T_IPEP nblk_src = {
|
---|
| 179 | IP_ADDRANY,
|
---|
| 180 | TCP_PORTANY,
|
---|
| 181 | };
|
---|
| 182 | static T_IPEP nblk_dst;
|
---|
| 183 | static ER_UINT nblk_error;
|
---|
| 184 |
|
---|
| 185 | /*
|
---|
| 186 | * ãã³ããããã³ã°ã³ã¼ã«ã®ã³ã¼ã«ããã¯é¢æ°
|
---|
| 187 | */
|
---|
| 188 |
|
---|
| 189 | ER
|
---|
| 190 | callback_nblk_tcp_echo_cli (ID cepid, FN fncd, void *p_parblk)
|
---|
| 191 | {
|
---|
| 192 | ER error = E_OK;
|
---|
| 193 |
|
---|
| 194 | nblk_error = *(ER*)p_parblk;
|
---|
| 195 |
|
---|
| 196 | switch (fncd) {
|
---|
| 197 |
|
---|
| 198 | case TFN_TCP_CON_CEP:
|
---|
| 199 | syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 200 | break;
|
---|
| 201 |
|
---|
| 202 | case TFN_TCP_RCV_BUF:
|
---|
| 203 | if (nblk_error < 0)
|
---|
| 204 | syslog(LOG_NOTICE, "[TEC:%02d CBN] rcv buf error: %s", cepid, itron_strerror(nblk_error));
|
---|
| 205 | syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 206 | break;
|
---|
| 207 |
|
---|
| 208 | case TFN_TCP_CLS_CEP:
|
---|
| 209 | if (nblk_error < 0)
|
---|
| 210 | syslog(LOG_NOTICE, "[TEC:%02d CBN] close error: %s", cepid, itron_strerror(nblk_error));
|
---|
| 211 | syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 212 | break;
|
---|
| 213 |
|
---|
| 214 | case TFN_TCP_RCV_DAT:
|
---|
| 215 | if (nblk_error < 0)
|
---|
| 216 | syslog(LOG_NOTICE, "[TEC:%02d CBN] rcv dat error: %s", cepid, itron_strerror(nblk_error));
|
---|
| 217 | syscall(sig_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 218 | break;
|
---|
| 219 |
|
---|
| 220 | case TFN_TCP_SND_OOB:
|
---|
| 221 | if (nblk_error > 0)
|
---|
| 222 | syslog(LOG_NOTICE, "[TEC:%02d CBN] snd urg: %4d", cepid, nblk_error);
|
---|
| 223 | else
|
---|
| 224 | syslog(LOG_NOTICE, "[TEC:%02d CBN] snd urg error: %s", cepid, itron_strerror(nblk_error));
|
---|
| 225 | break;
|
---|
| 226 |
|
---|
| 227 | case TFN_TCP_ACP_CEP:
|
---|
| 228 | case TFN_TCP_SND_DAT:
|
---|
| 229 | case TFN_TCP_GET_BUF:
|
---|
| 230 | default:
|
---|
| 231 | error = E_PAR;
|
---|
| 232 | break;
|
---|
| 233 | }
|
---|
| 234 | return error;
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | /*
|
---|
| 238 | * send_tcp_echo -- ECHO/TCP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 239 | */
|
---|
| 240 |
|
---|
| 241 | static ER
|
---|
| 242 | send_tcp_echo (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
|
---|
| 243 | {
|
---|
| 244 | static char smsg[SND_BUF_SIZE];
|
---|
| 245 |
|
---|
| 246 | ER_UINT slen;
|
---|
| 247 | ER error;
|
---|
| 248 | SYSTIM time;
|
---|
| 249 | uint32_t total;
|
---|
| 250 | uint16_t soff, echo, rep;
|
---|
| 251 | char *p, pat;
|
---|
| 252 |
|
---|
| 253 | #ifdef SND_URG_DATA_SIZE
|
---|
| 254 | int_t urg = SND_URG_COUNT;
|
---|
| 255 | #endif
|
---|
| 256 |
|
---|
| 257 | nblk_dst.ipaddr = *ipaddr;
|
---|
| 258 | nblk_dst.portno = portno;
|
---|
| 259 |
|
---|
| 260 | p = smsg;
|
---|
| 261 | for (rep = NUM_REP_PAT; rep -- > 0; )
|
---|
| 262 | for (pat = PAT_BEGIN; pat <= PAT_END; pat ++)
|
---|
| 263 | *p ++ = pat;
|
---|
| 264 |
|
---|
| 265 | if ((error = TCP_CON_CEP(cepid, &nblk_src, &nblk_dst, TMO_NBLK)) != E_WBLK) {
|
---|
| 266 | syslog(LOG_NOTICE, "[TEC:%02d SND] connect error: %s", cepid, itron_strerror(error));
|
---|
| 267 | return error;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | /* æ¥ç¶ãå®äºããã¾ã§å¾
|
---|
| 271 | ã¤ã*/
|
---|
| 272 | syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 273 |
|
---|
| 274 | if (nblk_error != E_OK)
|
---|
| 275 | syslog(LOG_NOTICE, "[TEC:%02d SND] connect error: %s", cepid, itron_strerror(nblk_error));
|
---|
| 276 | else {
|
---|
| 277 | get_tim(&time);
|
---|
| 278 | syslog(LOG_NOTICE, "[TEC:%02d SND] connecting: %6lu, to: %s.%u",
|
---|
| 279 | cepid, time / SYSTIM_HZ, IP2STR(NULL, ipaddr), nblk_dst.portno);
|
---|
| 280 |
|
---|
| 281 | if ((error = psnd_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t)cepid)) != E_OK) {
|
---|
| 282 | syslog(LOG_NOTICE, "[TEC:%02d SND] sync error: %s", cepid, itron_strerror(error));
|
---|
| 283 | goto cls_ret;
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | scount = total = 0;
|
---|
| 287 | for (echo = NUM_ECHO; echo -- > 0; ) {
|
---|
| 288 | soff = 0;
|
---|
| 289 | while (soff < SND_BUF_SIZE) {
|
---|
| 290 | if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, SND_TMO)) < 0) {
|
---|
| 291 | syslog(LOG_NOTICE, "[TEC:%02d SND] snd dat error: %s",
|
---|
| 292 | cepid, itron_strerror(slen));
|
---|
| 293 | goto cls_ret;
|
---|
| 294 | }
|
---|
| 295 | soff += (uint16_t)slen;
|
---|
| 296 | total += slen;
|
---|
| 297 | scount ++;
|
---|
| 298 | #ifdef SHOW_RCV_RANGE
|
---|
| 299 | syslog(LOG_NOTICE, "[TEC:%02d SND] send cnt: %2d, len: %4d, off: %4d",
|
---|
| 300 | cepid, scount, (uint16_t)slen, soff);
|
---|
| 301 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 302 |
|
---|
| 303 | #ifdef SND_URG_DATA_SIZE
|
---|
| 304 | if (urg) {
|
---|
| 305 | if (urg == 1) {
|
---|
| 306 | if ((error = tcp_snd_oob(cepid, smsg, SND_URG_DATA_SIZE, TMO_NBLK)) != E_WBLK)
|
---|
| 307 | syslog(LOG_NOTICE, "[TEC:%02d SND] snd urg error: %s",
|
---|
| 308 | cepid, itron_strerror(error));
|
---|
| 309 | }
|
---|
| 310 | urg --;
|
---|
| 311 | }
|
---|
| 312 | #endif /* of #ifdef SND_URG_DATA_SIZE */
|
---|
| 313 |
|
---|
| 314 | #if SND_DLY > 0
|
---|
| 315 | syscall(dly_tsk(SND_DLY + net_rand() % SYSTIM_HZ));
|
---|
| 316 | #endif
|
---|
| 317 | }
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | cls_ret:
|
---|
| 321 | if ((error = tcp_sht_cep(cepid)) < 0)
|
---|
| 322 | syslog(LOG_NOTICE, "[TEC:%02d SND] shutdown error: %s", cepid, itron_strerror(error));
|
---|
| 323 |
|
---|
| 324 | /* åä¿¡ãå®äºããã¾ã§å¾
|
---|
| 325 | ã¤ã*/
|
---|
| 326 | syscall(slp_tsk());
|
---|
| 327 | }
|
---|
| 328 |
|
---|
| 329 | return error;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | /*
|
---|
| 333 | * TCP ECHO ã¯ã©ã¤ã¢ã³ãåä¿¡ã¿ã¹ã¯
|
---|
| 334 | */
|
---|
| 335 |
|
---|
| 336 | #ifdef USE_COPYSAVE_API
|
---|
| 337 |
|
---|
| 338 | void
|
---|
| 339 | tcp_echo_cli_rcv_task (intptr_t exinf)
|
---|
| 340 | {
|
---|
| 341 | ID tskid, cepid;
|
---|
| 342 | ER error;
|
---|
| 343 | SYSTIM time;
|
---|
| 344 | uint32_t total;
|
---|
| 345 | uint16_t roff, rlen;
|
---|
| 346 | char *rmsg, head, tail;
|
---|
| 347 |
|
---|
| 348 | get_tid(&tskid);
|
---|
| 349 | syslog(LOG_NOTICE, "[TCP ECHO CLI (NBLK,CS) RCV:%d] started.", tskid);
|
---|
| 350 | while (true) {
|
---|
| 351 | if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {
|
---|
| 352 | syslog(LOG_NOTICE, "[TEC:%02d RCV] sync error: %s",
|
---|
| 353 | cepid, itron_strerror(error));
|
---|
| 354 | }
|
---|
| 355 | else {
|
---|
| 356 | roff = rcount = total = 0;
|
---|
| 357 | while (true) {
|
---|
| 358 | if ((error = tcp_rcv_buf(cepid, (void**)&rmsg, TMO_NBLK)) != E_WBLK) {
|
---|
| 359 | syslog(LOG_NOTICE, "[TEC:%02d RCV] rcv buf error: %s", cepid, itron_strerror(error));
|
---|
| 360 | break;
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | /* åä¿¡ãããã¡ã®ç²å¾ãå®äºããã¾ã§å¾
|
---|
| 364 | ã¤ã*/
|
---|
| 365 | syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 366 | if (nblk_error < 0)
|
---|
| 367 | break;
|
---|
| 368 |
|
---|
| 369 | rlen = nblk_error;
|
---|
| 370 | head = *rmsg;
|
---|
| 371 | tail = *(rmsg + rlen - 1);
|
---|
| 372 | if (rlen > 0) {
|
---|
| 373 | roff += rlen;
|
---|
| 374 | total += rlen;
|
---|
| 375 | rcount ++;
|
---|
| 376 | #ifdef SHOW_RCV_RANGE
|
---|
| 377 | syslog(LOG_NOTICE, "[TEC:%02d RCV] "
|
---|
| 378 | "recv cnt: %2d, len: %4d, off: %4d, data: %02x -> %02x",
|
---|
| 379 | cepid, rcount, rlen, roff, head, tail);
|
---|
| 380 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 381 | }
|
---|
| 382 | else
|
---|
| 383 | break;
|
---|
| 384 |
|
---|
| 385 | if ((error = tcp_rel_buf(cepid, rlen)) != E_OK)
|
---|
| 386 | syslog(LOG_NOTICE, "[TEC:%02d RCV] rel buf error: %s",
|
---|
| 387 | cepid, itron_strerror(error));
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK && error != E_OK)
|
---|
| 391 | syslog(LOG_NOTICE, "[TEC:%02d SND] close error: %s", cepid, itron_strerror(error));
|
---|
| 392 |
|
---|
| 393 | /* åæãå®äºããã¾ã§å¾
|
---|
| 394 | ã¤ã*/
|
---|
| 395 | syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 396 |
|
---|
| 397 | get_tim(&time);
|
---|
| 398 | syslog(LOG_NOTICE, "[TEC:%02u RCV] finished: %6lu, snd: %4u, rcv: %4u, len: %u",
|
---|
| 399 | cepid, time / SYSTIM_HZ, scount, rcount, total);
|
---|
| 400 | }
|
---|
| 401 |
|
---|
| 402 | syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));
|
---|
| 403 | }
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
| 407 |
|
---|
| 408 | void
|
---|
| 409 | tcp_echo_cli_rcv_task (intptr_t exinf)
|
---|
| 410 | {
|
---|
| 411 | static char rmsg[RCV_BUF_SIZE];
|
---|
| 412 |
|
---|
| 413 | ID tskid, cepid;
|
---|
| 414 | ER error;
|
---|
| 415 | SYSTIM time;
|
---|
| 416 | uint32_t total;
|
---|
| 417 | uint16_t roff, rlen;
|
---|
| 418 | char head, tail;
|
---|
| 419 |
|
---|
| 420 | get_tid(&tskid);
|
---|
| 421 | syslog(LOG_NOTICE, "[TCP ECHO CLI (NBLK) RCV:%d] started.", tskid);
|
---|
| 422 | while (true) {
|
---|
| 423 | if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {
|
---|
| 424 | syslog(LOG_NOTICE, "[TEC:%02d RCV] sync error: %s",
|
---|
| 425 | cepid, itron_strerror(error));
|
---|
| 426 | }
|
---|
| 427 | else {
|
---|
| 428 | roff = rcount = total = 0;
|
---|
| 429 | while (true) {
|
---|
| 430 | if ((error = tcp_rcv_dat(cepid, rmsg, sizeof(rmsg), TMO_NBLK)) != E_WBLK) {
|
---|
| 431 | syslog(LOG_NOTICE, "[TEC:%02d RCV] rcv error: %s", cepid, itron_strerror(error));
|
---|
| 432 | break;
|
---|
| 433 | }
|
---|
| 434 |
|
---|
| 435 | /* åä¿¡ãå®äºããã¾ã§å¾
|
---|
| 436 | ã¤ã*/
|
---|
| 437 | syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 438 | if (nblk_error < 0)
|
---|
| 439 | break;
|
---|
| 440 |
|
---|
| 441 | rlen = nblk_error;
|
---|
| 442 | head = *rmsg;
|
---|
| 443 | tail = *(rmsg + rlen - 1);
|
---|
| 444 | rcount ++;
|
---|
| 445 | if (rlen > 0) {
|
---|
| 446 | roff += rlen;
|
---|
| 447 | total += rlen;
|
---|
| 448 | #ifdef SHOW_RCV_RANGE
|
---|
| 449 | syslog(LOG_NOTICE, "[TEC:%02d RCV] "
|
---|
| 450 | "recv cnt: %2d, len: %4d, off: %4d, data: %02x -> %02x",
|
---|
| 451 | cepid, rcount, rlen, roff, head, tail);
|
---|
| 452 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 453 | }
|
---|
| 454 | else
|
---|
| 455 | break;
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | if ((error = tcp_cls_cep(cepid, TMO_NBLK)) != E_WBLK && error != E_OK)
|
---|
| 459 | syslog(LOG_NOTICE, "[TEC:%02d SND] close error: %s", cepid, itron_strerror(error));
|
---|
| 460 |
|
---|
| 461 | /* åæãå®äºããã¾ã§å¾
|
---|
| 462 | ã¤ã*/
|
---|
| 463 | syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 464 |
|
---|
| 465 | get_tim(&time);
|
---|
| 466 | syslog(LOG_NOTICE, "[TEC:%02u RCV] finished: %6lu, snd: %4u, rcv: %4u, len: %u",
|
---|
| 467 | cepid, time / SYSTIM_HZ, scount, rcount, total);
|
---|
| 468 | }
|
---|
| 469 |
|
---|
| 470 | syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
| 475 |
|
---|
| 476 | #else /* of #ifdef USE_TCP_NON_BLOCKING */
|
---|
| 477 |
|
---|
| 478 | /*
|
---|
| 479 | * send_tcp_echo -- ECHO/TCP ãµã¼ãã«ã¡ãã»ã¼ã¸ãéä¿¡ããã
|
---|
| 480 | */
|
---|
| 481 |
|
---|
| 482 | static ER
|
---|
| 483 | send_tcp_echo (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno)
|
---|
| 484 | {
|
---|
| 485 | static char smsg[SND_BUF_SIZE];
|
---|
| 486 | static T_IPEP src = {
|
---|
| 487 | IP_ADDRANY,
|
---|
| 488 | TCP_PORTANY,
|
---|
| 489 | };
|
---|
| 490 |
|
---|
| 491 | T_IPEP dst;
|
---|
| 492 | ER_UINT slen;
|
---|
| 493 | ER error;
|
---|
| 494 | SYSTIM time;
|
---|
| 495 | uint32_t total;
|
---|
| 496 | uint16_t soff, echo, rep;
|
---|
| 497 | char pat, *p;
|
---|
| 498 |
|
---|
| 499 | #ifdef SND_URG_DATA_SIZE
|
---|
| 500 | int_t urg = SND_URG_COUNT;
|
---|
| 501 | #endif
|
---|
| 502 |
|
---|
| 503 | dst.ipaddr = *ipaddr;
|
---|
| 504 | dst.portno = portno;
|
---|
| 505 |
|
---|
| 506 | p = smsg;
|
---|
| 507 | for (rep = NUM_REP_PAT; rep -- > 0; )
|
---|
| 508 | for (pat = PAT_BEGIN; pat <= PAT_END; pat ++)
|
---|
| 509 | *p ++ = pat;
|
---|
| 510 |
|
---|
| 511 | if ((error = TCP_CON_CEP(cepid, &src, &dst, CON_TMO)) != E_OK) {
|
---|
| 512 | syslog(LOG_NOTICE, "[TEC:%02d SND] connect error: %s", cepid, itron_strerror(error));
|
---|
| 513 | return error;
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | get_tim(&time);
|
---|
| 517 | syslog(LOG_NOTICE, "[TEC:%02u SND] connecting: %6lu, to: %s.%u",
|
---|
| 518 | cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
| 519 |
|
---|
| 520 | if ((error = psnd_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t)cepid)) != E_OK) {
|
---|
| 521 | syslog(LOG_NOTICE, "[TEC:%02d SND] sync error: %s", cepid, itron_strerror(error));
|
---|
| 522 | goto cls_ret;
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | scount = total = 0;
|
---|
| 526 | for (echo = NUM_ECHO; echo -- > 0; ) {
|
---|
| 527 | soff = 0;
|
---|
| 528 | while (soff < SND_BUF_SIZE) {
|
---|
| 529 | if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, SND_TMO)) < 0) {
|
---|
| 530 | syslog(LOG_NOTICE, "[TEC:%02d SND] snd dat error: %s", cepid, itron_strerror(slen));
|
---|
| 531 | goto cls_ret;
|
---|
| 532 | }
|
---|
| 533 | soff += (uint16_t)slen;
|
---|
| 534 | total += slen;
|
---|
| 535 | scount ++;
|
---|
| 536 | #ifdef SHOW_RCV_RANGE
|
---|
| 537 | syslog(LOG_NOTICE, "[TEC:%02d SND] send count: %3d, len: %4d, offset: %4d",
|
---|
| 538 | cepid, scount, (uint16_t)slen, soff);
|
---|
| 539 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 540 |
|
---|
| 541 | #ifdef SND_URG_DATA_SIZE
|
---|
| 542 | if (urg > 0) {
|
---|
| 543 | if (urg == 1) {
|
---|
| 544 | if ((slen = tcp_snd_oob(cepid, smsg, SND_URG_DATA_SIZE, SND_TMO)) >= 0)
|
---|
| 545 | syslog(LOG_NOTICE, "[TEC:%02d SND] snd urg: %4d",
|
---|
| 546 | cepid, (uint16_6)slen);
|
---|
| 547 | else
|
---|
| 548 | syslog(LOG_NOTICE, "[TEC:%02d SND] snd urg error: %s",
|
---|
| 549 | cepid, itron_strerror(slen));
|
---|
| 550 | }
|
---|
| 551 | urg --;
|
---|
| 552 | }
|
---|
| 553 | #endif /* of #ifdef SND_URG_DATA_SIZE */
|
---|
| 554 |
|
---|
| 555 | #if SND_DLY > 0
|
---|
| 556 | syscall(dly_tsk(SND_DLY + net_rand() % SYSTIM_HZ));
|
---|
| 557 | #endif
|
---|
| 558 | }
|
---|
| 559 | }
|
---|
| 560 |
|
---|
| 561 | cls_ret:
|
---|
| 562 | if ((error = tcp_sht_cep(cepid)) < 0)
|
---|
| 563 | syslog(LOG_NOTICE, "[TEC:%02d SND] shutdown error: %s", cepid, itron_strerror(error));
|
---|
| 564 |
|
---|
| 565 | /* åä¿¡ãå®äºããã¾ã§å¾
|
---|
| 566 | ã¤ã*/
|
---|
| 567 | syscall(slp_tsk());
|
---|
| 568 |
|
---|
| 569 | return error;
|
---|
| 570 | }
|
---|
| 571 |
|
---|
| 572 | /*
|
---|
| 573 | * TCP ECHO ã¯ã©ã¤ã¢ã³ãåä¿¡ã¿ã¹ã¯
|
---|
| 574 | */
|
---|
| 575 |
|
---|
| 576 | #ifdef USE_COPYSAVE_API
|
---|
| 577 |
|
---|
| 578 | void
|
---|
| 579 | tcp_echo_cli_rcv_task (intptr_t exinf)
|
---|
| 580 | {
|
---|
| 581 | ID tskid, cepid;
|
---|
| 582 | ER_UINT rlen;
|
---|
| 583 | ER error;
|
---|
| 584 | SYSTIM time;
|
---|
| 585 | uint32_t total;
|
---|
| 586 | uint16_t roff;
|
---|
| 587 | char *rmsg;
|
---|
| 588 |
|
---|
| 589 | get_tid(&tskid);
|
---|
| 590 | syslog(LOG_NOTICE, "[TCP ECHO CLI (CS) RCV:%d] started.", tskid);
|
---|
| 591 | while (true) {
|
---|
| 592 | if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {
|
---|
| 593 | syslog(LOG_NOTICE, "[TEC:%02d RCV] sync error: %s",
|
---|
| 594 | cepid, itron_strerror(error));
|
---|
| 595 | }
|
---|
| 596 | else {
|
---|
| 597 | roff = rcount = total = 0;
|
---|
| 598 | while (true) {
|
---|
| 599 | if ((rlen = tcp_rcv_buf(cepid, (void**)&rmsg, RCV_TMO)) < 0) {
|
---|
| 600 | syslog(LOG_NOTICE, "[TEC:%02d RCV] rcv buf error: %s",
|
---|
| 601 | cepid, itron_strerror(rlen));
|
---|
| 602 | break;
|
---|
| 603 | }
|
---|
| 604 | else if (rlen > 0) {
|
---|
| 605 | roff += (uint16_t)rlen;
|
---|
| 606 | total += rlen;
|
---|
| 607 | rcount ++;
|
---|
| 608 | #ifdef SHOW_RCV_RANGE
|
---|
| 609 | syslog(LOG_NOTICE, "[TEC:%02d RCV] recv count: %3d, len: %4d, data: %02x -> %02x",
|
---|
| 610 | cepid, rcount, (uint16_t)rlen, *rmsg, *(rmsg + rlen - 1));
|
---|
| 611 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 612 | }
|
---|
| 613 | else
|
---|
| 614 | break;
|
---|
| 615 | if ((error = tcp_rel_buf(cepid, rlen)) != E_OK)
|
---|
| 616 | syslog(LOG_NOTICE, "[TEC:%02d RCV] rel buf error: %s", cepid, itron_strerror(error));
|
---|
| 617 | }
|
---|
| 618 |
|
---|
| 619 | if ((error = tcp_cls_cep(cepid, CLS_TMO)) < 0)
|
---|
| 620 | syslog(LOG_NOTICE, "[TEC:%02d RCV] close error: %s", cepid, itron_strerror(error));
|
---|
| 621 |
|
---|
| 622 | get_tim(&time);
|
---|
| 623 | syslog(LOG_NOTICE, "[TEC:%02u RCV] finished: %6lu, snd: %4u, rcv: %4u, len: %u",
|
---|
| 624 | cepid, time / SYSTIM_HZ, scount, rcount, total);
|
---|
| 625 | }
|
---|
| 626 |
|
---|
| 627 | syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));
|
---|
| 628 | }
|
---|
| 629 | }
|
---|
| 630 |
|
---|
| 631 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
| 632 |
|
---|
| 633 | void
|
---|
| 634 | tcp_echo_cli_rcv_task (intptr_t exinf)
|
---|
| 635 | {
|
---|
| 636 | static char rmsg[RCV_BUF_SIZE];
|
---|
| 637 |
|
---|
| 638 | ID tskid, cepid;
|
---|
| 639 | ER_UINT rlen;
|
---|
| 640 | ER error;
|
---|
| 641 | SYSTIM time;
|
---|
| 642 | uint32_t total;
|
---|
| 643 | uint16_t roff;
|
---|
| 644 |
|
---|
| 645 | get_tid(&tskid);
|
---|
| 646 | syslog(LOG_NOTICE, "[TCP ECHO CLI RCV:%d] started.", tskid);
|
---|
| 647 | while (true) {
|
---|
| 648 | if ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t*)&cepid)) != E_OK) {
|
---|
| 649 | syslog(LOG_NOTICE, "[TEC:%02d RCV] sync error: %s",
|
---|
| 650 | cepid, itron_strerror(error));
|
---|
| 651 | }
|
---|
| 652 | else {
|
---|
| 653 | roff = rcount = total = 0;
|
---|
| 654 | while (true) {
|
---|
| 655 | if ((rlen = tcp_rcv_dat(cepid, rmsg, sizeof(rmsg), RCV_TMO)) < 0) {
|
---|
| 656 | syslog(LOG_NOTICE, "[TEC:%02d RCV] rcv dat error: %s", cepid, itron_strerror(rlen));
|
---|
| 657 | tcp_can_cep(cepid, TFN_TCP_ALL);
|
---|
| 658 | break;
|
---|
| 659 | }
|
---|
| 660 | else if (rlen > 0) {
|
---|
| 661 | roff += (uint16_t)rlen;
|
---|
| 662 | total += rlen;
|
---|
| 663 | rcount ++;
|
---|
| 664 | #ifdef SHOW_RCV_RANGE
|
---|
| 665 | syslog(LOG_NOTICE, "[TEC:%02d RCV] recv count: %3d, len: %4d, data: %02x -> %02x",
|
---|
| 666 | cepid, rcount, (uint16_t)rlen, *rmsg, *(rmsg + rlen - 1));
|
---|
| 667 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 668 | }
|
---|
| 669 | else
|
---|
| 670 | break;
|
---|
| 671 | }
|
---|
| 672 |
|
---|
| 673 | if ((error = tcp_cls_cep(cepid, CLS_TMO)) < 0)
|
---|
| 674 | syslog(LOG_NOTICE, "[TEC:%02d RCV] close error: %s", cepid, itron_strerror(error));
|
---|
| 675 |
|
---|
| 676 | get_tim(&time);
|
---|
| 677 | syslog(LOG_NOTICE, "[TEC:%02u RCV] received: %6lu, snd: %4u, rcv: %4u, len: %u",
|
---|
| 678 | cepid, time / SYSTIM_HZ, scount, rcount, total);
|
---|
| 679 | }
|
---|
| 680 |
|
---|
| 681 | syscall(wup_tsk(TCP_ECHO_CLI_SND_TASK));
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 |
|
---|
| 685 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
| 686 |
|
---|
| 687 | #endif /* of #ifdef USE_TCP_NON_BLOCKING */
|
---|
| 688 |
|
---|
| 689 | /*
|
---|
| 690 | * getcomd -- ã³ãã³ããå¾ãã
|
---|
| 691 | */
|
---|
| 692 |
|
---|
| 693 | #ifdef AUTO_RUN_STR
|
---|
| 694 |
|
---|
| 695 | static char *
|
---|
| 696 | getcomd (ID cepid)
|
---|
| 697 | {
|
---|
| 698 | ER error;
|
---|
| 699 | char *line = NULL;
|
---|
| 700 | static char auto_run_str[] = AUTO_RUN_STR;
|
---|
| 701 | static int_t count = 0;
|
---|
| 702 |
|
---|
| 703 | if (count == 0) {
|
---|
| 704 | line = auto_run_str;
|
---|
| 705 | dly_tsk(3 * 1000);
|
---|
| 706 | }
|
---|
| 707 | else {
|
---|
| 708 | while ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_SND, (intptr_t*)&line)) != E_OK) {
|
---|
| 709 | syslog(LOG_NOTICE, "[TEC:%02d TSK] error: %s", cepid, itron_strerror(error));
|
---|
| 710 | dly_tsk(SLP_ITV);
|
---|
| 711 | }
|
---|
| 712 | }
|
---|
| 713 |
|
---|
| 714 | count ++;
|
---|
| 715 | return line;
|
---|
| 716 | }
|
---|
| 717 |
|
---|
| 718 | #else /* of #ifdef AUTO_RUN_STR */
|
---|
| 719 |
|
---|
| 720 | static char *
|
---|
| 721 | getcomd (ID cepid)
|
---|
| 722 | {
|
---|
| 723 | ER error;
|
---|
| 724 | char *line = NULL;
|
---|
| 725 |
|
---|
| 726 | while ((error = rcv_dtq(DTQ_TCP_ECHO_CLI_SND, (intptr_t*)&line)) != E_OK) {
|
---|
| 727 | syslog(LOG_NOTICE, "[TEC:%02d TSK] error: %s", cepid, itron_strerror(error));
|
---|
| 728 | dly_tsk(SLP_ITV);
|
---|
| 729 | }
|
---|
| 730 | return line;
|
---|
| 731 | }
|
---|
| 732 |
|
---|
| 733 | #endif /* of #ifdef AUTO_RUN_STR */
|
---|
| 734 |
|
---|
| 735 | /*
|
---|
| 736 | * TCP ECHO ã¯ã©ã¤ã¢ã³ãéä¿¡ã¿ã¹ã¯
|
---|
| 737 | */
|
---|
| 738 |
|
---|
| 739 | void
|
---|
| 740 | tcp_echo_cli_snd_task (intptr_t exinf)
|
---|
| 741 | {
|
---|
| 742 | ID tskid, cepid;
|
---|
| 743 | ER error;
|
---|
| 744 | T_IN_ADDR addr;
|
---|
| 745 | uint16_t portno;
|
---|
| 746 | int_t rep, count;
|
---|
| 747 | char *line;
|
---|
| 748 |
|
---|
| 749 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 750 |
|
---|
| 751 | T_TCP_CCEP ccep;
|
---|
| 752 |
|
---|
| 753 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 754 |
|
---|
| 755 | get_tid(&tskid);
|
---|
| 756 | syslog(LOG_NOTICE, "[TCP ECHO CLI SND:%d,%d] started.", tskid, (ID)exinf);
|
---|
| 757 | while (true) {
|
---|
| 758 | line = getcomd((ID)exinf);
|
---|
| 759 | line = skip_blanks(GET_IPADDR(&addr, skip_blanks(line))); /* IP Address */
|
---|
| 760 |
|
---|
| 761 | if ('0' <= *line && *line <= '9') { /* Port No */
|
---|
| 762 | line = get_int(&rep, line);
|
---|
| 763 | portno = (uint16_t)rep;
|
---|
| 764 | }
|
---|
| 765 | else {
|
---|
| 766 | line ++;
|
---|
| 767 | portno = ECHO_SRV_PORTNO;
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | line = skip_blanks(line);
|
---|
| 771 | if ('0' <= *line && *line <= '9') /* Repeat */
|
---|
| 772 | line = get_int(&rep, line);
|
---|
| 773 | else
|
---|
| 774 | rep = 1;
|
---|
| 775 |
|
---|
| 776 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 777 |
|
---|
| 778 | ccep.cepatr = 0;
|
---|
| 779 | ccep.sbufsz = TCP_ECHO_CLI_SWBUF_SIZE;
|
---|
| 780 | ccep.rbufsz = TCP_ECHO_CLI_RWBUF_SIZE;
|
---|
| 781 |
|
---|
| 782 | #ifdef TCP_CFG_SWBUF_CSAVE
|
---|
| 783 | ccep.sbuf = NADR;
|
---|
| 784 | #else
|
---|
| 785 | ccep.sbuf = tcp_echo_cli_swbuf;
|
---|
| 786 | #endif
|
---|
| 787 | #ifdef TCP_CFG_RWBUF_CSAVE
|
---|
| 788 | ccep.rbuf = NADR;
|
---|
| 789 | #else
|
---|
| 790 | ccep.rbuf = tcp_echo_cli_rwbuf;
|
---|
| 791 | #endif
|
---|
| 792 | #ifdef USE_TCP_NON_BLOCKING
|
---|
| 793 | ccep.callback = (FP)callback_nblk_tcp_echo_cli;
|
---|
| 794 | #else
|
---|
| 795 | ccep.callback = NULL;
|
---|
| 796 | #endif
|
---|
| 797 |
|
---|
| 798 | if ((error = alloc_tcp_cep(&cepid, tskid, &ccep)) != E_OK) {
|
---|
| 799 | syslog(LOG_NOTICE, "[TEC:%02d TSK] CEP create error: %s", cepid, itron_strerror(error));
|
---|
| 800 | continue;
|
---|
| 801 | }
|
---|
| 802 |
|
---|
| 803 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 804 |
|
---|
| 805 | cepid = (ID)exinf;
|
---|
| 806 |
|
---|
| 807 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 808 |
|
---|
| 809 | tcp_echo_cli_valid = true;
|
---|
| 810 | count = 0;
|
---|
| 811 | while (rep == 0 || count < rep) {
|
---|
| 812 | if (!tcp_echo_cli_valid) {
|
---|
| 813 | syslog(LOG_NOTICE, "[TEC:%02d TSK] canceled.", cepid);
|
---|
| 814 | break;
|
---|
| 815 | }
|
---|
| 816 |
|
---|
| 817 | count ++;
|
---|
| 818 | if (rep == 0) {
|
---|
| 819 | syslog(LOG_NOTICE, "[TEC:%02d TSK] start: repeat: %d", cepid, count);
|
---|
| 820 | error = send_tcp_echo(cepid, &addr, portno);
|
---|
| 821 | syslog(LOG_NOTICE, "[TEC:%02d TSK] finished: repeat: %d", cepid, count);
|
---|
| 822 | }
|
---|
| 823 | else {
|
---|
| 824 | syslog(LOG_NOTICE, "[TEC:%02d TSK] start: repeat: %d/%d", cepid, count, rep);
|
---|
| 825 | error = send_tcp_echo(cepid, &addr, portno);
|
---|
| 826 | syslog(LOG_NOTICE, "[TEC:%02d TSK] finished: repeat: %d/%d", cepid, count, rep);
|
---|
| 827 | }
|
---|
| 828 |
|
---|
| 829 | if (error != E_OK) {
|
---|
| 830 | syslog(LOG_NOTICE, "[TEC:%02d TSK] sleep %d[ms], error: %s",
|
---|
| 831 | cepid, SLP_ITV, itron_strerror(error));
|
---|
| 832 | tslp_tsk(SLP_ITV);
|
---|
| 833 | syslog(LOG_NOTICE, "[TEC:%02d TSK] resume.", cepid);
|
---|
| 834 | }
|
---|
| 835 |
|
---|
| 836 | #if defined(SND_ITV)
|
---|
| 837 | #if SND_ITV > 0
|
---|
| 838 | if (count > 0) {
|
---|
| 839 | uint_t itv;
|
---|
| 840 |
|
---|
| 841 | itv = SND_ITV;
|
---|
| 842 | syslog(LOG_NOTICE, "[TEC:%02d TSK] interval: %d[ms].", cepid, itv);
|
---|
| 843 | syscall(dly_tsk(SND_ITV));
|
---|
| 844 | }
|
---|
| 845 | #endif
|
---|
| 846 | #endif
|
---|
| 847 | }
|
---|
| 848 |
|
---|
| 849 | #ifdef USE_TCP_EXTENTIONS
|
---|
| 850 |
|
---|
| 851 | if ((error = free_tcp_cep(cepid)) != E_OK)
|
---|
| 852 | syslog(LOG_NOTICE, "[TEC:%02d TSK] CEP delete error: %s", cepid, itron_strerror(error));
|
---|
| 853 |
|
---|
| 854 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 855 |
|
---|
| 856 | }
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | #endif /* of #ifdef USE_TCP_ECHO_CLI */
|
---|