source: azure_iot_hub/trunk/asp3_dcre/tinet/netapp/tcp_echo_srv1_nblk.c@ 388

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

Azure IoT Hub Device C SDK を使ったサンプルの追加

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