source: asp3_tinet_ecnl_rx/trunk/asp3_dcre/tinet/netapp/udp6_echo_srv.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: 8.3 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 * UDP ECHO サーバ
36 *
37 * IPv6
38 */
39
40#include <string.h>
41
42#ifdef TARGET_KERNEL_ASP
43
44#include <kernel.h>
45#include <sil.h>
46#include <t_syslog.h>
47#include "kernel_cfg.h"
48
49#endif /* of #ifdef TARGET_KERNEL_ASP */
50
51#ifdef TARGET_KERNEL_JSP
52
53#include <t_services.h>
54#include "kernel_id.h"
55#include "tinet_id.h"
56
57#endif /* of #ifdef TARGET_KERNEL_JSP */
58
59#include <netinet/in.h>
60#include <netinet/in_itron.h>
61
62#include <netapp/netapp.h>
63#include <netapp/netapp_var.h>
64#include <netapp/udp6_echo_srv.h>
65
66#ifdef USE_UDP6_ECHO_SRV_TSK
67
68/*
69 * 受信タイムアウト
70 */
71
72#define RCV_TMOUT TMO_FEVR
73//#define RCV_TMOUT (30*ULONG_C(1000))
74
75#define BUF_SIZE 2048
76
77static char echo_rcv_buf[BUF_SIZE];
78static T_IPV6EP dst;
79
80#ifdef USE_UDP_CALL_BACK
81
82/*
83 * コールバック関数
84 */
85
86ER
87callback_udp6_echo_srv (ID cepid, FN fncd, void *p_parblk)
88{
89 ER_UINT len;
90 SYSTIM now;
91
92 if ((len = udp6_rcv_dat(cepid, &dst, echo_rcv_buf, sizeof(echo_rcv_buf), TMO_FEVR)) >= 0) {
93 echo_rcv_buf[len] = '\0';
94 get_tim(&now);
95 syslog(LOG_NOTICE, "[UES6:%02u UCB] recv: %7lu,from: %s.%d\n"
96 " msg: %s",
97 cepid, now / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, echo_rcv_buf);
98 if (len > 0) {
99 len = udp6_snd_dat(cepid, &dst, echo_rcv_buf, len, TMO_FEVR);
100 get_tim(&now);
101 if (len >= 0)
102 syslog(LOG_NOTICE, "[UES6:%02u UCB] send: %7lu, len: %d",
103 cepid, now / SYSTIM_HZ, len);
104 else
105 syslog(LOG_NOTICE, "[UES6:%02u UCB] error: %7lu,%s",
106 cepid, now / SYSTIM_HZ, itron_strerror(len));
107 }
108 len = E_OK;
109 }
110 else {
111 get_tim(&now);
112 syslog(LOG_NOTICE, "[UES6:%02u UCB] recv: %7lu,%s",
113 cepid, now / SYSTIM_HZ, itron_strerror(len));
114 }
115
116 return len;
117 }
118
119#else /* of #ifdef USE_UDP_CALL_BACK */
120
121#ifdef USE_UDP_NON_BLOCKING
122
123/*
124 * 変数
125 */
126
127static ER_UINT nblk_len;
128
129/*
130 * ノンブロッキングコールのコールバック関数
131 */
132
133ER
134callback_nblk_udp6_echo_srv (ID cepid, FN fncd, void *p_parblk)
135{
136 SYSTIM now;
137
138 get_tim(&now);
139 nblk_len = *(ER_UINT*)p_parblk;
140 if (nblk_len < 0) { /* 0 以下の場合は、エラーコード */
141 syslog(LOG_NOTICE, "[UES6:%02u CBR] error: %7lu,%s, fncd: %s",
142 cepid, now / SYSTIM_HZ, itron_strerror(nblk_len), in_strtfn(fncd));
143 }
144 else if (fncd == TFN_UDP_RCV_DAT) {
145 echo_rcv_buf[nblk_len] = '\0';
146 syslog(LOG_NOTICE, "[UES6:%02u CBR] recv: %7lu,from: %s.%d\n"
147 " msg: %s",
148 cepid, now / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, echo_rcv_buf);
149 }
150 syscall(wup_tsk(UDP6_ECHO_SRV_TASK));
151 return E_OK;
152 }
153
154/*
155 * UDP ECHO サーバ
156 */
157
158ER
159udp6_echo_srv (ID cepid)
160{
161 ER error;
162 SYSTIM now;
163
164 if ((error = udp6_rcv_dat(cepid, &dst, echo_rcv_buf, sizeof(echo_rcv_buf), TMO_NBLK)) != E_WBLK) {
165 get_tim(&now);
166 syslog(LOG_NOTICE, "[UES6:%02u RCV] error: %7lu,%s", cepid, now / SYSTIM_HZ, itron_strerror(error));
167 return error;
168 }
169
170 syscall(slp_tsk());
171 if (nblk_len < 0)
172 error = nblk_len;
173 else {
174 if ((error = udp6_snd_dat(cepid, &dst, echo_rcv_buf, nblk_len, TMO_NBLK)) != E_WBLK) {
175 get_tim(&now);
176 syslog(LOG_NOTICE, "[UES6:%02u SND] error %7lu,%s",
177 cepid, now / SYSTIM_HZ, itron_strerror(error));
178 return error;
179 }
180
181 syscall(slp_tsk());
182 if (nblk_len < 0)
183 error = nblk_len;
184 else {
185 get_tim(&now);
186 syslog(LOG_NOTICE, "[UES6:%02u SND] send: %7lu, len: %d",
187 cepid, now / SYSTIM_HZ, nblk_len);
188 error = E_OK;
189 }
190 }
191
192 return error;
193 }
194
195#else /* of #ifdef USE_UDP_NON_BLOCKING */
196
197/*
198 * UDP ECHO サーバ
199 */
200
201ER
202udp6_echo_srv (ID cepid)
203{
204 ER_UINT len;
205 SYSTIM now;
206
207 if ((len = udp6_rcv_dat(cepid, &dst, echo_rcv_buf, sizeof(echo_rcv_buf), RCV_TMOUT)) >= 0) {
208 get_tim(&now);
209 echo_rcv_buf[len] = '\0';
210 syslog(LOG_NOTICE, "[UES6:%02u RCV] recv: %7lu,from: %s.%d\n"
211 " msg: %s",
212 cepid, now / SYSTIM_HZ, ipv62str(NULL, &dst.ipaddr), dst.portno, echo_rcv_buf);
213 if (len > 0) {
214 len = udp6_snd_dat(cepid, &dst, echo_rcv_buf, len, TMO_FEVR);
215 get_tim(&now);
216 if (len >= 0)
217 syslog(LOG_NOTICE, "[UES6:%02u SND] send: %7lu, len: %d",
218 cepid, now / SYSTIM_HZ, (uint16_t)len);
219 else
220 syslog(LOG_NOTICE, "[UES6:%02u SND] error: %7lu,%s",
221 cepid, now / SYSTIM_HZ, itron_strerror(len));
222 }
223 }
224 else {
225 get_tim(&now);
226 syslog(LOG_NOTICE, "[UES6:%02u RCV] error: %7lu,%s",
227 cepid, now / SYSTIM_HZ, itron_strerror(len));
228 }
229
230 return len >= 0 || len == E_TMOUT ? E_OK : len;
231 }
232
233#endif /* of #ifdef USE_UDP_NON_BLOCKING */
234
235/*
236 * UDP ECHO サーバタスク
237 */
238
239#ifdef USE_UDP_EXTENTIONS
240
241void
242udp6_echo_srv_task (intptr_t exinf)
243{
244 ID tskid, cepid;
245 ER error;
246 T_UDP6_CCEP ccep;
247
248 get_tid(&tskid);
249 syslog(LOG_NOTICE, "[UDP6 ECHO SRV(EXT):%d] started.", tskid);
250 while (true) {
251
252 syscall(slp_tsk());
253 syslog(LOG_NOTICE, "[UDP6 ECHO SRV(EXT):%d] wake up.", tskid);
254
255 ccep.cepatr = UINT_C(0);
256 ccep.myaddr.portno = UINT_C(7);
257 memcpy(&ccep.myaddr.ipaddr, &ipv6_addrany, sizeof(T_IN6_ADDR));
258
259#ifdef USE_UDP_NON_BLOCKING
260 ccep.callback = (FP)callback_nblk_udp6_echo_srv;
261#else
262 ccep.callback = NULL;
263#endif
264
265 if ((error = alloc_udp6_cep(&cepid, tskid, &ccep)) != E_OK) {
266 syslog(LOG_NOTICE, "[UES6:%02u TSK] CEP create error:%s", cepid, itron_strerror(error));
267 continue;
268 }
269
270 while (error == E_OK) {
271 if ((error = udp6_echo_srv(cepid)) != E_OK) {
272 if ((error = free_udp6_cep(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
273 syslog(LOG_NOTICE, "[UES6:%02u TSK] CEP delete error:%s", cepid, itron_strerror(error));
274 break;
275 }
276 }
277
278 }
279 slp_tsk();
280 }
281
282#else /* of #ifdef USE_UDP_EXTENTIONS */
283
284void
285udp6_echo_srv_task (intptr_t exinf)
286{
287 ID tskid;
288 ER error = E_OK;
289
290 get_tid(&tskid);
291 syslog(LOG_NOTICE, "[UDP6 ECHO SRV:%d,%d] started.", tskid, (ID)exinf);
292 while (error == E_OK) {
293 error = udp6_echo_srv((ID)exinf);
294 }
295 slp_tsk();
296 }
297
298#endif /* of #ifdef USE_UDP_EXTENTIONS */
299
300#endif /* of #ifdef USE_UDP_CALL_BACK */
301
302#endif /* of #ifdef USE_UDP6_ECHO_SRV_TSK */
Note: See TracBrowser for help on using the repository browser.