diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-07-19 13:50:08 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2009-07-19 13:50:08 +0000 |
commit | 85f8218d49dfea1bea70633d38cede541143a1df (patch) | |
tree | 05dbb3d914eaf7434bd20987200ba57e3aafaa24 /nuttx/net/recvfrom.c | |
parent | 17553d10657c2a395a2ab1f7d6629453fc5ed342 (diff) | |
download | px4-nuttx-85f8218d49dfea1bea70633d38cede541143a1df.tar.gz px4-nuttx-85f8218d49dfea1bea70633d38cede541143a1df.tar.bz2 px4-nuttx-85f8218d49dfea1bea70633d38cede541143a1df.zip |
Add non-blocking capability for TCP sockets
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1996 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/recvfrom.c')
-rw-r--r-- | nuttx/net/recvfrom.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/nuttx/net/recvfrom.c b/nuttx/net/recvfrom.c index 6ff8e5724..345ec380a 100644 --- a/nuttx/net/recvfrom.c +++ b/nuttx/net/recvfrom.c @@ -868,7 +868,6 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, return -ENOTCONN; } - /* Initialize the state structure. This is done with interrupts * disabled because we don't want anything to happen until we * are ready. @@ -883,11 +882,29 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, recvfrom_readahead(&state); - /* If there is space to receive anything more, then we will - * wait to receive the data. + /* In general, this uI-based implementation will not support non-blocking + * socket operations... except in this one case: TCP receive with read-ahead + * enabled. If this socket is configured as non-blocking then return EAGAIN + * if no data was obtained from the read-ahead buffers. + */ + + if (_SS_ISNONBLOCK(psock->s_flags)) + { + /* Return OK if something was received; EGAIN if not */ + + if (state.rf_recvlen <= 0) + { + /* Nothing was received */ + + return -EAGAIN; + } + } + + /* 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. */ - if (state.rf_buflen > 0) + else if (state.rf_buflen > 0) #endif { struct uip_conn *conn = (struct uip_conn *)psock->s_conn; |