[270] | 1 | /*
|
---|
| 2 | * TINET (TCP/IP Protocol Stack)
|
---|
| 3 | *
|
---|
[331] | 4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
[270] | 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 サーバ #1
|
---|
| 36 | *
|
---|
| 37 | * ・送受信タスク同一型
|
---|
| 38 | * ・ノンブロッキングコール
|
---|
| 39 | * ・省コピー API
|
---|
| 40 | * ・IPv4/IPv6
|
---|
| 41 | * ・緊急データの受信
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | #include <string.h>
|
---|
| 45 |
|
---|
| 46 | #ifdef TARGET_KERNEL_ASP
|
---|
| 47 |
|
---|
| 48 | #include <kernel.h>
|
---|
| 49 | #include <sil.h>
|
---|
| 50 | #include <t_syslog.h>
|
---|
| 51 | #include "kernel_cfg.h"
|
---|
| 52 | #include "tinet_cfg.h"
|
---|
| 53 |
|
---|
| 54 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
| 55 |
|
---|
| 56 | #ifdef TARGET_KERNEL_JSP
|
---|
| 57 |
|
---|
| 58 | #include <t_services.h>
|
---|
| 59 | #include "kernel_id.h"
|
---|
| 60 | #include "tinet_id.h"
|
---|
| 61 |
|
---|
| 62 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
| 63 |
|
---|
| 64 | #include <netinet/in.h>
|
---|
| 65 | #include <netinet/in_itron.h>
|
---|
| 66 |
|
---|
| 67 | #include <netapp/netapp.h>
|
---|
| 68 | #include <netapp/netapp_var.h>
|
---|
[331] | 69 | #include <netapp/tcp_echo_srv1.h>
|
---|
| 70 | #include <netapp/tcp_echo_srv1_var.h>
|
---|
[270] | 71 |
|
---|
[331] | 72 | #if defined(_NET_CFG_BYTE_ORDER)
|
---|
| 73 | #error "net/net.h included."
|
---|
| 74 | #endif
|
---|
| 75 |
|
---|
[270] | 76 | #ifdef USE_TCP_ECHO_SRV1
|
---|
| 77 |
|
---|
| 78 | /*
|
---|
| 79 | * 表示
|
---|
| 80 | */
|
---|
| 81 |
|
---|
| 82 | //#define SHOW_RCV_RANGE
|
---|
| 83 |
|
---|
| 84 | /*
|
---|
| 85 | * コネクション切断方法の指定
|
---|
| 86 | */
|
---|
| 87 |
|
---|
| 88 | #define USE_TCP_SHT_CEP
|
---|
| 89 |
|
---|
| 90 | /*
|
---|
| 91 | * タイムアウト
|
---|
| 92 | */
|
---|
| 93 |
|
---|
[331] | 94 | #ifdef TOPPERS_S810_CLG3_85
|
---|
| 95 |
|
---|
| 96 | #define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */
|
---|
| 97 | //#define RCV_TMO TMO_FEVR
|
---|
| 98 | #define RCV_TMO (30*SYSTIM_HZ)
|
---|
| 99 | //#define SND_TMO TMO_FEVR
|
---|
| 100 | #define SND_TMO (30*SYSTIM_HZ)
|
---|
| 101 |
|
---|
| 102 | #else /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 103 |
|
---|
[270] | 104 | //#define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */
|
---|
[331] | 105 | #define CLS_TMO (70*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*10)
|
---|
[270] | 106 | //#define RCV_TMO TMO_FEVR
|
---|
[331] | 107 | #define RCV_TMO (30*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*30)
|
---|
[270] | 108 | //#define SND_TMO TMO_FEVR
|
---|
[331] | 109 | #define SND_TMO (40*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*20)
|
---|
[270] | 110 |
|
---|
[331] | 111 | #endif /* of #ifdef TOPPERS_S810_CLG3_85 */
|
---|
| 112 |
|
---|
[270] | 113 | /*
|
---|
| 114 | * 全域変数
|
---|
| 115 | */
|
---|
| 116 |
|
---|
| 117 | /* TCP 送受信ウィンドバッファ */
|
---|
| 118 |
|
---|
| 119 | #ifndef TCP_CFG_SWBUF_CSAVE
|
---|
| 120 | uint8_t tcp_echo_srv_swbuf[NUM_TCP_ECHO_SRV_TASKS][TCP_ECHO_SRV_SWBUF_SIZE];
|
---|
| 121 | #endif
|
---|
| 122 |
|
---|
| 123 | #ifndef TCP_CFG_RWBUF_CSAVE
|
---|
| 124 | uint8_t tcp_echo_srv_rwbuf[NUM_TCP_ECHO_SRV_TASKS][TCP_ECHO_SRV_RWBUF_SIZE];
|
---|
| 125 | #endif
|
---|
| 126 |
|
---|
[331] | 127 | #ifndef USE_TCP_NON_BLOCKING
|
---|
| 128 |
|
---|
[270] | 129 | /*
|
---|
| 130 | * 変数
|
---|
| 131 | */
|
---|
| 132 |
|
---|
[331] | 133 | #ifdef USE_TCP_EXTENTIONS
|
---|
[270] | 134 |
|
---|
[331] | 135 | T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[NUM_TCP_ECHO_SRV_TASKS];
|
---|
[270] | 136 |
|
---|
[331] | 137 | #else /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
[270] | 138 |
|
---|
[331] | 139 | T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[] = {
|
---|
[270] | 140 |
|
---|
[331] | 141 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV)
|
---|
[270] | 142 |
|
---|
[331] | 143 | { TCP4_ECHO_SRV_CEPID1, TCP4_ECHO_SRV_REPID },
|
---|
[270] | 144 |
|
---|
[331] | 145 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
[270] | 146 |
|
---|
[331] | 147 | { TCP_ECHO_SRV_CEPID1, TCP_ECHO_SRV_REPID },
|
---|
[270] | 148 |
|
---|
[331] | 149 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
[270] | 150 |
|
---|
[331] | 151 | #if NUM_TCP_ECHO_SRV_TASKS >= 2
|
---|
| 152 | { TCP_ECHO_SRV_CEPID2, TCP_ECHO_SRV_REPID },
|
---|
| 153 | #endif
|
---|
| 154 | #if NUM_TCP_ECHO_SRV_TASKS >= 3
|
---|
| 155 | { TCP_ECHO_SRV_CEPID3, TCP_ECHO_SRV_REPID },
|
---|
| 156 | #endif
|
---|
| 157 | #if NUM_TCP_ECHO_SRV_TASKS >= 4
|
---|
| 158 | { TCP_ECHO_SRV_CEPID4, TCP_ECHO_SRV_REPID },
|
---|
| 159 | #endif
|
---|
| 160 | #if NUM_TCP_ECHO_SRV_TASKS >= 5
|
---|
| 161 | { TCP_ECHO_SRV_CEPID5, TCP_ECHO_SRV_REPID },
|
---|
| 162 | #endif
|
---|
| 163 | #if NUM_TCP_ECHO_SRV_TASKS >= 6
|
---|
| 164 | { TCP_ECHO_SRV_CEPID6, TCP_ECHO_SRV_REPID },
|
---|
| 165 | #endif
|
---|
| 166 | #if NUM_TCP_ECHO_SRV_TASKS >= 7
|
---|
| 167 | { TCP_ECHO_SRV_CEPID7, TCP_ECHO_SRV_REPID },
|
---|
| 168 | #endif
|
---|
| 169 | #if NUM_TCP_ECHO_SRV_TASKS >= 8
|
---|
| 170 | { TCP_ECHO_SRV_CEPID8, TCP_ECHO_SRV_REPID },
|
---|
| 171 | #endif
|
---|
[270] | 172 |
|
---|
[331] | 173 | };
|
---|
[270] | 174 |
|
---|
[331] | 175 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
[270] | 176 |
|
---|
| 177 | /*
|
---|
[331] | 178 | * tcp_passive_open -- 受動オープンを実行する。
|
---|
| 179 | *
|
---|
| 180 | * USE_TCP_NON_BLOCKING OFF
|
---|
[270] | 181 | */
|
---|
| 182 |
|
---|
[331] | 183 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
| 184 |
|
---|
| 185 | static ER
|
---|
| 186 | tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
|
---|
[270] | 187 | {
|
---|
[331] | 188 | ER error = E_OK;
|
---|
[270] | 189 |
|
---|
[331] | 190 | #if TNUM_TCP4_REPID > 0
|
---|
| 191 | T_IPV4EP dst4;
|
---|
| 192 | #endif
|
---|
[270] | 193 |
|
---|
[331] | 194 | if (apip == API_PROTO_IPV6) {
|
---|
[270] | 195 |
|
---|
[331] | 196 | #if TNUM_TCP6_REPID > 0
|
---|
[270] | 197 |
|
---|
[331] | 198 | /* 受付口は IPv6 */
|
---|
| 199 | if ((error = tcp6_acp_cep(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
|
---|
| 200 | return error;
|
---|
[270] | 201 |
|
---|
| 202 | #ifdef USE_TCP_EXTENTIONS
|
---|
[331] | 203 | if ((error = free_tcp6_rep(info->repid, true)) != E_OK)
|
---|
| 204 | return error;
|
---|
[270] | 205 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 206 |
|
---|
[331] | 207 | #endif /* of #if TNUM_TCP6_REPID > 0 */
|
---|
[270] | 208 |
|
---|
| 209 | }
|
---|
[331] | 210 | else {
|
---|
[270] | 211 |
|
---|
[331] | 212 | #if TNUM_TCP4_REPID > 0
|
---|
[270] | 213 |
|
---|
[331] | 214 | /* 受付口は IPv4 */
|
---|
| 215 | if ((error = tcp_acp_cep(info->cepid, info->repid, &dst4, TMO_FEVR)) != E_OK)
|
---|
| 216 | return error;
|
---|
| 217 | in6_make_ipv4mapped (&info->dst.ipaddr, dst4.ipaddr);
|
---|
| 218 | info->dst.portno = dst4.portno;
|
---|
[270] | 219 |
|
---|
| 220 | #ifdef USE_TCP_EXTENTIONS
|
---|
[331] | 221 | if ((error = free_tcp4_rep(info->repid, true)) != E_OK)
|
---|
| 222 | return error;
|
---|
[270] | 223 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 224 |
|
---|
[331] | 225 | #endif /* of #if TNUM_TCP4_REPID > 0 */
|
---|
[270] | 226 |
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[331] | 229 | return error;
|
---|
| 230 | }
|
---|
[270] | 231 |
|
---|
[331] | 232 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
[270] | 233 |
|
---|
[331] | 234 | /*
|
---|
| 235 | * tcp_passive_open -- 受動オープンを実行する。
|
---|
| 236 | *
|
---|
| 237 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 238 | */
|
---|
[270] | 239 |
|
---|
| 240 | static ER
|
---|
[331] | 241 | tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
|
---|
[270] | 242 | {
|
---|
[331] | 243 | ER error = E_OK;
|
---|
[270] | 244 |
|
---|
[331] | 245 | if ((error = TCP_ACP_CEP(info->cepid, info->repid, &info->dst, TMO_FEVR)) != E_OK)
|
---|
[270] | 246 | return error;
|
---|
| 247 |
|
---|
| 248 | #ifdef USE_TCP_EXTENTIONS
|
---|
[331] | 249 | if ((error = FREE_TCP_REP(info->repid, true)) != E_OK)
|
---|
| 250 | return error;
|
---|
[270] | 251 | #endif /* of #ifdef USE_TCP_EXTENTIONS */
|
---|
| 252 |
|
---|
[331] | 253 | return error;
|
---|
| 254 | }
|
---|
[270] | 255 |
|
---|
[331] | 256 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
[270] | 257 |
|
---|
[331] | 258 | #ifdef USE_COPYSAVE_API
|
---|
[270] | 259 |
|
---|
[331] | 260 | /*
|
---|
| 261 | * tcp_echo_srv -- TCP エコーサーバ
|
---|
| 262 | *
|
---|
| 263 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 264 | * USE_COPYSAVE_API ON
|
---|
| 265 | */
|
---|
[270] | 266 |
|
---|
[331] | 267 | ER
|
---|
| 268 | tcp_echo_srv (uint_t six, char apip)
|
---|
| 269 | {
|
---|
| 270 | ER error = E_OK;
|
---|
| 271 | ER_UINT rblen, sblen;
|
---|
| 272 | SYSTIM now;
|
---|
| 273 | uint32_t total;
|
---|
| 274 | uint16_t rlen, slen, soff, scount, rcount;
|
---|
| 275 | char *rbuf, *sbuf;
|
---|
[270] | 276 |
|
---|
| 277 | #ifdef SHOW_RCV_RANGE
|
---|
[331] | 278 | char head, tail;
|
---|
| 279 | #endif
|
---|
[270] | 280 |
|
---|
[331] | 281 | if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK) {
|
---|
| 282 | syslog(LOG_NOTICE, "[TES%c:%02u OPN] error: %s",
|
---|
| 283 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
| 284 | return error;
|
---|
[270] | 285 | }
|
---|
| 286 |
|
---|
| 287 | syscall(get_tim(&now));
|
---|
| 288 |
|
---|
[331] | 289 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
[270] | 290 |
|
---|
[331] | 291 | if (apip == API_PROTO_IPV6)
|
---|
| 292 | syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 293 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 294 | ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
| 295 | tcp_echo_srv_info[six].dst.portno);
|
---|
| 296 | else {
|
---|
| 297 | T_IN4_ADDR addr;
|
---|
[270] | 298 |
|
---|
[331] | 299 | addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
|
---|
| 300 | syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 301 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 302 | ip2str(NULL, &addr), tcp_echo_srv_info[six].dst.portno);
|
---|
| 303 | }
|
---|
[270] | 304 |
|
---|
[331] | 305 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
[270] | 306 |
|
---|
[331] | 307 | syslog(LOG_NOTICE, "[TES%c:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 308 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 309 | IP2STR(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
| 310 | tcp_echo_srv_info[six].dst.portno);
|
---|
[270] | 311 |
|
---|
[331] | 312 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
[270] | 313 |
|
---|
| 314 | scount = rcount = total = 0;
|
---|
| 315 | while (true) {
|
---|
[331] | 316 | if ((rblen = tcp_rcv_buf(tcp_echo_srv_info[six].cepid, (void**)&rbuf, RCV_TMO)) <= 0) {
|
---|
[270] | 317 | if (rblen != E_OK)
|
---|
[331] | 318 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
| 319 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(rblen));
|
---|
[270] | 320 | break;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
[331] | 323 | rcount ++;
|
---|
| 324 |
|
---|
| 325 | #ifdef SHOW_RCV_RANGE
|
---|
[270] | 326 | head = *rbuf;
|
---|
| 327 | tail = *(rbuf + rblen - 1);
|
---|
| 328 |
|
---|
[331] | 329 | //syslog(LOG_NOTICE, "[TES%c:%02u RCV] len: %7lu",
|
---|
| 330 | // apip, tcp_echo_srv_info[six].cepid, (uint16_t)rblen);
|
---|
| 331 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] rcount: %7lu, len: %6lu, data %02x -> %02x",
|
---|
| 332 | apip, tcp_echo_srv_info[six].cepid, rcount, (uint16_t)rblen, head, tail);
|
---|
[270] | 333 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 334 |
|
---|
| 335 | rlen = (uint16_t)rblen;
|
---|
| 336 | total += rblen;
|
---|
| 337 | soff = 0;
|
---|
| 338 | while (rlen > 0) {
|
---|
| 339 |
|
---|
[331] | 340 | if ((sblen = tcp_get_buf(tcp_echo_srv_info[six].cepid, (void**)&sbuf, SND_TMO)) < 0) {
|
---|
| 341 | syslog(LOG_NOTICE, "[TES%c:%02u GET] error: %s",
|
---|
| 342 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(sblen));
|
---|
[270] | 343 | goto err_fin;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
[331] | 346 | //syslog(LOG_NOTICE, "[TES%c:%02u SND] len: %7lu",
|
---|
| 347 | // apip, tcp_echo_srv_info[six].cepid, (uint16_t)sblen);
|
---|
[270] | 348 | scount ++;
|
---|
| 349 | slen = rlen < (uint16_t)sblen ? rlen : (uint16_t)sblen;
|
---|
| 350 | memcpy(sbuf, rbuf + soff, slen);
|
---|
[331] | 351 | if ((error = tcp_snd_buf(tcp_echo_srv_info[six].cepid, slen)) != E_OK) {
|
---|
| 352 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
| 353 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
[270] | 354 | goto err_fin;
|
---|
| 355 | }
|
---|
| 356 | #ifdef SHOW_RCV_RANGE
|
---|
[331] | 357 | syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %4u, len: %4u",
|
---|
| 358 | apip, tcp_echo_srv_info[six].cepid, scount, slen);
|
---|
[270] | 359 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 360 |
|
---|
| 361 | rlen -= slen;
|
---|
| 362 | soff += slen;
|
---|
| 363 | }
|
---|
| 364 |
|
---|
[331] | 365 | if ((error = tcp_rel_buf(tcp_echo_srv_info[six].cepid, rblen)) < 0) {
|
---|
| 366 | syslog(LOG_NOTICE, "[TES%c:%02u REL] error: %s",
|
---|
| 367 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
[270] | 368 | break;
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 | err_fin:
|
---|
| 372 |
|
---|
| 373 | #ifdef USE_TCP_SHT_CEP
|
---|
[331] | 374 | if ((error = tcp_sht_cep(tcp_echo_srv_info[six].cepid)) != E_OK)
|
---|
| 375 | syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
|
---|
| 376 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
[270] | 377 | #endif /* of #ifdef USE_TCP_SHT_CEP */
|
---|
| 378 |
|
---|
[331] | 379 | if ((error = tcp_cls_cep(tcp_echo_srv_info[six].cepid, CLS_TMO)) != E_OK)
|
---|
| 380 | syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
|
---|
| 381 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
[270] | 382 |
|
---|
| 383 | syscall(get_tim(&now));
|
---|
[331] | 384 | #if 1
|
---|
| 385 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
|
---|
| 386 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total);
|
---|
| 387 | #else
|
---|
| 388 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu, error: %s",
|
---|
| 389 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total, itron_strerror(error));
|
---|
| 390 | #endif
|
---|
[270] | 391 |
|
---|
| 392 | return error;
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | #else /* of #ifdef USE_COPYSAVE_API */
|
---|
| 396 |
|
---|
| 397 | /*
|
---|
| 398 | * tcp_echo_srv -- TCP エコーサーバ
|
---|
[331] | 399 | *
|
---|
| 400 | * USE_TCP_NON_BLOCKING OFF
|
---|
| 401 | * USE_COPYSAVE_API OFF
|
---|
[270] | 402 | */
|
---|
| 403 |
|
---|
[331] | 404 | ER
|
---|
| 405 | tcp_echo_srv (uint_t six, char apip)
|
---|
[270] | 406 | {
|
---|
[331] | 407 | ID cepid;
|
---|
| 408 | ER error = E_OK;
|
---|
[270] | 409 | ER_UINT rlen, slen;
|
---|
| 410 | SYSTIM now;
|
---|
| 411 | uint32_t total;
|
---|
| 412 | uint16_t soff, scount, rcount;
|
---|
| 413 |
|
---|
[331] | 414 | if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK) {
|
---|
| 415 | syslog(LOG_NOTICE, "[TES%c:%02u OPN] error: %s",
|
---|
| 416 | apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
|
---|
[270] | 417 | return error;
|
---|
| 418 | }
|
---|
[331] | 419 |
|
---|
| 420 | syscall(get_tim(&now));
|
---|
[270] | 421 |
|
---|
[331] | 422 | #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
|
---|
[270] | 423 |
|
---|
[331] | 424 | if (apip == API_PROTO_IPV6)
|
---|
| 425 | syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 426 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 427 | ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
| 428 | tcp_echo_srv_info[six].dst.portno);
|
---|
| 429 | else {
|
---|
| 430 | T_IN4_ADDR addr;
|
---|
| 431 |
|
---|
| 432 | addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
|
---|
| 433 | syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 434 | tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 435 | ip2str(NULL, &addr), tcp_echo_srv_info[six].dst.portno);
|
---|
| 436 | }
|
---|
| 437 |
|
---|
| 438 | #else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 439 |
|
---|
| 440 | syslog(LOG_NOTICE, "[TES%c:%02u ACP] conct: %7lu,from: %s.%u",
|
---|
| 441 | apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
|
---|
| 442 | IP2STR(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
|
---|
| 443 | tcp_echo_srv_info[six].dst.portno);
|
---|
| 444 |
|
---|
| 445 | #endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
|
---|
| 446 |
|
---|
| 447 | cepid = tcp_echo_srv_info[six].cepid;
|
---|
[270] | 448 | scount = rcount = total = 0;
|
---|
| 449 | while (true) {
|
---|
[331] | 450 | if ((rlen = tcp_rcv_dat(cepid, tcp_echo_srv_info[six].buffer, BUF_SIZE - 1, RCV_TMO)) <= 0) {
|
---|
[270] | 451 | if (rlen != E_OK)
|
---|
[331] | 452 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
|
---|
| 453 | apip, cepid, itron_strerror(rlen));
|
---|
[270] | 454 | break;
|
---|
| 455 | }
|
---|
| 456 |
|
---|
| 457 | rcount ++;
|
---|
| 458 | #ifdef SHOW_RCV_RANGE
|
---|
[331] | 459 | syslog(LOG_NOTICE, "[TES%c:%02u RCV] rcount: %4u, len: %4u, data %02x -> %02x",
|
---|
| 460 | apip, cepid, rcount,
|
---|
| 461 | (uint16_t)rlen, * tcp_echo_srv_info[six].tcp_echo_srv_info[six].buffer,
|
---|
| 462 | *(tcp_echo_srv_info[six].tcp_echo_srv_info[six].buffer + rlen - 1));
|
---|
[270] | 463 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 464 |
|
---|
| 465 | total += rlen;
|
---|
| 466 | soff = 0;
|
---|
| 467 | while (rlen > 0) {
|
---|
| 468 | scount ++;
|
---|
[331] | 469 | if ((slen = tcp_snd_dat(cepid, &tcp_echo_srv_info[six].buffer[soff], rlen, SND_TMO)) < 0) {
|
---|
| 470 | syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
|
---|
| 471 | apip, cepid, itron_strerror(slen));
|
---|
[270] | 472 | goto err_fin;
|
---|
| 473 | }
|
---|
| 474 | #ifdef SHOW_RCV_RANGE
|
---|
[331] | 475 | syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %4u, len: %4u",
|
---|
| 476 | apip, cepid, scount, (uint16_t)slen);
|
---|
[270] | 477 | #endif /* of #ifdef SHOW_RCV_RANGE */
|
---|
| 478 |
|
---|
| 479 | rlen -= slen;
|
---|
| 480 | soff += slen;
|
---|
| 481 | }
|
---|
| 482 | }
|
---|
| 483 | err_fin:
|
---|
| 484 |
|
---|
| 485 | #ifdef USE_TCP_SHT_CEP
|
---|
| 486 | if ((error = tcp_sht_cep(cepid)) != E_OK)
|
---|
[331] | 487 | syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
|
---|
| 488 | apip, cepid, itron_strerror(error));
|
---|
[270] | 489 | #endif /* of #ifdef USE_TCP_SHT_CEP */
|
---|
| 490 |
|
---|
| 491 | if ((error = tcp_cls_cep(cepid, CLS_TMO)) != E_OK)
|
---|
[331] | 492 | syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
|
---|
| 493 | apip, cepid, itron_strerror(error));
|
---|
[270] | 494 |
|
---|
| 495 | syscall(get_tim(&now));
|
---|
[331] | 496 | syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
|
---|
| 497 | apip, cepid, now / SYSTIM_HZ, total);
|
---|
[270] | 498 |
|
---|
| 499 | return error;
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | #endif /* of #ifdef USE_COPYSAVE_API */
|
---|
| 503 |
|
---|
[331] | 504 | #endif /* of #ifndef USE_TCP_NON_BLOCKING */
|
---|
[270] | 505 |
|
---|
[331] | 506 | #ifndef USE_TCP_EXTENTIONS
|
---|
[270] | 507 |
|
---|
| 508 | /*
|
---|
[331] | 509 | * tcp_echo_srv_task -- TCP エコーサーバタスク
|
---|
[270] | 510 | */
|
---|
| 511 |
|
---|
[331] | 512 | void
|
---|
| 513 | tcp_echo_srv_task(intptr_t exinf)
|
---|
[270] | 514 | {
|
---|
[331] | 515 | ID tskid, cepid;
|
---|
| 516 | ER error;
|
---|
| 517 | uint_t six;
|
---|
| 518 | char apip;
|
---|
[270] | 519 |
|
---|
[331] | 520 | six = INDEX_SRV_INFO((ID)exinf);
|
---|
[270] | 521 |
|
---|
| 522 | #if defined(SUPPORT_INET6)
|
---|
| 523 |
|
---|
[331] | 524 | #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV)
|
---|
[270] | 525 |
|
---|
[331] | 526 | if (six >= NUM_TCP4_ECHO_SRV_TASKS)
|
---|
| 527 | apip = API_PROTO_IPV6;
|
---|
| 528 | else
|
---|
| 529 | apip = API_PROTO_IPV4;
|
---|
[270] | 530 |
|
---|
[331] | 531 | #else /* of #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
[270] | 532 |
|
---|
[331] | 533 | apip = API_PROTO_IPV6;
|
---|
[270] | 534 |
|
---|
[331] | 535 | #endif /* of #if defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
|
---|
[270] | 536 |
|
---|
[331] | 537 | #else /* of #if defined(SUPPORT_INET6) */
|
---|
[270] | 538 |
|
---|
[331] | 539 | apip = API_PROTO_IPV4;
|
---|
[270] | 540 |
|
---|
[331] | 541 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
[270] | 542 |
|
---|
| 543 | syscall(get_tid(&tskid));
|
---|
[331] | 544 | cepid = tcp_echo_srv_info[six].cepid;
|
---|
| 545 | syslog(LOG_NOTICE, "[TCP%c ECHO SRV:%d,%d] started.", apip, tskid, cepid);
|
---|
[270] | 546 |
|
---|
| 547 | while (true) {
|
---|
[331] | 548 | while ((error = tcp_echo_srv(six, apip)) == E_OK)
|
---|
[270] | 549 | ;
|
---|
[331] | 550 | syslog(LOG_NOTICE, "[TES%c:%02u TSK] sleep 60[s], error: %s", apip, cepid, itron_strerror(error));
|
---|
| 551 | tslp_tsk(60 * 1000 * 1000);
|
---|
| 552 | syslog(LOG_NOTICE, "[TES%c:%02u TSK] resume.", apip, cepid);
|
---|
[270] | 553 | }
|
---|
| 554 | }
|
---|
| 555 |
|
---|
[331] | 556 | #endif /* of #ifndef USE_TCP_EXTENTIONS */
|
---|
[270] | 557 |
|
---|
| 558 | #endif /* of #ifdef USE_TCP_ECHO_SRV1 */
|
---|