diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-15 22:45:45 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-09-15 22:45:45 +0000 |
commit | 42027d080b72b8198072e7dc3933d8b70b6b40a5 (patch) | |
tree | d471d699ed674cbc615d89cd830e83c1b61d9eea /nuttx/net/connect.c | |
parent | 8bd136d2202c6706ac2166a31b90f1ec18139dea (diff) | |
download | px4-nuttx-42027d080b72b8198072e7dc3933d8b70b6b40a5.tar.gz px4-nuttx-42027d080b72b8198072e7dc3933d8b70b6b40a5.tar.bz2 px4-nuttx-42027d080b72b8198072e7dc3933d8b70b6b40a5.zip |
Add basic structure to support multiple network interfaces
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@343 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/connect.c')
-rw-r--r-- | nuttx/net/connect.c | 82 |
1 files changed, 71 insertions, 11 deletions
diff --git a/nuttx/net/connect.c b/nuttx/net/connect.c index 2a9708b9a..523c1d7c1 100644 --- a/nuttx/net/connect.c +++ b/nuttx/net/connect.c @@ -47,7 +47,55 @@ #include "net-internal.h" /**************************************************************************** - * Global Functions + * Private Functions + ****************************************************************************/ +/**************************************************************************** + * Function: connection_event + * + * Description: + * Some connection related event has occurred + * + * Parameters: + * dev The sructure of the network driver that caused the interrupt + * private An instance of struct recvfrom_s cast to void* + * + * Returned Value: + * None + * + * Assumptions: + * Running at the interrupt level + * + ****************************************************************************/ + +static void connection_event(void *private) +{ + FAR struct socket *psock = (FAR struct socket *)private; + if (psock) + { + /* UIP_CLOSE: The remote host has closed the connection + * UIP_ABORT: The remote host has aborted the connection + * UIP_TIMEDOUT: Connection aborted due to too many retransmissions. + */ + if ((uip_flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) + { + /* Indicate that the socet is no longer connected */ + + psock->s_flags &= ~_SF_CONNECTED; + } + + /* UIP_CONNECTED: The socket is successfully connected */ + + else if ((uip_flags & UIP_CONNECTED) != 0) + { + /* Indicate that the socet is no longer connected */ + + psock->s_flags |= _SF_CONNECTED; + } + } +} + +/**************************************************************************** + * Public Functions ****************************************************************************/ /**************************************************************************** @@ -128,6 +176,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) FAR const struct sockaddr_in *inaddr = (const struct sockaddr_in *)addr; #endif int err; + int ret; /* Verify that the sockfd corresponds to valid, allocated socket */ @@ -155,7 +204,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { case SOCK_STREAM: { - int ret; + struct uip_conn *conn; /* Verify that the socket is not already connected */ @@ -165,25 +214,36 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) goto errout; } - /* Perform the uIP connection operation */ + /* Get the connection reference from the socket */ - ret = uip_tcpconnect(psock->s_conn, inaddr); - if (ret < 0) + conn = psock->s_conn; + if (conn) /* Should alwasy be non-NULL */ { - err = -ret; - goto errout; - } + /* Perform the uIP connection operation */ - /* Mark the connection bound and connected */ + ret = uip_tcpconnect(psock->s_conn, inaddr); + if (ret < 0) + { + err = -ret; + goto errout; + } - psock->s_flags |= (_SF_BOUND|_SF_CONNECTED); + /* Mark the connection bound and connected */ + + psock->s_flags |= (_SF_BOUND|_SF_CONNECTED); + + /* Set up to receive callbacks on connection-related events */ + + conn->connection_private = (void*)psock; + conn->connection_event = connection_event; + } } break; #ifdef CONFIG_NET_UDP case SOCK_DGRAM: { - int ret = uip_udpconnect(psock->s_conn, inaddr); + ret = uip_udpconnect(psock->s_conn, inaddr); if (ret < 0) { err = -ret; |