diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-23 20:45:30 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-23 20:45:30 +0000 |
commit | 7326b1166b618ddc6b3eb9e9224b1f5ded5515a5 (patch) | |
tree | aac340a4c4cc123213e08b83d1c452a67f333a35 /nuttx/net/listen.c | |
parent | 1b15ed82bb5f48d8a03366af769331eac73c9993 (diff) | |
download | px4-nuttx-7326b1166b618ddc6b3eb9e9224b1f5ded5515a5.tar.gz px4-nuttx-7326b1166b618ddc6b3eb9e9224b1f5ded5515a5.tar.bz2 px4-nuttx-7326b1166b618ddc6b3eb9e9224b1f5ded5515a5.zip |
Partial implementation of accept() and listen()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@354 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/listen.c')
-rw-r--r-- | nuttx/net/listen.c | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/nuttx/net/listen.c b/nuttx/net/listen.c index 30dcb778b..08f9d851a 100644 --- a/nuttx/net/listen.c +++ b/nuttx/net/listen.c @@ -56,7 +56,7 @@ * Description: * To accept connections, a socket is first created with socket(), a * willingness to accept incoming connections and a queue limit for incoming - * connections are specified with listen, and then the connections are + * connections are specified with listen(), and then the connections are * accepted with accept(). The listen() call applies only to sockets of * type SOCK_STREAM or SOCK_SEQPACKET. * @@ -87,7 +87,51 @@ int listen(int sockfd, int backlog) { - *get_errno_ptr() = ENOSYS; + FAR struct socket *psock = sockfd_socket(sockfd); + struct uip_conn *conn; + int err; + + /* Verify that the sockfd corresponds to valid, allocated socket */ + + if (!psock || psock->s_crefs <= 0) + { + /* It is not a valid socket description. Distinguish between the cases + * where sockfd is a just valid and when it is a valid file descriptor used + * in the wrong context. + */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 + if ((unsigned int)sockfd < CONFIG_NFILE_DESCRIPTORS) + { + err = ENOTSOCK; + } + else +#endif + { + err = EBADF; + } + goto errout; + } + + /* Verify that the sockfd corresponds to a connected SOCK_STREAM */ + + conn = (struct uip_conn *)psock->s_conn; + if (psock->s_type != SOCK_STREAM || !psock->s_conn || conn->lport <= 0) + { + err = EOPNOTSUPP; + goto errout; + } + + /* Start listening to the bound port. This enables callbacks when accept() + * is called; and someday should enable post() or select() logic. + */ + + uip_listen(conn->lport); + psock->s_flags |= _SF_LISTENING; + return OK; + +errout: + *get_errno_ptr() = err; return ERROR; } |