[317] | 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 |
|
---|
| 47 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 48 |
|
---|
| 49 | #ifdef TARGET_KERNEL_JSP
|
---|
| 50 |
|
---|
| 51 | #include <t_services.h>
|
---|
| 52 | #include "kernel_id.h"
|
---|
| 53 |
|
---|
| 54 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 55 |
|
---|
| 56 | #include <netinet/in.h>
|
---|
| 57 | #include <netinet/in_itron.h>
|
---|
| 58 |
|
---|
| 59 | #include <netapp/netapp.h>
|
---|
| 60 | #include <netapp/netapp_var.h>
|
---|
| 61 | #include <netapp/tcp_echo_cli.h>
|
---|
| 62 |
|
---|
| 63 | #ifdef USE_TCP_ECHO_CLI
|
---|
| 64 |
|
---|
| 65 | /* 表示 */
|
---|
| 66 |
|
---|
| 67 | //#define SHOW_TIME_OUT
|
---|
| 68 | //#define SHOW_SND_COUNT
|
---|
| 69 |
|
---|
| 70 | /* タイムアウト */
|
---|
| 71 |
|
---|
| 72 | #ifdef TOPPERS_S810_CLG3_85
|
---|
| 73 |
|
---|
| 74 | #define CON_TMO TMO_FEVR
|
---|
| 75 | //#define CON_TMO (60*SYSTIM_HZ)
|
---|
| 76 | //#define SND_TMO TMO_FEVR
|
---|
| 77 | #define SND_TMO (30*SYSTIM_HZ)
|
---|
| 78 |
|
---|
| 79 | #else /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 80 |
|
---|
| 81 | #define CON_TMO TMO_FEVR
|
---|
| 82 | //#define CON_TMO (60*SYSTIM_HZ)
|
---|
| 83 | //#define SND_TMO TMO_FEVR
|
---|
| 84 | #define SND_TMO (30*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*30)
|
---|
| 85 |
|
---|
| 86 | #endif /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 87 |
|
---|
| 88 | #ifdef USE_TCP_NON_BLOCKING
|
---|
| 89 |
|
---|
| 90 | /*
|
---|
| 91 | * 変数
|
---|
| 92 | */
|
---|
| 93 |
|
---|
| 94 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
|
---|
| 95 |
|
---|
| 96 | static T_IPV4EP nblk_src4 = {
|
---|
| 97 | IPV4_ADDRANY,
|
---|
| 98 | TCP_PORTANY,
|
---|
| 99 | };
|
---|
| 100 | static T_IPV4EP nblk_dst4;
|
---|
| 101 |
|
---|
| 102 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 103 |
|
---|
| 104 | static T_IPEP nblk_src = {
|
---|
| 105 | IP_ADDRANY,
|
---|
| 106 | TCP_PORTANY,
|
---|
| 107 | };
|
---|
| 108 | static T_IPEP nblk_dst;
|
---|
| 109 |
|
---|
| 110 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
|
---|
| 111 |
|
---|
| 112 | /*
|
---|
| 113 | * tcp4_active_open -- 能動オープンを実行する。
|
---|
| 114 | *
|
---|
| 115 | * USE_TCP_NON_BLOCKING ON
|
---|
| 116 | */
|
---|
| 117 |
|
---|
| 118 | static ER
|
---|
| 119 | tcp4_active_open (ID cepid, T_IN4_ADDR ipaddr, uint16_t portno)
|
---|
| 120 | {
|
---|
| 121 | ER error;
|
---|
| 122 | SYSTIM time;
|
---|
| 123 |
|
---|
| 124 | nblk_dst4.ipaddr = ipaddr;
|
---|
| 125 | nblk_dst4.portno = portno;
|
---|
| 126 |
|
---|
| 127 | if ((error = tcp_con_cep(cepid, &nblk_src4, &nblk_dst4, TMO_NBLK)) != E_WBLK) {
|
---|
| 128 | syslog(LOG_NOTICE, "[TEC4:%02u CON] error: %s", cepid, itron_strerror(error));
|
---|
| 129 | return error;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | /* 接続が完了するまで待つ。*/
|
---|
| 133 | syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 134 |
|
---|
| 135 | if ((error = tcp_echo_cli_nblk_error) != E_OK) {
|
---|
| 136 | syslog(LOG_NOTICE, "[TEC4:%02u CON] error: %s", cepid, itron_strerror(tcp_echo_cli_nblk_error));
|
---|
| 137 | return error;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | get_tim(&time);
|
---|
| 141 | syslog(LOG_NOTICE, "[TEC4:%02u CON] conct: %7lu, to: %s.%u",
|
---|
| 142 | cepid, time / SYSTIM_HZ, ip2str(NULL, &nblk_dst4.ipaddr), nblk_dst4.portno);
|
---|
| 143 | return error;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 147 |
|
---|
| 148 | /*
|
---|
| 149 | * tcp_active_open -- 能動オープンを実行する。
|
---|
| 150 | *
|
---|
| 151 | * USE_TCP_NON_BLOCKING ON
|
---|
| 152 | */
|
---|
| 153 |
|
---|
| 154 | static ER
|
---|
| 155 | tcp_active_open (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno, char apip)
|
---|
| 156 | {
|
---|
| 157 | ER error;
|
---|
| 158 | SYSTIM time;
|
---|
| 159 |
|
---|
| 160 | nblk_dst.ipaddr = *ipaddr;
|
---|
| 161 | nblk_dst.portno = portno;
|
---|
| 162 |
|
---|
| 163 | if ((error = TCP_CON_CEP(cepid, &nblk_src, &nblk_dst, TMO_NBLK)) != E_WBLK) {
|
---|
| 164 | if (error == E_PAR || error == E_ID)
|
---|
| 165 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] error: %s, API: IPv%c, addr: %s",
|
---|
| 166 | apip, cepid, itron_strerror(error), apip, IP2STR(NULL, ipaddr));
|
---|
| 167 | else
|
---|
| 168 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] error: %s",
|
---|
| 169 | apip, cepid, itron_strerror(error));
|
---|
| 170 | return error;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | /* 接続が完了するまで待つ。*/
|
---|
| 174 | syscall(wai_sem(SEM_TCP_ECHO_CLI_NBLK_READY));
|
---|
| 175 |
|
---|
| 176 | if ((error = tcp_echo_cli_nblk_error) != E_OK) {
|
---|
| 177 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] error: %s",
|
---|
| 178 | apip, cepid, itron_strerror(tcp_echo_cli_nblk_error));
|
---|
| 179 | return error;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | get_tim(&time);
|
---|
| 183 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] conct: %7lu, to: %s.%u",
|
---|
| 184 | apip, cepid, time / SYSTIM_HZ,
|
---|
| 185 | IP2STR(NULL, &nblk_dst.ipaddr), nblk_dst.portno);
|
---|
| 186 | return error;
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | /*
|
---|
| 190 | * tcp_echo_cli_snd -- ECHO/TCP サーバにメッセージを送信する。
|
---|
| 191 | *
|
---|
| 192 | * USE_TCP_NON_BLOCKING ON
|
---|
| 193 | */
|
---|
| 194 |
|
---|
| 195 | ER
|
---|
| 196 | tcp_echo_cli_snd (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno, char apip)
|
---|
| 197 | {
|
---|
| 198 | static char smsg[SND_BUF_SIZE];
|
---|
| 199 |
|
---|
| 200 | ER_UINT slen;
|
---|
| 201 | ER error;
|
---|
| 202 | uint32_t total;
|
---|
| 203 | uint16_t soff, echo, rep;
|
---|
| 204 | char *p, pat;
|
---|
| 205 |
|
---|
| 206 | #ifdef SND_URG_DATA_SIZE
|
---|
| 207 | int_t urg = SND_URG_COUNT;
|
---|
| 208 | #endif
|
---|
| 209 |
|
---|
| 210 | p = smsg;
|
---|
| 211 | for (rep = NUM_REP_PAT; rep -- > 0; )
|
---|
| 212 | for (pat = PAT_BEGIN; pat <= PAT_END; pat ++)
|
---|
| 213 | *p ++ = pat;
|
---|
| 214 |
|
---|
| 215 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
|
---|
| 216 |
|
---|
| 217 | if (apip == API_PROTO_IPV6) {
|
---|
| 218 | if ((error = tcp_active_open(cepid, ipaddr, portno, apip)) != E_OK)
|
---|
| 219 | return error;
|
---|
| 220 | }
|
---|
| 221 | else if (in6_is_addr_ipv4mapped(ipaddr)) {
|
---|
| 222 | if ((error = tcp4_active_open(cepid, ntohl(ipaddr->s6_addr32[3]), portno)) != E_OK)
|
---|
| 223 | return error;
|
---|
| 224 | }
|
---|
| 225 | else {
|
---|
| 226 | if ((error = tcp_active_open(cepid, ipaddr, portno, apip)) != E_OK)
|
---|
| 227 | return error;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 231 |
|
---|
| 232 | if ((error = tcp_active_open(cepid, ipaddr, portno, apip)) != E_OK)
|
---|
| 233 | return error;
|
---|
| 234 |
|
---|
| 235 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 236 |
|
---|
| 237 | if ((error = psnd_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t)cepid)) != E_OK) {
|
---|
| 238 | syslog(LOG_NOTICE, "[TEC%c:%02u DTQ] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 239 | goto cls_ret;
|
---|
| 240 | }
|
---|
| 241 |
|
---|
| 242 | tcp_echo_cli_scount = total = 0;
|
---|
| 243 | for (echo = NUM_ECHO; echo -- > 0; ) {
|
---|
| 244 | soff = 0;
|
---|
| 245 | while (soff < SND_BUF_SIZE) {
|
---|
| 246 | #ifdef SHOW_TIME_OUT
|
---|
| 247 | syslog(LOG_NOTICE, "[TEC%c:%02u SND] tmo: %7lu", apip, cepid, SND_TMO);;
|
---|
| 248 | #endif/* of #ifdef SHOW_TIME_OUT */
|
---|
| 249 | if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, SND_TMO)) < 0) {
|
---|
| 250 | syslog(LOG_NOTICE, "[TEC%c:%02u SND] error: %s",
|
---|
| 251 | apip, cepid, itron_strerror(slen));
|
---|
| 252 | error = slen;
|
---|
| 253 | goto cls_ret;
|
---|
| 254 | }
|
---|
| 255 | soff += (uint16_t)slen;
|
---|
| 256 | total += slen;
|
---|
| 257 | tcp_echo_cli_scount ++;
|
---|
| 258 | #ifdef SHOW_SND_COUNT
|
---|
| 259 | syslog(LOG_NOTICE, "[TEC%c:%02u SND] count: %7lu, len: %4u, off: %4u",
|
---|
| 260 | apip, cepid, tcp_echo_cli_scount, (uint16_t)slen, soff);
|
---|
| 261 | #endif/* of #ifdef SHOW_SND_COUNT */
|
---|
| 262 |
|
---|
| 263 | #ifdef SND_URG_DATA_SIZE
|
---|
| 264 | if (urg) {
|
---|
| 265 | if (urg == 1) {
|
---|
| 266 | if ((error = tcp_snd_oob(cepid, smsg, SND_URG_DATA_SIZE, TMO_NBLK)) != E_WBLK)
|
---|
| 267 | syslog(LOG_NOTICE, "[TEC%c:%02u OOB] error: %s",
|
---|
| 268 | apip, cepid, itron_strerror(error));
|
---|
| 269 | }
|
---|
| 270 | urg --;
|
---|
| 271 | }
|
---|
| 272 | #endif/* of #ifdef SND_URG_DATA_SIZE */
|
---|
| 273 |
|
---|
| 274 | #if defined(SND_DLY)
|
---|
| 275 | #if SND_DLY > 0
|
---|
| 276 | syscall(dly_tsk(SND_DLY + netapp_rand() % SYSTIM_HZ));
|
---|
| 277 | #endif
|
---|
| 278 | #endif
|
---|
| 279 | }
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | cls_ret:
|
---|
| 283 | if ((error = tcp_sht_cep(cepid)) < 0)
|
---|
| 284 | syslog(LOG_NOTICE, "[TEC%c:%02u SHT] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 285 |
|
---|
| 286 | /* 受信が完了するまで待つ。*/
|
---|
| 287 | syscall(slp_tsk());
|
---|
| 288 |
|
---|
| 289 | return error;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | #else /* of #ifdef USE_TCP_NON_BLOCKING */
|
---|
| 293 |
|
---|
| 294 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
|
---|
| 295 |
|
---|
| 296 | /*
|
---|
| 297 | * tcp4_active_open -- 能動オープンを実行する。
|
---|
| 298 | *
|
---|
| 299 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 300 | */
|
---|
| 301 |
|
---|
| 302 | static ER
|
---|
| 303 | tcp4_active_open (ID cepid, T_IN4_ADDR ipaddr, uint16_t portno)
|
---|
| 304 | {
|
---|
| 305 | static T_IPV4EP src = {
|
---|
| 306 | IPV4_ADDRANY,
|
---|
| 307 | TCP_PORTANY,
|
---|
| 308 | };
|
---|
| 309 |
|
---|
| 310 | T_IPV4EP dst;
|
---|
| 311 | ER error;
|
---|
| 312 | SYSTIM time;
|
---|
| 313 |
|
---|
| 314 | dst.ipaddr = ipaddr;
|
---|
| 315 | dst.portno = portno;
|
---|
| 316 |
|
---|
| 317 | #ifdef SHOW_TIME_OUT
|
---|
| 318 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] tmo: %7lu", API_PROTO_IPV4, cepid, CON_TMO);
|
---|
| 319 | #endif /* of #ifdef SHOW_TIME_OUT */
|
---|
| 320 | if ((error = tcp_con_cep(cepid, &src, &dst, CON_TMO)) != E_OK) {
|
---|
| 321 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] error: %s, addr: %s",
|
---|
| 322 | API_PROTO_IPV4, cepid, itron_strerror(error), ip2str(NULL, &ipaddr));
|
---|
| 323 | return error;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | get_tim(&time);
|
---|
| 327 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] conct: %7lu, to: %s.%u",
|
---|
| 328 | API_PROTO_IPV4, cepid, time / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno);
|
---|
| 329 | return error;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 333 |
|
---|
| 334 | /*
|
---|
| 335 | * tcp_active_open -- 能動オープンを実行する。
|
---|
| 336 | *
|
---|
| 337 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 338 | */
|
---|
| 339 |
|
---|
| 340 | static ER
|
---|
| 341 | tcp_active_open (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno, char apip)
|
---|
| 342 | {
|
---|
| 343 | static T_IPEP src = {
|
---|
| 344 | IP_ADDRANY,
|
---|
| 345 | TCP_PORTANY,
|
---|
| 346 | };
|
---|
| 347 |
|
---|
| 348 | T_IPEP dst;
|
---|
| 349 | ER error;
|
---|
| 350 | SYSTIM time;
|
---|
| 351 |
|
---|
| 352 | dst.ipaddr = *ipaddr;
|
---|
| 353 | dst.portno = portno;
|
---|
| 354 |
|
---|
| 355 | #ifdef SHOW_TIME_OUT
|
---|
| 356 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] tmo: %7lu", apip, cepid, CON_TMO);
|
---|
| 357 | #endif /* of #ifdef SHOW_TIME_OUT */
|
---|
| 358 | if ((error = TCP_CON_CEP(cepid, &src, &dst, CON_TMO)) != E_OK) {
|
---|
| 359 | if (error == E_PAR || error == E_ID)
|
---|
| 360 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] error: %s, API: IPv%c, addr: %s",
|
---|
| 361 | apip, cepid, itron_strerror(error), apip, IP2STR(NULL, ipaddr));
|
---|
| 362 | else
|
---|
| 363 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 364 | return error;
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | get_tim(&time);
|
---|
| 368 | syslog(LOG_NOTICE, "[TEC%c:%02u CON] conct: %7lu, to: %s.%u",
|
---|
| 369 | apip, cepid, time / SYSTIM_HZ, IP2STR(NULL, &dst.ipaddr), dst.portno);
|
---|
| 370 | return error;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
| 373 | /*
|
---|
| 374 | * tcp_echo_cli_snd -- ECHO/TCP サーバにメッセージを送信する。
|
---|
| 375 | *
|
---|
| 376 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 377 | */
|
---|
| 378 |
|
---|
| 379 | ER
|
---|
| 380 | tcp_echo_cli_snd (ID cepid, T_IN_ADDR *ipaddr, uint16_t portno, char apip)
|
---|
| 381 | {
|
---|
| 382 | static char smsg[SND_BUF_SIZE];
|
---|
| 383 |
|
---|
| 384 | ER_UINT slen;
|
---|
| 385 | ER error;
|
---|
| 386 | uint32_t total;
|
---|
| 387 | uint16_t soff, echo, rep;
|
---|
| 388 | char *p, pat;
|
---|
| 389 |
|
---|
| 390 | #ifdef SND_URG_DATA_SIZE
|
---|
| 391 | int_t urg = SND_URG_COUNT;
|
---|
| 392 | #endif
|
---|
| 393 |
|
---|
| 394 | p = smsg;
|
---|
| 395 | for (rep = NUM_REP_PAT; rep -- > 0; )
|
---|
| 396 | for (pat = PAT_BEGIN; pat <= PAT_END; pat ++)
|
---|
| 397 | *p ++ = pat;
|
---|
| 398 |
|
---|
| 399 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI)
|
---|
| 400 |
|
---|
| 401 | if (apip == API_PROTO_IPV6) {
|
---|
| 402 | if ((error = tcp_active_open(cepid, ipaddr, portno, apip)) != E_OK)
|
---|
| 403 | return error;
|
---|
| 404 | }
|
---|
| 405 | else if (in6_is_addr_ipv4mapped(ipaddr)) {
|
---|
| 406 | if ((error = tcp4_active_open(cepid, ntohl(ipaddr->s6_addr32[3]), portno)) != E_OK)
|
---|
| 407 | return error;
|
---|
| 408 | }
|
---|
| 409 | else {
|
---|
| 410 | if ((error = tcp_active_open(cepid, ipaddr, portno, apip)) != E_OK)
|
---|
| 411 | return error;
|
---|
| 412 | }
|
---|
| 413 |
|
---|
| 414 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 415 |
|
---|
| 416 | if ((error = tcp_active_open(cepid, ipaddr, portno, apip)) != E_OK)
|
---|
| 417 | return error;
|
---|
| 418 |
|
---|
| 419 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_CLI) */
|
---|
| 420 |
|
---|
| 421 | if ((error = psnd_dtq(DTQ_TCP_ECHO_CLI_RCV, (intptr_t)cepid)) != E_OK) {
|
---|
| 422 | syslog(LOG_NOTICE, "[TEC%c:%02u DTQ] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 423 | goto cls_ret;
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | tcp_echo_cli_scount = total = 0;
|
---|
| 427 | for (echo = NUM_ECHO; echo -- > 0; ) {
|
---|
| 428 | soff = 0;
|
---|
| 429 | while (soff < SND_BUF_SIZE) {
|
---|
| 430 | #ifdef SHOW_TIME_OUT
|
---|
| 431 | syslog(LOG_NOTICE, "[TEC%c:%02u SND] tmo: %7lu", apip, cepid, SND_TMO);
|
---|
| 432 | #endif /* of #ifdef SHOW_TIME_OUT */
|
---|
| 433 | if ((slen = tcp_snd_dat(cepid, smsg + soff, sizeof(smsg) - soff, SND_TMO)) < 0) {
|
---|
| 434 | syslog(LOG_NOTICE, "[TEC%c:%02u SND] error: %s", apip, cepid, itron_strerror(slen));
|
---|
| 435 | error = slen;
|
---|
| 436 | goto cls_ret;
|
---|
| 437 | }
|
---|
| 438 | soff += (uint16_t)slen;
|
---|
| 439 | total += slen;
|
---|
| 440 | tcp_echo_cli_scount ++;
|
---|
| 441 | #ifdef SHOW_SND_COUNT
|
---|
| 442 | syslog(LOG_NOTICE, "[TEC%c:%02u SND] count: %7lu, len: %4u",
|
---|
| 443 | apip, cepid, tcp_echo_cli_scount, (uint16_t)slen);
|
---|
| 444 | #endif /* of #ifdef SHOW_SND_COUNT */
|
---|
| 445 |
|
---|
| 446 | #ifdef SND_URG_DATA_SIZE
|
---|
| 447 | if (urg > 0) {
|
---|
| 448 | if (urg == 1) {
|
---|
| 449 | #ifdef SHOW_TIME_OUT
|
---|
| 450 | syslog(LOG_NOTICE, "[TEC%c:%02u SND] tmo: %7lu", apip, cepid, SND_TMO);
|
---|
| 451 | #endif /* of #ifdef SHOW_TIME_OUT */
|
---|
| 452 | if ((slen = tcp_snd_oob(cepid, smsg, SND_URG_DATA_SIZE, SND_TMO)) >= 0)
|
---|
| 453 | syslog(LOG_NOTICE, "[TEC%c:%02u SND] urg: %7lu",
|
---|
| 454 | apip, cepid, (uint16_6)slen);
|
---|
| 455 | else
|
---|
| 456 | syslog(LOG_NOTICE, "[TEC%c:%02u OOB] error: %s",
|
---|
| 457 | apip, cepid, itron_strerror(slen));
|
---|
| 458 | }
|
---|
| 459 | urg --;
|
---|
| 460 | }
|
---|
| 461 | #endif /* of #ifdef SND_URG_DATA_SIZE */
|
---|
| 462 |
|
---|
| 463 | #if defined(SND_DLY)
|
---|
| 464 | #if SND_DLY > 0
|
---|
| 465 | syscall(dly_tsk(SND_DLY + netapp_rand() % SYSTIM_HZ));
|
---|
| 466 | #endif
|
---|
| 467 | #endif
|
---|
| 468 | }
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | cls_ret:
|
---|
| 472 | if ((error = tcp_sht_cep(cepid)) < 0)
|
---|
| 473 | syslog(LOG_NOTICE, "[TEC%c:%02u SHT] error: %s", apip, cepid, itron_strerror(error));
|
---|
| 474 |
|
---|
| 475 | /* 受信が完了するまで待つ。*/
|
---|
| 476 | syscall(slp_tsk());
|
---|
| 477 |
|
---|
| 478 | return error;
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | #endif /* of #ifdef USE_TCP_NON_BLOCKING */
|
---|
| 482 |
|
---|
| 483 | #endif /* of #ifdef USE_TCP_ECHO_CLI */
|
---|