source: asp3_tinet_ecnl_rx/trunk/asp3_dcre/tinet/netapp/tcp_echo_srv1_nblk.c@ 337

Last change on this file since 337 was 337, checked in by coas-nagasima, 6 years ago

ASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 18.9 KB
Line 
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 サーバ #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>
69#include <netapp/tcp_echo_srv1.h>
70#include <netapp/tcp_echo_srv1_var.h>
71
72#ifdef USE_TCP_ECHO_SRV1
73
74/*
75 * 表示
76 */
77
78//#define SHOW_RCV_RANGE
79
80/*
81 * コネクション切断方法の指定
82 */
83
84#define USE_TCP_SHT_CEP
85
86/*
87 * タイムアウト
88 */
89
90#ifdef TOPPERS_S810_CLG3_85
91
92#define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */
93//#define RCV_TMO TMO_FEVR
94#define RCV_TMO (30*SYSTIM_HZ)
95//#define SND_TMO TMO_FEVR
96#define SND_TMO (30*SYSTIM_HZ)
97
98#else /* of #ifdef TOPPERS_S810_CLG3_85 */
99
100//#define CLS_TMO TMO_FEVR /* Close Wait は標準で 60秒 */
101#define CLS_TMO (70*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*10)
102//#define RCV_TMO TMO_FEVR
103#define RCV_TMO (30*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*30)
104//#define SND_TMO TMO_FEVR
105#define SND_TMO (40*SYSTIM_HZ+(netapp_rand()%SYSTIM_HZ)*20)
106
107#endif /* of #ifdef TOPPERS_S810_CLG3_85 */
108
109#ifdef USE_TCP_NON_BLOCKING
110
111/*
112 * 変数
113 */
114
115#ifdef USE_TCP_EXTENTIONS
116
117T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[] = {
118
119 { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY1 },
120
121#if NUM_TCP_ECHO_SRV_TASKS >= 2
122 { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY2 },
123#endif
124#if NUM_TCP_ECHO_SRV_TASKS >= 3
125 { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY3 },
126#endif
127#if NUM_TCP_ECHO_SRV_TASKS >= 4
128 { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY4 },
129#endif
130#if NUM_TCP_ECHO_SRV_TASKS >= 5
131 { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY5 },
132#endif
133#if NUM_TCP_ECHO_SRV_TASKS >= 6
134 { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY6 },
135#endif
136#if NUM_TCP_ECHO_SRV_TASKS >= 7
137 { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY7 },
138#endif
139#if NUM_TCP_ECHO_SRV_TASKS >= 8
140 { 0, 0, SEM_TCP_ECHO_SRV_NBLK_READY8 },
141#endif
142
143 };
144
145#else /* of #ifdef USE_TCP_EXTENTIONS */
146
147T_TCP_ECHO_SRV_INFO tcp_echo_srv_info[] = {
148
149#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV)
150
151 { TCP4_ECHO_SRV_CEPID1, TCP4_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY1 },
152
153#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
154
155 { TCP_ECHO_SRV_CEPID1, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY1 },
156
157#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
158
159#if NUM_TCP_ECHO_SRV_TASKS >= 2
160 { TCP_ECHO_SRV_CEPID2, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY2 },
161#endif
162#if NUM_TCP_ECHO_SRV_TASKS >= 3
163 { TCP_ECHO_SRV_CEPID3, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY3 },
164#endif
165#if NUM_TCP_ECHO_SRV_TASKS >= 4
166 { TCP_ECHO_SRV_CEPID4, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY4 },
167#endif
168#if NUM_TCP_ECHO_SRV_TASKS >= 5
169 { TCP_ECHO_SRV_CEPID5, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY5 },
170#endif
171#if NUM_TCP_ECHO_SRV_TASKS >= 6
172 { TCP_ECHO_SRV_CEPID6, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY6 },
173#endif
174#if NUM_TCP_ECHO_SRV_TASKS >= 7
175 { TCP_ECHO_SRV_CEPID7, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY7 },
176#endif
177#if NUM_TCP_ECHO_SRV_TASKS >= 8
178 { TCP_ECHO_SRV_CEPID8, TCP_ECHO_SRV_REPID, SEM_TCP_ECHO_SRV_NBLK_READY8 },
179#endif
180
181 };
182
183#endif /* of #ifdef USE_TCP_EXTENTIONS */
184
185/*
186 * find_srv_info -- 接続相手の情報構造体を探索する。
187 */
188
189static
190T_TCP_ECHO_SRV_INFO *find_srv_info (ID cepid)
191{
192 T_TCP_ECHO_SRV_INFO *ri;
193
194 for (ri = &tcp_echo_srv_info[sizeof(tcp_echo_srv_info) / sizeof(T_TCP_ECHO_SRV_INFO)]; ri --; )
195 if (ri->cepid == cepid)
196 return ri;
197 return NULL;
198 }
199
200/*
201 * ノンブロッキングコールのコールバック関数
202 */
203
204ER
205callback_nblk_tcp_echo_srv (ID cepid, FN fncd, void *p_parblk)
206{
207 ER error = E_OK;
208 T_TCP_ECHO_SRV_INFO *ri;
209
210 if ((ri = find_srv_info(cepid)) == NULL) {
211 syslog(LOG_NOTICE, "[TESn:%02u CBN] CEPID not found", cepid);
212 return E_PAR;
213 }
214
215 switch (fncd) {
216
217 case TFN_TCP_ACP_CEP:
218 ri->error = *(ER*)p_parblk;
219 syscall(sig_sem(ri->semid));
220 break;
221
222 case TFN_TCP_RCV_DAT:
223 if ((ri->rlen = *(ER*)p_parblk) < 0)
224 syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->rlen));
225 syscall(sig_sem(ri->semid));
226 break;
227
228 case TFN_TCP_SND_DAT:
229 if ((ri->slen = *(ER*)p_parblk) < 0)
230 syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->slen));
231 syscall(sig_sem(ri->semid));
232 break;
233
234 case TFN_TCP_CLS_CEP:
235 if ((ri->error = *(ER*)p_parblk) < 0)
236 syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->error));
237 syscall(sig_sem(ri->semid));
238 break;
239
240 case TFN_TCP_RCV_BUF:
241 if ((ri->rlen = *(ER*)p_parblk) < 0)
242 syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->rlen));
243 syscall(sig_sem(ri->semid));
244 break;
245
246 case TFN_TCP_GET_BUF:
247 if ((ri->slen = *(ER*)p_parblk) < 0)
248 syslog(LOG_NOTICE, "[TESn:%02u CBN] error: %s", cepid, itron_strerror(ri->slen));
249 syscall(sig_sem(ri->semid));
250 break;
251
252#ifdef USE_TCP_EXTENTIONS
253
254 case TEV_TCP_RCV_OOB:
255 if ((ri->rlen = *(ER*)p_parblk) < 0)
256 syslog(LOG_NOTICE, "[TESn:%02u OOB] error: %s", cepid, itron_strerror(ri->rlen));
257 else if (ri->rlen > 0) {
258 char ch;
259
260 if ((ri->rlen = tcp_rcv_oob(cepid, &ch, sizeof(ch))) > 0)
261 syslog(LOG_NOTICE, "[TESn:%02u OOB] recv oob: 0x%02x", cepid, ch);
262 else if (ri->rlen < 0)
263 syslog(LOG_NOTICE, "[TESn:%02u OOB] error: %s", cepid, itron_strerror(ri->rlen));
264 }
265 break;
266
267#endif /* of #ifdef USE_TCP_EXTENTIONS */
268
269 case TFN_TCP_CON_CEP:
270 case TFN_TCP_SND_OOB:
271 default:
272 error = E_PAR;
273 break;
274 }
275 return error;
276 }
277
278/*
279 * tcp_passive_open -- 受動オープンを実行する。
280 *
281 * USE_TCP_NON_BLOCKING ON
282 */
283
284#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
285
286static ER
287tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
288{
289 ER error;
290 T_IPV4EP dst4;
291
292 if (apip == API_PROTO_IPV6) {
293 /* 受付口は IPv6 */
294 if ((error = tcp6_acp_cep(info->cepid, info->repid, &info->dst, TMO_NBLK)) != E_WBLK)
295 return error;
296
297 /* 相手から接続されるまで待つ。*/
298 syscall(wai_sem(info->semid));
299
300 if (info->error != E_OK)
301 return info->error;
302
303#ifdef USE_TCP_EXTENTIONS
304 if ((error = free_tcp6_rep(info->repid, true)) != E_OK)
305 return error;
306#endif /* of #ifdef USE_TCP_EXTENTIONS */
307
308 }
309 else {
310 /* 受付口は IPv4 */
311 if ((error = tcp_acp_cep(info->cepid, info->repid, &dst4, TMO_NBLK)) != E_WBLK)
312 return error;
313
314 /* 相手から接続されるまで待つ。*/
315 syscall(wai_sem(info->semid));
316
317 if (info->error != E_OK)
318 return info->error;
319
320#ifdef USE_TCP_EXTENTIONS
321 if ((error = free_tcp4_rep(info->repid, true)) != E_OK)
322 return error;
323#endif /* of #ifdef USE_TCP_EXTENTIONS */
324
325 in6_make_ipv4mapped (&info->dst.ipaddr, dst4.ipaddr);
326 info->dst.portno = dst4.portno;
327
328 }
329
330 return E_OK;
331 }
332
333#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
334
335static ER
336tcp_passive_open (T_TCP_ECHO_SRV_INFO *info, char apip)
337{
338 ER error;
339
340 if ((error = TCP_ACP_CEP(info->cepid, info->repid, &info->dst, TMO_NBLK)) != E_WBLK)
341 return error;
342
343 /* 相手から接続されるまで待つ。*/
344 syscall(wai_sem(info->semid));
345
346 if (info->error != E_OK)
347 return info->error;
348
349#ifdef USE_TCP_EXTENTIONS
350 if ((error = FREE_TCP_REP(info->repid, true)) != E_OK)
351 return error;
352#endif /* of #ifdef USE_TCP_EXTENTIONS */
353
354 return E_OK;
355 }
356
357#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) && defined(USE_TCP4_ECHO_SRV) */
358
359#ifdef USE_COPYSAVE_API
360
361/*
362 * tcp_echo_srv -- TCP エコーサーバ
363 *
364 * USE_TCP_NON_BLOCKING ON
365 * USE_COPYSAVE_API ON
366 */
367
368ER
369tcp_echo_srv (uint_t six, char apip)
370{
371#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
372 T_IN4_ADDR ipv4addr;
373#endif
374 ER error;
375 SYSTIM now;
376 uint32_t total;
377 uint16_t rblen, sblen, rlen, slen, soff, scount, rcount;
378 char *rbuf, *sbuf, head, tail;
379
380 if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK)
381 return error;
382
383 syscall(get_tim(&now));
384
385#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
386
387 if (apip == API_PROTO_IPV6)
388 syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
389 tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
390 ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
391 tcp_echo_srv_info[six].dst.portno);
392 else {
393 ipv4addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
394 syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
395 tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
396 ip2str(NULL, &ipv4addr),
397 tcp_echo_srv_info[six].dst.portno);
398 }
399
400#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
401
402 syslog(LOG_NOTICE, "[TES%c:%02u ACP] conct: %7lu,from: %s.%u",
403 apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
404 IP2STR(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
405 tcp_echo_srv_info[six].dst.portno);
406
407#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
408
409 rlen = scount = rcount = total = 0;
410 while (true) {
411 if ((error = tcp_rcv_buf(tcp_echo_srv_info[six].cepid, (void**)&rbuf, TMO_NBLK)) != E_WBLK) {
412 syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
413 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
414 break;
415 }
416
417 /* 受信するまで待つ。*/
418 syscall(wai_sem(tcp_echo_srv_info[six].semid));
419
420 if (tcp_echo_srv_info[six].rlen < 0) { /* エラー */
421 syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
422 apip, tcp_echo_srv_info[six].cepid, itron_strerror(tcp_echo_srv_info[six].rlen));
423 break;
424 }
425 else if (tcp_echo_srv_info[six].rlen == 0) /* 受信終了 */
426 break;
427
428 rblen = tcp_echo_srv_info[six].rlen;
429
430 /* バッファの残りにより、受信長を調整する。*/
431 if (rblen > BUF_SIZE - rlen)
432 rblen = BUF_SIZE - rlen;
433 total += rblen;
434 rlen = rblen;
435
436 head = *rbuf;
437 tail = *(rbuf + rblen - 1);
438 rcount ++;
439
440#ifdef SHOW_RCV_RANGE
441 syslog(LOG_NOTICE, "[TES%c:%02u RCV] "
442 "rcount: %7lu, len: %6lu, data %02x -> %02x",
443 apip, tcp_echo_srv_info[six].cepid, rcount, rblen, head, tail);
444#endif /* of #ifdef SHOW_RCV_RANGE */
445
446 memcpy(tcp_echo_srv_info[six].buffer, rbuf, rblen);
447
448 if ((error = tcp_rel_buf(tcp_echo_srv_info[six].cepid, rlen)) < 0) {
449 syslog(LOG_NOTICE, "[TES%c:%02u REL] error: %s",
450 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
451 break;
452 }
453
454 soff = 0;
455 while (rlen > 0) {
456
457 if ((error = tcp_get_buf(tcp_echo_srv_info[six].cepid, (void**)&sbuf, TMO_NBLK)) != E_WBLK) {
458 syslog(LOG_NOTICE, "[TES%c:%02u GET] error: %s",
459 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
460 goto err_fin;
461 }
462
463 /* 送信バッファの獲得が完了するまで待つ。*/
464 syscall(wai_sem(tcp_echo_srv_info[six].semid));
465
466 if (tcp_echo_srv_info[six].slen < 0) {
467 syslog(LOG_NOTICE, "[TES%c:%02u GET] error: %s",
468 apip, tcp_echo_srv_info[six].cepid, itron_strerror(tcp_echo_srv_info[six].slen));
469 goto err_fin;
470 }
471
472 sblen = tcp_echo_srv_info[six].slen;
473 scount ++;
474 slen = sblen < rlen ? sblen : rlen;
475 memcpy(sbuf, tcp_echo_srv_info[six].buffer + soff, slen);
476
477 if ((error = tcp_snd_buf(tcp_echo_srv_info[six].cepid, slen)) != E_OK) {
478 syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
479 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
480 goto err_fin;
481 }
482#ifdef SHOW_RCV_RANGE
483 syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %7lu, len: %4u",
484 apip, cepid, scount, slen);
485#endif /* of #ifdef SHOW_RCV_RANGE */
486
487 rlen -= slen;
488 soff += slen;
489 }
490 }
491err_fin:
492
493#ifdef USE_TCP_SHT_CEP
494 if ((error = tcp_sht_cep(tcp_echo_srv_info[six].cepid)) != E_OK)
495 syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
496 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
497#endif /* of #ifdef USE_TCP_SHT_CEP */
498
499 if ((error = tcp_cls_cep(tcp_echo_srv_info[six].cepid, TMO_NBLK)) != E_WBLK)
500 syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
501 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
502
503 /* 開放が完了するまで待つ。*/
504 syscall(wai_sem(tcp_echo_srv_info[six].semid));
505
506 syscall(get_tim(&now));
507 syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
508 apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total);
509
510 return error == E_WBLK ? E_OK : error;
511 }
512
513#else /* of #ifdef USE_COPYSAVE_API */
514
515/*
516 * tcp_echo_srv -- TCP エコーサーバ
517 *
518 * USE_TCP_NON_BLOCKING ON
519 * USE_COPYSAVE_API OFF
520 */
521
522ER
523tcp_echo_srv (uint_t six, char apip)
524{
525 T_IN4_ADDR ipv4addr;
526 ER error;
527 SYSTIM now;
528 uint32_t total;
529 uint16_t rlen, slen, soff, scount, rcount;
530 char head, tail;
531
532 if ((error = tcp_passive_open(&tcp_echo_srv_info[six], apip)) != E_OK)
533 return error;
534
535 syscall(get_tim(&now));
536 if (apip == API_PROTO_IPV6)
537 syslog(LOG_NOTICE, "[TES6:%02u ACP] conct: %7lu,from: %s.%u",
538 tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
539 ipv62str(NULL, &tcp_echo_srv_info[six].dst.ipaddr),
540 tcp_echo_srv_info[six].dst.portno);
541 else {
542 ipv4addr = ntohl(tcp_echo_srv_info[six].dst.ipaddr.s6_addr32[3]);
543 syslog(LOG_NOTICE, "[TES4:%02u ACP] conct: %7lu,from: %s.%u",
544 tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ,
545 ip2str(NULL, &ipv4addr),
546 tcp_echo_srv_info[six].dst.portno);
547 }
548
549 scount = rcount = total = 0;
550 while (true) {
551 if ((error = tcp_rcv_dat(tcp_echo_srv_info[six].cepid, tcp_echo_srv_info[six].buffer, BUF_SIZE - 1, TMO_NBLK)) != E_WBLK) {
552 syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
553 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
554 break;
555 }
556
557 /* 受信完了まで待つ。*/
558 syscall(wai_sem(tcp_echo_srv_info[six].semid));
559
560 if (tcp_echo_srv_info[six].rlen < 0) {
561 syslog(LOG_NOTICE, "[TES%c:%02u RCV] error: %s",
562 apip, tcp_echo_srv_info[six].cepid, itron_strerror(tcp_echo_srv_info[six].rlen));
563 break;
564 }
565 else if (tcp_echo_srv_info[six].rlen == 0)
566 break;
567
568 rlen = tcp_echo_srv_info[six].rlen;
569 head = * tcp_echo_srv_info[six].buffer;
570 tail = *(tcp_echo_srv_info[six].buffer + rlen - 1);
571 rcount ++;
572
573#ifdef SHOW_RCV_RANGE
574 syslog(LOG_NOTICE, "[TES%c:%02u RCV] rcount: %4u, len: %4u, data %02x -> %02x",
575 apip, tcp_echo_srv_info[six].cepid, rcount, rlen, head, tail);
576#endif /* of #ifdef SHOW_RCV_RANGE */
577
578 total += rlen;
579 soff = 0;
580 while (rlen > 0) {
581 scount ++;
582 if ((error = tcp_snd_dat(tcp_echo_srv_info[six].cepid, &tcp_echo_srv_info[six].buffer[soff], rlen, TMO_NBLK)) != E_WBLK) {
583 syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
584 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
585 goto err_fin;
586 }
587
588 /* 送信完了まで待つ。*/
589 syscall(wai_sem(tcp_echo_srv_info[six].semid));
590
591 if (tcp_echo_srv_info[six].slen < 0) {
592 syslog(LOG_NOTICE, "[TES%c:%02u SND] error: %s",
593 apip, tcp_echo_srv_info[six].cepid, itron_strerror(tcp_echo_srv_info[six].slen));
594 goto err_fin;
595 }
596
597 slen = tcp_echo_srv_info[six].slen;
598
599#ifdef SHOW_RCV_RANGE
600 syslog(LOG_NOTICE, "[TES%c:%02u SND] scount: %4u, len: %4u",
601 apip, tcp_echo_srv_info[six].cepid, scount, slen);
602#endif /* of #ifdef SHOW_RCV_RANGE */
603
604 rlen -= slen;
605 soff += slen;
606 }
607 }
608err_fin:
609
610#ifdef USE_TCP_SHT_CEP
611 if ((error = tcp_sht_cep(tcp_echo_srv_info[six].cepid)) != E_OK)
612 syslog(LOG_NOTICE, "[TES%c:%02u SHT] error: %s",
613 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
614#endif /* of #ifdef USE_TCP_SHT_CEP */
615
616 if ((error = tcp_cls_cep(tcp_echo_srv_info[six].cepid, TMO_NBLK)) != E_WBLK)
617 syslog(LOG_NOTICE, "[TES%c:%02u CLS] error: %s",
618 apip, tcp_echo_srv_info[six].cepid, itron_strerror(error));
619
620 /* 開放が完了するまで待つ。*/
621 syscall(wai_sem(tcp_echo_srv_info[six].semid));
622
623 syscall(get_tim(&now));
624 syslog(LOG_NOTICE, "[TES%c:%02u FIN] finsh: %7lu, ttl: %lu",
625 apip, tcp_echo_srv_info[six].cepid, now / SYSTIM_HZ, total);
626
627 return error == E_WBLK ? E_OK : error;
628 }
629
630#endif /* of #ifdef USE_COPYSAVE_API */
631
632#endif /* of #ifdef USE_TCP_NON_BLOCKING */
633
634#endif /* of #ifdef USE_TCP_ECHO_SRV1 */
Note: See TracBrowser for help on using the repository browser.