source: asp3_tinet_ecnl_rx/trunk/asp3_dcre/tinet/netapp/udp4_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 * IPv4
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/udp4_echo_srv.h>
65
66#ifdef USE_UDP4_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_IPV4EP dst;
79
80#ifdef USE_UDP_CALL_BACK
81
82/*
83 * コールバック関数
84 */
85
86ER
87callback_udp4_echo_srv (ID cepid, FN fncd, void *p_parblk)
88{
89 ER_UINT len;
90 SYSTIM now;
91
92 if ((len = udp_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, "[UES4:%02u UCB] recv: %7lu,from: %s.%d\n"
96 " msg: %s",
97 cepid, now / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, echo_rcv_buf);
98 if (len > 0) {
99 len = udp_snd_dat(cepid, &dst, echo_rcv_buf, len, TMO_FEVR);
100 get_tim(&now);
101 if (len >= 0)
102 syslog(LOG_NOTICE, "[UES4:%02u UCB] send: %7lu, len: %d",
103 cepid, now / SYSTIM_HZ, len);
104 else
105 syslog(LOG_NOTICE, "[UES4:%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, "[UES4:%02u UCB] error: %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_udp4_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, "[UES4:%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, "[UES4:%02u CBR] recv: %7lu,from: %s.%d\n"
147 " msg: %s",
148 cepid, now / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, echo_rcv_buf);
149 }
150 syscall(wup_tsk(UDP4_ECHO_SRV_TASK));
151 return E_OK;
152 }
153
154/*
155 * UDP ECHO サーバ
156 */
157
158ER
159udp4_echo_srv (ID cepid)
160{
161 ER error;
162 SYSTIM now;
163
164 if ((error = udp_rcv_dat(cepid, &dst, echo_rcv_buf, sizeof(echo_rcv_buf), TMO_NBLK)) != E_WBLK) {
165 get_tim(&now);
166 syslog(LOG_NOTICE, "[UES4:%02u RCV] error: %7lu,%s",
167 cepid, now / SYSTIM_HZ, itron_strerror(error));
168 return error;
169 }
170
171 syscall(slp_tsk());
172 if (nblk_len < 0)
173 error = nblk_len;
174 else {
175 if ((error = udp_snd_dat(cepid, &dst, echo_rcv_buf, nblk_len, TMO_NBLK)) != E_WBLK) {
176 get_tim(&now);
177 syslog(LOG_NOTICE, "[UES4:%02u SND] error: %7lu,%s",
178 cepid, now / SYSTIM_HZ, itron_strerror(error));
179 return error;
180 }
181
182 syscall(slp_tsk());
183 if (nblk_len < 0)
184 error = nblk_len;
185 else {
186 get_tim(&now);
187 syslog(LOG_NOTICE, "[UES4:%02u SND] send: %7lu, len: %d",
188 cepid, now / SYSTIM_HZ, nblk_len);
189 error = E_OK;
190 }
191 }
192
193 return error;
194 }
195
196#else /* of #ifdef USE_UDP_NON_BLOCKING */
197
198/*
199 * UDP ECHO サーバ
200 */
201
202ER
203udp4_echo_srv (ID cepid)
204{
205 ER_UINT len;
206 SYSTIM now;
207
208 if ((len = udp_rcv_dat(cepid, &dst, echo_rcv_buf, sizeof(echo_rcv_buf), RCV_TMOUT)) >= 0) {
209 get_tim(&now);
210 echo_rcv_buf[len] = '\0';
211 syslog(LOG_NOTICE, "[UES4:%02u RCV] recv: %7lu,from: %s.%d\n"
212 " msg: %s",
213 cepid, now / SYSTIM_HZ, ip2str(NULL, &dst.ipaddr), dst.portno, echo_rcv_buf);
214 if (len > 0) {
215 len = udp_snd_dat(cepid, &dst, echo_rcv_buf, len, TMO_FEVR);
216 get_tim(&now);
217 if (len >= 0)
218 syslog(LOG_NOTICE, "[UES4:%02u SND] send: %7lu, len: %d",
219 cepid, now / SYSTIM_HZ, (uint16_t)len);
220 else
221 syslog(LOG_NOTICE, "[UES4:%02u SND] error: %7lu,%s",
222 cepid, now / SYSTIM_HZ, itron_strerror(len));
223 }
224 }
225 else {
226 get_tim(&now);
227 syslog(LOG_NOTICE, "[UES4:%02u RCV] error: %7lu,%s",
228 cepid, now / SYSTIM_HZ, itron_strerror(len));
229 }
230
231 return len >= 0 || len == E_TMOUT ? E_OK : len;
232 }
233
234#endif /* of #ifdef USE_UDP_NON_BLOCKING */
235
236/*
237 * UDP ECHO サーバタスク
238 */
239
240#ifdef USE_UDP_EXTENTIONS
241
242void
243udp4_echo_srv_task (intptr_t exinf)
244{
245 ID tskid, cepid;
246 ER error;
247 T_UDP_CCEP ccep;
248
249 get_tid(&tskid);
250 syslog(LOG_NOTICE, "[UDP4 ECHO SRV(EXT):%d] started.", tskid);
251 while (true) {
252
253 syscall(slp_tsk());
254 syslog(LOG_NOTICE, "[UDP4 ECHO SRV(EXT):%d] wake up.", tskid);
255
256 ccep.cepatr = UINT_C(0);
257 ccep.myaddr.portno = UINT_C(7);
258 ccep.myaddr.ipaddr = IPV4_ADDRANY;
259
260#ifdef USE_UDP_NON_BLOCKING
261 ccep.callback = (FP)callback_nblk_udp4_echo_srv;
262#else
263 ccep.callback = NULL;
264#endif
265
266 if ((error = alloc_udp4_cep(&cepid, tskid, &ccep)) != E_OK) {
267 syslog(LOG_NOTICE, "[UES4:%02u TSK] CEP create error:%s", cepid, itron_strerror(error));
268 continue;
269 }
270
271 while (error == E_OK) {
272 if ((error = udp4_echo_srv(cepid)) != E_OK) {
273 if ((error = free_udp4_cep(cepid, !(error == E_NOEXS || error == E_DLT))) != E_OK)
274 syslog(LOG_NOTICE, "[UES4:%02u TSK] CEP delete error:%s", cepid, itron_strerror(error));
275 break;
276 }
277 }
278
279 }
280 slp_tsk();
281 }
282
283#else /* of #ifdef USE_UDP_EXTENTIONS */
284
285void
286udp4_echo_srv_task (intptr_t exinf)
287{
288 ID tskid;
289 ER error = E_OK;
290
291 get_tid(&tskid);
292 syslog(LOG_NOTICE, "[UDP4 ECHO SRV:%d,%d] started.", tskid, (ID)exinf);
293 while (error == E_OK) {
294 error = udp4_echo_srv((ID)exinf);
295 }
296 slp_tsk();
297 }
298
299#endif /* of #ifdef USE_UDP_EXTENTIONS */
300
301#endif /* of #ifdef USE_UDP_CALL_BACK */
302
303#endif /* of #ifdef USE_UDP4_ECHO_SRV_TSK */
Note: See TracBrowser for help on using the repository browser.