source: asp3_tinet_ecnl_arm/trunk/asp3_dcre/tinet/netapp/tcp_echo_srv1_ext.c@ 352

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

arm向けASP3版ECNLを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-csrc;charset=UTF-8
File size: 9.8 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_EXTENTIONS
110
111/*
112 * 変数
113 */
114
115typedef struct t_tcp_echo_srv_task_info {
116 ID taskid; /* タスク ID */
117 bool_t active; /* 動作状態 */
118 char apip; /* API IPプロトコル */
119 } T_TCP_ECHO_SRV_TASK_INFO;
120
121static T_TCP_ECHO_SRV_TASK_INFO tcp_echo_srv_task_info[NUM_TCP_ECHO_SRV_TASKS] = {
122
123 { TCP_ECHO_SRV_TASK1, false },
124
125#if NUM_TCP_ECHO_SRV_TASKS >= 2
126 { TCP_ECHO_SRV_TASK2, false },
127#endif
128#if NUM_TCP_ECHO_SRV_TASKS >= 3
129 { TCP_ECHO_SRV_TASK3, false },
130#endif
131#if NUM_TCP_ECHO_SRV_TASKS >= 4
132 { TCP_ECHO_SRV_TASK4, false },
133#endif
134#if NUM_TCP_ECHO_SRV_TASKS >= 5
135 { TCP_ECHO_SRV_TASK5, false },
136#endif
137#if NUM_TCP_ECHO_SRV_TASKS >= 6
138 { TCP_ECHO_SRV_TASK6, false },
139#endif
140#if NUM_TCP_ECHO_SRV_TASKS >= 7
141 { TCP_ECHO_SRV_TASK7, false },
142#endif
143#if NUM_TCP_ECHO_SRV_TASKS >= 8
144 { TCP_ECHO_SRV_TASK8, false },
145#endif
146
147 };
148
149/*
150 * get_tcp_rep -- TCP 受付口を獲得する。
151 */
152
153#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
154
155static ER
156get_tcp_rep (ID *repid, char apip)
157{
158 ID tskid;
159 T_TCP6_CREP crep6;
160 T_TCP_CREP crep4;
161
162 get_tid(&tskid);
163 if (apip == API_PROTO_IPV6) {
164 crep6.repatr = UINT_C(0);
165 crep6.myaddr.portno = UINT_C(7);
166 memcpy(&crep6.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
167 return alloc_tcp6_rep(repid, tskid, &crep6);
168 }
169 else {
170 crep4.repatr = UINT_C(0);
171 crep4.myaddr.portno = UINT_C(7);
172 crep4.myaddr.ipaddr = IPV4_ADDRANY;
173 return alloc_tcp4_rep(repid, tskid, &crep4);
174 }
175 }
176
177#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
178
179static ER
180get_tcp_rep (ID *repid, char apip)
181{
182 ID tskid;
183 T_TCPN_CREP crep;
184
185 get_tid(&tskid);
186
187 crep.repatr = UINT_C(0);
188 crep.myaddr.portno = UINT_C(7);
189
190#if defined(SUPPORT_INET6)
191
192 memcpy(&crep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
193
194#else /* #if defined(SUPPORT_INET6) */
195
196#if defined(SUPPORT_INET4)
197 crep.myaddr.ipaddr = IPV4_ADDRANY;
198#endif
199
200#endif /* #if defined(SUPPORT_INET6) */
201
202 return ALLOC_TCP_REP(repid, tskid, &crep);
203 }
204
205#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
206
207/*
208 * get_tcp_cep -- TCP 通信端点を獲得する。
209 */
210
211static ER
212get_tcp_cep (ID *cepid, char apip)
213{
214 ID tskid;
215 T_TCP_CCEP ccep;
216
217 get_tid(&tskid);
218
219 ccep.cepatr = UINT_C(0);
220 ccep.sbufsz = TCP_ECHO_SRV_SWBUF_SIZE;
221 ccep.rbufsz = TCP_ECHO_SRV_RWBUF_SIZE;
222
223#ifdef TCP_CFG_SWBUF_CSAVE
224 ccep.sbuf = NADR;
225#else
226 ccep.sbuf = tcp_echo_srv_swbuf;
227#endif
228#ifdef TCP_CFG_RWBUF_CSAVE
229 ccep.rbuf = NADR;
230#else
231 ccep.rbuf = tcp_echo_srv_rwbuf;
232#endif
233#ifdef USE_TCP_NON_BLOCKING
234 ccep.callback = (FP)callback_nblk_tcp_echo_srv;
235#else
236 ccep.callback = NULL;
237#endif
238
239#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
240
241 if (apip == API_PROTO_IPV6)
242 return alloc_tcp6_cep(cepid, tskid, &ccep);
243 else
244 return alloc_tcp4_cep(cepid, tskid, &ccep);
245
246#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
247
248 return ALLOC_TCP_CEP(cepid, tskid, &ccep);
249
250#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
251
252 }
253
254/*
255 * wakeup_tcp_echo_srv -- TCP エコーサーバタスクの休止解除
256 */
257
258ER
259wakeup_tcp_echo_srv (char apip)
260{
261 int ix;
262
263 for (ix = NUM_TCP_ECHO_SRV_TASKS; -- ix >= 0; )
264 if (!tcp_echo_srv_task_info[ix].active) {
265 syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] wake up.",
266 apip, tcp_echo_srv_task_info[ix].taskid);
267 tcp_echo_srv_task_info[ix].apip = apip;
268 tcp_echo_srv_task_info[ix].active = true;
269 return syscall(wup_tsk(tcp_echo_srv_task_info[ix].taskid));
270 }
271 syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] wake up error: %s.",
272 apip, tcp_echo_srv_task_info[ix].taskid, itron_strerror(E_ID));
273 return E_ID;
274 }
275
276/*
277 * tcp_echo_srv_task -- TCP エコーサーバタスク
278 */
279
280void
281tcp_echo_srv_task (intptr_t exinf)
282{
283 ID tskid;
284 ER error = E_OK;
285 int ix;
286 char apip;
287
288 syscall(get_tid(&tskid));
289 syslog(LOG_NOTICE, "[TCPn ECHO SRV(EXT):%d] started.", tskid);
290 while (true) {
291 syslog(LOG_NOTICE, "[TCPn ECHO SRV(EXT):%d] goto sleep.", tskid);
292 syscall(slp_tsk());
293
294 for (ix = NUM_TCP_ECHO_SRV_TASKS; -- ix >= 0; ) {
295 if (tcp_echo_srv_task_info[ix].taskid == tskid) {
296 break;
297 }
298 }
299
300 apip = tcp_echo_srv_task_info[ix].apip;
301 if ((error = get_tcp_cep(&tcp_echo_srv_info[ix].cepid, apip)) != E_OK) {
302 syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] create CEP error: %s",
303 apip, tskid, itron_strerror(error));
304 continue;
305 }
306
307 while (true) {
308
309 if ((error = get_tcp_rep(&tcp_echo_srv_info[ix].repid, apip)) != E_OK) {
310 syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] create REP error: %s",
311 apip, tskid, itron_strerror(error));
312 break;
313 }
314 else if ((error = tcp_echo_srv(ix, apip)) != E_OK) {
315
316#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
317
318 if (apip == API_PROTO_IPV6)
319 error = free_tcp6_rep(tcp_echo_srv_info[ix].repid, error != E_DLT);
320 else
321 error = free_tcp4_rep(tcp_echo_srv_info[ix].repid, error != E_DLT);
322
323#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
324
325 error = FREE_TCP_REP(tcp_echo_srv_info[ix].repid, error != E_DLT);
326
327#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
328
329 if (error != E_OK) {
330 syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] delete REP error: %s",
331 apip, tskid, itron_strerror(error));
332 }
333
334 break;
335 }
336 }
337
338#if defined(SUPPORT_INET6) && defined(SUPPORT_INET4)
339
340 if (apip == API_PROTO_IPV6)
341 error = free_tcp6_cep(tcp_echo_srv_info[ix].cepid);
342 else
343 error = free_tcp4_cep(tcp_echo_srv_info[ix].cepid);
344
345#else /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
346
347 error = FREE_TCP_CEP(tcp_echo_srv_info[ix].cepid);
348
349#endif /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
350
351 if (error != E_OK) {
352 syslog(LOG_NOTICE, "[TCP%c ECHO SRV(EXT):%d] delete CEP error: %s",
353 apip, tskid, itron_strerror(error));
354 }
355
356 for (ix = NUM_TCP_ECHO_SRV_TASKS; -- ix >= 0; ) {
357 if (tcp_echo_srv_task_info[ix].taskid == tskid) {
358 tcp_echo_srv_task_info[ix].active = false;
359 break;
360 }
361 }
362
363 }
364 }
365
366#endif /* of #ifdef USE_TCP_EXTENTIONS */
367
368#endif /* of #ifdef USE_TCP_ECHO_SRV1 */
Note: See TracBrowser for help on using the repository browser.