FreeCalypso > hg > fc-selenite
comparison src/g23m-fad/tcpip/rnet/rnet_rt/rnet_rt_api_recvfrom.c @ 1:d393cd9bb723
src/g23m-*: initial import from Magnetite
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 15 Jul 2018 04:40:46 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:b6a5e36de839 | 1:d393cd9bb723 |
---|---|
1 /** | |
2 * @file rnet_rt_api_recvfrom.c | |
3 * | |
4 * RNET_RT API | |
5 * | |
6 * @author Regis Feneon | |
7 * @version 0.1 | |
8 */ | |
9 | |
10 /* | |
11 * $Id: rnet_rt_api_recvfrom.c,v 1.2 2002/10/30 15:23:34 rf Exp $ | |
12 * $Name: ti_20021030 $ | |
13 * | |
14 * History: | |
15 * | |
16 * Date Author Modification | |
17 * -------------------------------------------------- | |
18 * 6/24/2002 Regis Feneon Create | |
19 * | |
20 */ | |
21 #include "rnet_cfg.h" | |
22 #ifdef RNET_CFG_REAL_TRANSPORT | |
23 | |
24 #include "rnet_rt_i.h" | |
25 #include "rnet_rt_env.h" | |
26 | |
27 | |
28 /** | |
29 * Read the waiting data (not-blocking). | |
30 * | |
31 * Data reception is message based: When the application receives a | |
32 * T_RNET_RECV_IND message, it can read the data with this | |
33 * rnet_recv() function. | |
34 * | |
35 * The data are copied in the buffer given by the application to RNET | |
36 * via this rnet_recv function. | |
37 * | |
38 * Datagram oriented (UDP) | |
39 * ----------------------- | |
40 * When an UDP datagram arrives, the receiver application receives | |
41 * a T_RNET_RECV_IND message. The application can then read the | |
42 * datagram with the rnet_recv function. The buffer passed to the | |
43 * function should be big enough to contain a UDP datagram, otherwise | |
44 * the message is not put in the buffer and the error code | |
45 * RNET_MSG_SIZE is returned. | |
46 * | |
47 * The OUT value of the len_p parameter can have two possible values: | |
48 * - If there was data to read and no error detected (function | |
49 * returned RNET_OK), len_p contains the size of the received datagram. | |
50 * - If there was no error, but no data to read, len_p contains 0. | |
51 * | |
52 * RNET will only send a new T_RNET_RECV_IND with a specific descriptor | |
53 * when a rnet_recv function has been called that returned a len_p parameter | |
54 * with a 0 value. Therefore, the application should loop on rnet_recv when | |
55 * it receives a T_RNET_RECV_IND message, like: | |
56 * UINT16 *len_p = -1; | |
57 * while (*len_p != 0) { | |
58 * ret = rnet_recv(desc, buff, len_p); | |
59 * ... | |
60 * } | |
61 * | |
62 * Stream oriented (TCP) | |
63 * --------------------- | |
64 * When a new stream of data arrives on a connection, the receiver | |
65 * application receives a T_RNET_RECV_IND. It can then read the flow | |
66 * with the rnet_recv function, until the len_p parameter is returned | |
67 * with a 0 value. | |
68 * | |
69 * The stack will only send a new T_RNET_RECV_IND message when | |
70 * rnet_recv has been called and has returned the len_p parameter with a 0. | |
71 * | |
72 * | |
73 * @param desc Connection identifier [IN]. | |
74 * @param buff Buffer to store the received data [OUT]. | |
75 * @param len_p Pointer on the length of the passed buffer [IN] | |
76 * Pointer on the size of the received data in the buffer [OUT]. | |
77 * @return RNET_MEMORY_ERR Not enough memory is available | |
78 * RNET_NOT_INITIALIZED NET subsystem not initialized (internal error). | |
79 * RNET_INTERNAL_ERR Network subsystem failed. | |
80 * RNET_NOT_READY Still processing a callback function. | |
81 * RNET_INVALID_PARAMETER The connection ID is invalid. | |
82 * or The ID is not connected. | |
83 * or Invalid buff parameter. | |
84 * or Connection not bound with bind. | |
85 * RNET_CONN_ABORTED Connection broken due to the "keep-alive" activity | |
86 * detecting a failure while the operation was in progress. | |
87 * or Virtual circuit terminated due to a time-out or other failure. | |
88 * RNET_MSG_SIZE The socket is message oriented (UDP), and the message | |
89 * was too large to fit into the specified buffer and was truncated. | |
90 * RNET_CONN_RESET The virtual circuit was reset by the remote side executing a "hard" | |
91 * or "abortive" close. | |
92 * RNET_TIMEOUT The connection has been dropped, because of a | |
93 * network failure or because the system on the other end went down | |
94 * without notice. | |
95 * RNET_NET_UNREACHABLE Remote host cannot be reached from this host at this time. | |
96 * RNET_OK Data successfully read. | |
97 */ | |
98 | |
99 T_RNET_RET rnet_rt_recv_from (T_RNET_DESC * desc, | |
100 T_RVF_BUFFER * buff, | |
101 UINT16 * len_p, | |
102 T_RNET_IP_ADDR * from_addr, | |
103 T_RNET_PORT * from_port) | |
104 { | |
105 int ret, rflags; | |
106 NGsockaddr faddr; | |
107 | |
108 rflags = 0; | |
109 rvf_lock_mutex( &rnet_rt_env_ctrl_blk_p->mutex); | |
110 ret = ngSAIORecv( (NGsock *) desc, buff, *len_p, &rflags, &faddr, NULL); | |
111 if( ret == NG_EWOULDBLOCK) { | |
112 /* no more data to read, will send T_RNET_RECV_IND message */ | |
113 /* when new data will be received */ | |
114 ((T_RNET_RT_SOCK *) desc)->flags |= RNET_RT_SOCKF_NOTIFY_RECV; | |
115 ret = 0; | |
116 } | |
117 rvf_unlock_mutex( &rnet_rt_env_ctrl_blk_p->mutex); | |
118 | |
119 if( ret >= 0) { | |
120 /* return nb of read bytes */ | |
121 *len_p = ret; | |
122 /* return source address and port number */ | |
123 *from_addr = ngNTOHL( faddr.sin_addr); | |
124 *from_port = ngNTOHS( faddr.sin_port); | |
125 /* check if message was truncated */ | |
126 return( (rflags & NG_IO_TRUNC) ? RNET_MSG_SIZE : RNET_OK); | |
127 } | |
128 | |
129 return( rnet_rt_ngip_error( ret)); | |
130 } | |
131 | |
132 #endif /* ifdef RNET_CFG_REAL_TRANSPORT */ | |
133 |