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