summaryrefslogtreecommitdiffstats
path: root/nuttx/net
diff options
context:
space:
mode:
authorpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2011-06-05 23:29:38 +0000
committerpatacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679>2011-06-05 23:29:38 +0000
commit10184acdd204984b598e556579d702e0dd996915 (patch)
tree1c2ea4136091e836c9c285c7ec83b0e1da1b9adc /nuttx/net
parent3afdfef2ea534f8f729abb70e5d545dc04c2f3e0 (diff)
Minor improvement in recvfrom()
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@3673 7fd9a85b-ad96-42d3-883c-3090e2eb8679
Diffstat (limited to 'nuttx/net')
-rw-r--r--nuttx/net/recvfrom.c62
1 files changed, 32 insertions, 30 deletions
diff --git a/nuttx/net/recvfrom.c b/nuttx/net/recvfrom.c
index d974b85cf6..d9039b91be 100644
--- a/nuttx/net/recvfrom.c
+++ b/nuttx/net/recvfrom.c
@@ -861,7 +861,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
{
struct recvfrom_s state;
uip_lock_t save;
- int ret = OK;
+ int ret;
/* Initialize the state structure. This is done with interrupts
* disabled because we don't want anything to happen until we
@@ -878,9 +878,24 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
recvfrom_readahead(&state);
+
+ /* The default return value is the number of bytes that we just copied into
+ * the user buffer. We will return this if the socket has become disconnected
+ * or if the user request was completely satisfied with data from the readahead
+ * buffers.
+ */
+
+ ret = state.rf_recvlen;
+
+#else
+ /* Otherwise, the default return value of zero is used (only for the case
+ * where len == state.rf_buflen is zero).
+ */
+
+ ret = 0;
#endif
- /* Verify that the SOCK_STREAM has been or still is connected */
+ /* Verify that the SOCK_STREAM has been and still is connected */
if (!_SS_ISCONNECTED(psock->s_flags))
{
@@ -889,29 +904,17 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
*/
#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
- if (state.rf_recvlen <= 0)
+ if (ret <= 0)
+#endif
{
- /* Nothing was received. The SOCK_STREAM must be re-connected in
- * order to receive an additional data.
+ /* Nothing was previously received from the readahead buffers.
+ * The SOCK_STREAM must be (re-)connected in order to receive any
+ * additional data.
*/
ret = -ENOTCONN;
}
- else
- {
- /* The socket is disconnected, but there is data in the read-ahead
- * buffer. The return value is the number of bytes read from the
- * read-ahead buffer */
-
- ret = state.rf_recvlen;
- }
-#else
- /* The SOCK_STREAM must be connected inorder to receive data. */
-
- ret = -ENOTCONN;
-#endif
}
- else
/* In general, this uIP-based implementation will not support non-blocking
* socket operations... except in a few cases: Here for TCP receive with read-ahead
@@ -919,31 +922,30 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
* if no data was obtained from the read-ahead buffers.
*/
+ else
#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
if (_SS_ISNONBLOCK(psock->s_flags))
{
- /* Return OK if something was received; EGAIN if not */
+ /* Return the number of bytes read from the read-ahead buffer if
+ * something was received (already in 'ret'); EGAIN if not.
+ */
- if (state.rf_recvlen <= 0)
+ if (ret <= 0)
{
/* Nothing was received */
ret = -EAGAIN;
}
- else
- {
- /* The return value is the number of bytes read from the read-ahead buffer */
-
- ret = state.rf_recvlen;
- }
}
/* It is okay to block if we need to. If there is space to receive anything
- * more, then we will wait to receive the data.
+ * more, then we will wait to receive the data. Otherwise return the number
+ * of bytes read from the read-ahead buffer (already in 'ret').
*/
- else if (state.rf_buflen > 0)
+ else
#endif
+ if (state.rf_buflen > 0)
{
struct uip_conn *conn = (struct uip_conn *)psock->s_conn;
@@ -977,7 +979,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
uip_unlock(save);
recvfrom_uninit(&state);
- return ret;
+ return (ssize_t)ret;
}
#endif /* CONFIG_NET_TCP */