diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-03-13 13:02:45 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-03-13 13:02:45 +0000 |
commit | 44845f6ba52562efd54a6e87492ae909d00d5d7e (patch) | |
tree | f49c263c540623ab84da4b09bf4b1df4cd0e6c14 /nuttx/net | |
parent | 8dbef7e28bb85c9106ea80d03114ccfec0033a9a (diff) | |
download | px4-nuttx-44845f6ba52562efd54a6e87492ae909d00d5d7e.tar.gz px4-nuttx-44845f6ba52562efd54a6e87492ae909d00d5d7e.tar.bz2 px4-nuttx-44845f6ba52562efd54a6e87492ae909d00d5d7e.zip |
Add psock_connect()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4483 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net')
-rw-r--r-- | nuttx/net/connect.c | 97 |
1 files changed, 88 insertions, 9 deletions
diff --git a/nuttx/net/connect.c b/nuttx/net/connect.c index cffdb12e5..fdbb34f55 100644 --- a/nuttx/net/connect.c +++ b/nuttx/net/connect.c @@ -354,15 +354,15 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in * Public Functions ****************************************************************************/ /**************************************************************************** - * Name: connect + * Name: psock_connect * * Description: - * connect() connects the socket referred to by the file descriptor sockfd + * connect() connects the socket referred to by the structure 'psock' * to the address specified by 'addr'. The addrlen argument specifies * the size of 'addr'. The format of the address in 'addr' is - * determined by the address space of the socket sockfd. + * determined by the address space of the socket 'psock'. * - * If the socket sockfd is of type SOCK_DGRAM then 'addr' is the address + * If the socket 'psock' is of type SOCK_DGRAM then 'addr' is the address * to which datagrams are sent by default, and the only address from which * datagrams are received. If the socket is of type SOCK_STREAM or * SOCK_SEQPACKET, this call attempts to make a connection to the socket @@ -375,7 +375,7 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in * sockaddr set to AF_UNSPEC. * * Parameters: - * sockfd Socket descriptor returned by socket() + * psock Pointer to a socket structure initialized by psock_socket() * addr Server address (form depends on type of socket) * addrlen Length of actual 'addr' * @@ -422,10 +422,9 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in * ****************************************************************************/ -int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) +int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr, + socklen_t addrlen) { - FAR struct socket *psock = sockfd_socket(sockfd); - #if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) #ifdef CONFIG_NET_IPv6 FAR const struct sockaddr_in6 *inaddr = (const struct sockaddr_in6 *)addr; @@ -437,7 +436,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) int err; - /* Verify that the sockfd corresponds to valid, allocated socket */ + /* Verify that the psock corresponds to valid, allocated socket */ if (!psock || psock->s_crefs <= 0) { @@ -509,4 +508,84 @@ errout: return ERROR; } +/**************************************************************************** + * Name: connect + * + * Description: + * connect() connects the socket referred to by the file descriptor 'sockfd' + * to the address specified by 'addr'. The addrlen argument specifies + * the size of 'addr'. The format of the address in 'addr' is + * determined by the address space of the socket 'sockfd'. + * + * If the socket 'sockfd' is of type SOCK_DGRAM then 'addr' is the address + * to which datagrams are sent by default, and the only address from which + * datagrams are received. If the socket is of type SOCK_STREAM or + * SOCK_SEQPACKET, this call attempts to make a connection to the socket + * that is bound to the address specified by 'addr'. + * + * Generally, connection-based protocol sockets may successfully connect() + * only once; connectionless protocol sockets may use connect() multiple + * times to change their association. Connectionless sockets may dissolve + * the association by connecting to an address with the sa_family member of + * sockaddr set to AF_UNSPEC. + * + * Parameters: + * sockfd Socket descriptor returned by socket() + * addr Server address (form depends on type of socket) + * addrlen Length of actual 'addr' + * + * Returned Value: + * 0 on success; -1 on error with errno set appropriately + * + * EACCES, EPERM + * The user tried to connect to a broadcast address without having the + * socket broadcast flag enabled or the connection request failed + * because of a local firewall rule. + * EADDRINUSE + * Local address is already in use. + * EAFNOSUPPORT + * The passed address didn't have the correct address family in its + * sa_family field. + * EAGAIN + * No more free local ports or insufficient entries in the routing + * cache. + * EALREADY + * The socket is non-blocking and a previous connection attempt has + * not yet been completed. + * EBADF + * The file descriptor is not a valid index in the descriptor table. + * ECONNREFUSED + * No one listening on the remote address. + * EFAULT + * The socket structure address is outside the user's address space. + * EINPROGRESS + * The socket is non-blocking and the connection cannot be completed + * immediately. + * EINTR + * The system call was interrupted by a signal that was caught. + * EISCONN + * The socket is already connected. + * ENETUNREACH + * Network is unreachable. + * ENOTSOCK + * The file descriptor is not associated with a socket. + * ETIMEDOUT + * Timeout while attempting connection. The server may be too busy + * to accept new connections. + * + * Assumptions: + * + ****************************************************************************/ + +int connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen) +{ + /* Get the underlying socket structure */ + + FAR struct socket *psock = sockfd_socket(sockfd); + + /* Then let psock_connect() do all of the work */ + + return psock_connect(psock, addr, addrlen); +} + #endif /* CONFIG_NET */ |