mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
net/inet: move socket flags into socket_conn_s
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
1b0f85c5bc
commit
99cde13a11
@@ -1177,11 +1177,11 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
|
|||||||
if (file->f_inode && INODE_IS_SOCKET(file->f_inode))
|
if (file->f_inode && INODE_IS_SOCKET(file->f_inode))
|
||||||
{
|
{
|
||||||
FAR struct socket *socket = file->f_priv;
|
FAR struct socket *socket = file->f_priv;
|
||||||
|
FAR struct socket_conn_s *conn = socket->s_conn;
|
||||||
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
||||||
"%3d %3d %02x",
|
"%3d %3d %02x",
|
||||||
i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK +
|
i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK +
|
||||||
j, socket->s_type,
|
j, socket->s_type, conn->s_flags);
|
||||||
socket->s_flags);
|
|
||||||
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
copysize = procfs_memcpy(procfile->line, linesize, buffer,
|
||||||
remaining, &offset);
|
remaining, &offset);
|
||||||
|
|
||||||
|
|||||||
@@ -229,6 +229,10 @@ struct socket_conn_s
|
|||||||
FAR struct devif_callback_s *list;
|
FAR struct devif_callback_s *list;
|
||||||
FAR struct devif_callback_s *list_tail;
|
FAR struct devif_callback_s *list_tail;
|
||||||
|
|
||||||
|
/* Definitions of 8-bit socket flags */
|
||||||
|
|
||||||
|
uint8_t s_flags; /* See _SF_* definitions */
|
||||||
|
|
||||||
/* Connection-specific content may follow */
|
/* Connection-specific content may follow */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -243,7 +247,6 @@ struct socket
|
|||||||
uint8_t s_domain; /* IP domain */
|
uint8_t s_domain; /* IP domain */
|
||||||
uint8_t s_type; /* Protocol type */
|
uint8_t s_type; /* Protocol type */
|
||||||
uint8_t s_proto; /* Socket Protocol */
|
uint8_t s_proto; /* Socket Protocol */
|
||||||
uint8_t s_flags; /* See _SF_* definitions */
|
|
||||||
|
|
||||||
/* Socket options */
|
/* Socket options */
|
||||||
|
|
||||||
|
|||||||
@@ -426,7 +426,7 @@ static ssize_t bluetooth_l2cap_send(FAR struct socket *psock,
|
|||||||
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
||||||
DEBUGASSERT(conn != NULL);
|
DEBUGASSERT(conn != NULL);
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
if (!_SS_ISCONNECTED(conn->bc_conn.s_flags))
|
||||||
{
|
{
|
||||||
ret = -ENOTCONN;
|
ret = -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -447,15 +447,18 @@ static int bluetooth_l2cap_bind(FAR struct socket *psock,
|
|||||||
* Only SOCK_RAW is supported
|
* Only SOCK_RAW is supported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (psock->s_type != SOCK_RAW)
|
if (psock == NULL || psock->s_conn == NULL ||
|
||||||
|
psock->s_type != SOCK_RAW)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Invalid socket type: %u\n", psock->s_type);
|
nerr("ERROR: Invalid socket type: %u\n", psock->s_type);
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
||||||
|
|
||||||
/* Verify that the socket is not already bound. */
|
/* Verify that the socket is not already bound. */
|
||||||
|
|
||||||
if (_SS_ISBOUND(psock->s_flags))
|
if (_SS_ISBOUND(conn->bc_conn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Already bound\n");
|
nerr("ERROR: Already bound\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -467,8 +470,6 @@ static int bluetooth_l2cap_bind(FAR struct socket *psock,
|
|||||||
* support some moral equivalent to INADDR_ANY?
|
* support some moral equivalent to INADDR_ANY?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
|
||||||
|
|
||||||
conn->bc_proto = psock->s_proto;
|
conn->bc_proto = psock->s_proto;
|
||||||
|
|
||||||
/* Find the device associated with the requested address */
|
/* Find the device associated with the requested address */
|
||||||
@@ -519,22 +520,23 @@ static int bluetooth_hci_bind(FAR struct socket *psock,
|
|||||||
* Only SOCK_RAW is supported
|
* Only SOCK_RAW is supported
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (psock->s_type != SOCK_RAW)
|
if (psock == NULL || psock->s_conn == NULL ||
|
||||||
|
psock->s_type != SOCK_RAW)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Invalid socket type: %u\n", psock->s_type);
|
nerr("ERROR: Invalid socket type: %u\n", psock->s_type);
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
||||||
|
|
||||||
/* Verify that the socket is not already bound. */
|
/* Verify that the socket is not already bound. */
|
||||||
|
|
||||||
if (_SS_ISBOUND(psock->s_flags))
|
if (_SS_ISBOUND(conn->bc_conn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Already bound\n");
|
nerr("ERROR: Already bound\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
|
|
||||||
|
|
||||||
conn->bc_proto = psock->s_proto;
|
conn->bc_proto = psock->s_proto;
|
||||||
conn->bc_channel = hciaddr->hci_channel;
|
conn->bc_channel = hciaddr->hci_channel;
|
||||||
conn->bc_ldev = hciaddr->hci_dev;
|
conn->bc_ldev = hciaddr->hci_dev;
|
||||||
|
|||||||
@@ -652,7 +652,7 @@ ssize_t can_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||||||
|
|
||||||
/* Handle non-blocking CAN sockets */
|
/* Handle non-blocking CAN sockets */
|
||||||
|
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags) || (flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
/* Return the number of bytes read from the read-ahead buffer if
|
/* Return the number of bytes read from the read-ahead buffer if
|
||||||
* something was received (already in 'ret'); EAGAIN if not.
|
* something was received (already in 'ret'); EAGAIN if not.
|
||||||
|
|||||||
@@ -410,7 +410,8 @@ ssize_t icmp_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||||||
ret = icmp_readahead(conn, buf, len,
|
ret = icmp_readahead(conn, buf, len,
|
||||||
(FAR struct sockaddr_in *)from, fromlen);
|
(FAR struct sockaddr_in *)from, fromlen);
|
||||||
}
|
}
|
||||||
else if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
else if (_SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
||||||
|
(flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
/* Handle non-blocking ICMP sockets */
|
/* Handle non-blocking ICMP sockets */
|
||||||
|
|
||||||
|
|||||||
@@ -417,7 +417,8 @@ ssize_t icmpv6_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||||||
ret = icmpv6_readahead(conn, buf, len,
|
ret = icmpv6_readahead(conn, buf, len,
|
||||||
(FAR struct sockaddr_in6 *)from, fromlen);
|
(FAR struct sockaddr_in6 *)from, fromlen);
|
||||||
}
|
}
|
||||||
else if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
else if (_SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
||||||
|
(flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
/* Handle non-blocking ICMP sockets */
|
/* Handle non-blocking ICMP sockets */
|
||||||
|
|
||||||
|
|||||||
@@ -582,7 +582,7 @@ static ssize_t ieee802154_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
{
|
{
|
||||||
/* send() may be used only if the socket has been connected. */
|
/* send() may be used only if the socket has been connected. */
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags) ||
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags) ||
|
||||||
conn->raddr.s_mode == IEEE802154_ADDRMODE_NONE)
|
conn->raddr.s_mode == IEEE802154_ADDRMODE_NONE)
|
||||||
{
|
{
|
||||||
ret = -ENOTCONN;
|
ret = -ENOTCONN;
|
||||||
|
|||||||
@@ -357,8 +357,8 @@ static int ieee802154_bind(FAR struct socket *psock,
|
|||||||
socklen_t addrlen)
|
socklen_t addrlen)
|
||||||
{
|
{
|
||||||
FAR const struct sockaddr_ieee802154_s *iaddr;
|
FAR const struct sockaddr_ieee802154_s *iaddr;
|
||||||
FAR struct radio_driver_s *radio;
|
|
||||||
FAR struct ieee802154_conn_s *conn;
|
FAR struct ieee802154_conn_s *conn;
|
||||||
|
FAR struct radio_driver_s *radio;
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL && addr != NULL);
|
DEBUGASSERT(psock != NULL && addr != NULL);
|
||||||
|
|
||||||
@@ -373,9 +373,11 @@ static int ieee802154_bind(FAR struct socket *psock,
|
|||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn = (FAR struct ieee802154_conn_s *)psock->s_conn;
|
||||||
|
|
||||||
/* Bind a PF_IEEE802154 socket to an network device. */
|
/* Bind a PF_IEEE802154 socket to an network device. */
|
||||||
|
|
||||||
if (psock->s_type != SOCK_DGRAM)
|
if (conn == NULL || psock->s_type != SOCK_DGRAM)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Invalid socket type: %u\n", psock->s_type);
|
nerr("ERROR: Invalid socket type: %u\n", psock->s_type);
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
@@ -383,7 +385,7 @@ static int ieee802154_bind(FAR struct socket *psock,
|
|||||||
|
|
||||||
/* Verify that the socket is not already bound. */
|
/* Verify that the socket is not already bound. */
|
||||||
|
|
||||||
if (_SS_ISBOUND(psock->s_flags))
|
if (_SS_ISBOUND(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Already bound\n");
|
nerr("ERROR: Already bound\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -403,8 +405,6 @@ static int ieee802154_bind(FAR struct socket *psock,
|
|||||||
return -EADDRNOTAVAIL;
|
return -EADDRNOTAVAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = (FAR struct ieee802154_conn_s *)psock->s_conn;
|
|
||||||
|
|
||||||
/* Find the device associated with the requested address */
|
/* Find the device associated with the requested address */
|
||||||
|
|
||||||
radio = ieee802154_find_device(conn, &iaddr->sa_addr);
|
radio = ieee802154_find_device(conn, &iaddr->sa_addr);
|
||||||
|
|||||||
@@ -716,9 +716,11 @@ static int inet_connect(FAR struct socket *psock,
|
|||||||
#if defined(CONFIG_NET_TCP) && defined(NET_TCP_HAVE_STACK)
|
#if defined(CONFIG_NET_TCP) && defined(NET_TCP_HAVE_STACK)
|
||||||
case SOCK_STREAM:
|
case SOCK_STREAM:
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
/* Verify that the socket is not already connected */
|
/* Verify that the socket is not already connected */
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->s_flags))
|
||||||
{
|
{
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
}
|
}
|
||||||
@@ -1069,6 +1071,9 @@ static int inet_poll(FAR struct socket *psock, FAR struct pollfd *fds,
|
|||||||
static ssize_t inet_send(FAR struct socket *psock, FAR const void *buf,
|
static ssize_t inet_send(FAR struct socket *psock, FAR const void *buf,
|
||||||
size_t len, int flags)
|
size_t len, int flags)
|
||||||
{
|
{
|
||||||
|
#ifdef NET_UDP_HAVE_STACK
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
#endif
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
switch (psock->s_type)
|
switch (psock->s_type)
|
||||||
@@ -1112,7 +1117,7 @@ static ssize_t inet_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
{
|
{
|
||||||
/* UDP/IP packet send */
|
/* UDP/IP packet send */
|
||||||
|
|
||||||
ret = _SS_ISCONNECTED(psock->s_flags) ?
|
ret = _SS_ISCONNECTED(conn->s_flags) ?
|
||||||
psock_udp_sendto(psock, buf, len, 0, NULL, 0) : -ENOTCONN;
|
psock_udp_sendto(psock, buf, len, 0, NULL, 0) : -ENOTCONN;
|
||||||
}
|
}
|
||||||
#endif /* NET_UDP_HAVE_STACK */
|
#endif /* NET_UDP_HAVE_STACK */
|
||||||
@@ -1120,7 +1125,7 @@ static ssize_t inet_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
#elif defined(NET_UDP_HAVE_STACK)
|
#elif defined(NET_UDP_HAVE_STACK)
|
||||||
/* Only UDP/IP packet send */
|
/* Only UDP/IP packet send */
|
||||||
|
|
||||||
ret = _SS_ISCONNECTED(psock->s_flags) ?
|
ret = _SS_ISCONNECTED(conn->s_flags) ?
|
||||||
psock_udp_sendto(psock, buf, len, 0, NULL, 0) : -ENOTCONN;
|
psock_udp_sendto(psock, buf, len, 0, NULL, 0) : -ENOTCONN;
|
||||||
#else
|
#else
|
||||||
ret = -ENOSYS;
|
ret = -ENOSYS;
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ int ipv4_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
{
|
{
|
||||||
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
|
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
|
||||||
FAR struct sockaddr_in *outaddr = (FAR struct sockaddr_in *)addr;
|
FAR struct sockaddr_in *outaddr = (FAR struct sockaddr_in *)addr;
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
in_addr_t ripaddr;
|
in_addr_t ripaddr;
|
||||||
|
|
||||||
/* Check if enough space has been provided for the full address */
|
/* Check if enough space has been provided for the full address */
|
||||||
@@ -87,7 +88,7 @@ int ipv4_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
|
|
||||||
/* Verify that the socket has been connected */
|
/* Verify that the socket has been connected */
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags) == 0)
|
if (_SS_ISCONNECTED(conn->s_flags) == 0)
|
||||||
{
|
{
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
int ipv6_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
|
int ipv6_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
|
||||||
FAR socklen_t *addrlen)
|
FAR socklen_t *addrlen)
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
FAR struct sockaddr_in6 *outaddr = (FAR struct sockaddr_in6 *)addr;
|
FAR struct sockaddr_in6 *outaddr = (FAR struct sockaddr_in6 *)addr;
|
||||||
net_ipv6addr_t *ripaddr;
|
net_ipv6addr_t *ripaddr;
|
||||||
|
|
||||||
@@ -86,7 +87,7 @@ int ipv6_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
|
|
||||||
/* Verify that the socket has been connected */
|
/* Verify that the socket has been connected */
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags) == 0)
|
if (_SS_ISCONNECTED(conn->s_flags) == 0)
|
||||||
{
|
{
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,8 +181,8 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
* block.
|
* block.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = local_open_server_tx(conn,
|
ret = local_open_server_tx(
|
||||||
_SS_ISNONBLOCK(psock->s_flags));
|
conn, _SS_ISNONBLOCK(conn->lc_conn.s_flags));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Failed to open write-only FIFOs for %s: %d\n",
|
nerr("ERROR: Failed to open write-only FIFOs for %s: %d\n",
|
||||||
@@ -201,8 +201,8 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
* for writing.
|
* for writing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = local_open_server_rx(conn,
|
ret = local_open_server_rx(
|
||||||
_SS_ISNONBLOCK(psock->s_flags));
|
conn, _SS_ISNONBLOCK(conn->lc_conn.s_flags));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Failed to open read-only FIFOs for %s: %d\n",
|
nerr("ERROR: Failed to open read-only FIFOs for %s: %d\n",
|
||||||
@@ -254,7 +254,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
|
|
||||||
/* Was the socket opened non-blocking? */
|
/* Was the socket opened non-blocking? */
|
||||||
|
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags))
|
if (_SS_ISNONBLOCK(server->lc_conn.s_flags))
|
||||||
{
|
{
|
||||||
/* Yes.. return EAGAIN */
|
/* Yes.. return EAGAIN */
|
||||||
|
|
||||||
|
|||||||
@@ -311,8 +311,8 @@ int psock_local_connect(FAR struct socket *psock,
|
|||||||
if (conn->lc_proto == SOCK_STREAM)
|
if (conn->lc_proto == SOCK_STREAM)
|
||||||
{
|
{
|
||||||
ret =
|
ret =
|
||||||
local_stream_connect(client, conn,
|
local_stream_connect(
|
||||||
_SS_ISNONBLOCK(psock->s_flags));
|
client, conn, _SS_ISNONBLOCK(conn->lc_conn.s_flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
net_unlock();
|
net_unlock();
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf,
|
|||||||
* eventually be reported as ENOTCONN.
|
* eventually be reported as ENOTCONN.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
psock->s_flags &= ~(_SF_CONNECTED | _SF_CLOSED);
|
conn->lc_conn.s_flags &= ~(_SF_CONNECTED | _SF_CLOSED);
|
||||||
conn->lc_state = LOCAL_STATE_DISCONNECTED;
|
conn->lc_state = LOCAL_STATE_DISCONNECTED;
|
||||||
|
|
||||||
/* Did we receive any data? */
|
/* Did we receive any data? */
|
||||||
|
|
||||||
@@ -330,7 +330,7 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
|
|
||||||
/* Open the receiving side of the transfer */
|
/* Open the receiving side of the transfer */
|
||||||
|
|
||||||
ret = local_open_receiver(conn, _SS_ISNONBLOCK(psock->s_flags) ||
|
ret = local_open_receiver(conn, _SS_ISNONBLOCK(conn->lc_conn.s_flags) ||
|
||||||
(flags & MSG_DONTWAIT) != 0);
|
(flags & MSG_DONTWAIT) != 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ static ssize_t local_sendto(FAR struct socket *psock,
|
|||||||
/* Open the sending side of the transfer */
|
/* Open the sending side of the transfer */
|
||||||
|
|
||||||
ret = local_open_sender(conn, unaddr->sun_path,
|
ret = local_open_sender(conn, unaddr->sun_path,
|
||||||
_SS_ISNONBLOCK(psock->s_flags) ||
|
_SS_ISNONBLOCK(conn->lc_conn.s_flags) ||
|
||||||
(flags & MSG_DONTWAIT) != 0);
|
(flags & MSG_DONTWAIT) != 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -515,9 +515,11 @@ static int local_connect(FAR struct socket *psock,
|
|||||||
#ifdef CONFIG_NET_LOCAL_STREAM
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
||||||
case SOCK_STREAM:
|
case SOCK_STREAM:
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
/* Verify that the socket is not already connected */
|
/* Verify that the socket is not already connected */
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->s_flags))
|
||||||
{
|
{
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
}
|
}
|
||||||
@@ -797,7 +799,7 @@ static int local_socketpair(FAR struct socket *psocks[2])
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
nonblock = _SS_ISNONBLOCK(psocks[0]->s_flags);
|
nonblock = _SS_ISNONBLOCK(conns[0]->lc_conn.s_flags);
|
||||||
|
|
||||||
/* Open the client-side write-only FIFO. */
|
/* Open the client-side write-only FIFO. */
|
||||||
|
|
||||||
|
|||||||
@@ -761,6 +761,7 @@ static ssize_t netlink_recvmsg(FAR struct socket *psock,
|
|||||||
FAR struct sockaddr *from = msg->msg_name;
|
FAR struct sockaddr *from = msg->msg_name;
|
||||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||||
FAR struct netlink_response_s *entry;
|
FAR struct netlink_response_s *entry;
|
||||||
|
FAR struct socket_conn_s *conn;
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
|
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && buf != NULL);
|
||||||
DEBUGASSERT(from == NULL ||
|
DEBUGASSERT(from == NULL ||
|
||||||
@@ -771,11 +772,13 @@ static ssize_t netlink_recvmsg(FAR struct socket *psock,
|
|||||||
entry = netlink_tryget_response(psock->s_conn);
|
entry = netlink_tryget_response(psock->s_conn);
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
{
|
{
|
||||||
|
conn = psock->s_conn;
|
||||||
|
|
||||||
/* No response is variable, but presumably, one is expected. Check
|
/* No response is variable, but presumably, one is expected. Check
|
||||||
* if the socket has been configured for non-blocking operation.
|
* if the socket has been configured for non-blocking operation.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
if (_SS_ISNONBLOCK(conn->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-16
@@ -80,6 +80,10 @@ begin_packed_struct struct rpmsg_socket_data_s
|
|||||||
|
|
||||||
struct rpmsg_socket_conn_s
|
struct rpmsg_socket_conn_s
|
||||||
{
|
{
|
||||||
|
/* Common prologue of all connection structures. */
|
||||||
|
|
||||||
|
struct socket_conn_s sconn;
|
||||||
|
|
||||||
struct rpmsg_endpoint ept;
|
struct rpmsg_endpoint ept;
|
||||||
|
|
||||||
struct sockaddr_rpmsg rpaddr;
|
struct sockaddr_rpmsg rpaddr;
|
||||||
@@ -305,7 +309,7 @@ static int rpmsg_socket_ept_cb(FAR struct rpmsg_endpoint *ept,
|
|||||||
|
|
||||||
if (conn->psock)
|
if (conn->psock)
|
||||||
{
|
{
|
||||||
conn->psock->s_flags |= _SF_CONNECTED;
|
conn->sconn.s_flags |= _SF_CONNECTED;
|
||||||
_SO_SETERRNO(conn->psock, OK);
|
_SO_SETERRNO(conn->psock, OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -649,7 +653,7 @@ static int rpmsg_socket_listen(FAR struct socket *psock, int backlog)
|
|||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_SS_ISBOUND(psock->s_flags) || backlog <= 0)
|
if (!_SS_ISBOUND(server->sconn.s_flags) || backlog <= 0)
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -683,7 +687,7 @@ static int rpmsg_socket_connect_internal(FAR struct socket *psock)
|
|||||||
|
|
||||||
if (conn->sendsize == 0)
|
if (conn->sendsize == 0)
|
||||||
{
|
{
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags))
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
return -EINPROGRESS;
|
return -EINPROGRESS;
|
||||||
}
|
}
|
||||||
@@ -710,7 +714,7 @@ static int rpmsg_socket_connect(FAR struct socket *psock,
|
|||||||
FAR struct rpmsg_socket_conn_s *conn = psock->s_conn;
|
FAR struct rpmsg_socket_conn_s *conn = psock->s_conn;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
}
|
}
|
||||||
@@ -738,7 +742,7 @@ static int rpmsg_socket_accept(FAR struct socket *psock,
|
|||||||
return -ECONNRESET;
|
return -ECONNRESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_SS_ISLISTENING(psock->s_flags))
|
if (!_SS_ISLISTENING(server->sconn.s_flags))
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -782,7 +786,7 @@ static int rpmsg_socket_accept(FAR struct socket *psock,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags))
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
ret = -EAGAIN;
|
ret = -EAGAIN;
|
||||||
break;
|
break;
|
||||||
@@ -839,7 +843,7 @@ static int rpmsg_socket_poll(FAR struct socket *psock,
|
|||||||
|
|
||||||
/* Immediately notify on any of the requested events */
|
/* Immediately notify on any of the requested events */
|
||||||
|
|
||||||
if (_SS_ISLISTENING(psock->s_flags))
|
if (_SS_ISLISTENING(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
if (conn->backlog == -1)
|
if (conn->backlog == -1)
|
||||||
{
|
{
|
||||||
@@ -852,7 +856,7 @@ static int rpmsg_socket_poll(FAR struct socket *psock,
|
|||||||
eventset |= (fds->events & POLLIN);
|
eventset |= (fds->events & POLLIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_SS_ISCONNECTED(psock->s_flags))
|
else if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
if (!conn->ept.rdev)
|
if (!conn->ept.rdev)
|
||||||
{
|
{
|
||||||
@@ -878,8 +882,8 @@ static int rpmsg_socket_poll(FAR struct socket *psock,
|
|||||||
|
|
||||||
rpmsg_socket_unlock(&conn->recvlock);
|
rpmsg_socket_unlock(&conn->recvlock);
|
||||||
}
|
}
|
||||||
else if (!_SS_ISCONNECTED(psock->s_flags) &&
|
else if (!_SS_ISCONNECTED(conn->sconn.s_flags) &&
|
||||||
_SS_ISNONBLOCK(psock->s_flags))
|
_SS_ISNONBLOCK(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
ret = OK;
|
ret = OK;
|
||||||
}
|
}
|
||||||
@@ -1121,7 +1125,7 @@ static ssize_t rpmsg_socket_sendmsg(FAR struct socket *psock,
|
|||||||
bool nonblock;
|
bool nonblock;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
if (to == NULL)
|
if (to == NULL)
|
||||||
{
|
{
|
||||||
@@ -1142,7 +1146,8 @@ static ssize_t rpmsg_socket_sendmsg(FAR struct socket *psock,
|
|||||||
return -ECONNRESET;
|
return -ECONNRESET;
|
||||||
}
|
}
|
||||||
|
|
||||||
nonblock = _SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0;
|
nonblock = _SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
||||||
|
(flags & MSG_DONTWAIT) != 0;
|
||||||
|
|
||||||
if (psock->s_type == SOCK_STREAM)
|
if (psock->s_type == SOCK_STREAM)
|
||||||
{
|
{
|
||||||
@@ -1164,8 +1169,8 @@ static ssize_t rpmsg_socket_recvmsg(FAR struct socket *psock,
|
|||||||
FAR struct rpmsg_socket_conn_s *conn = psock->s_conn;
|
FAR struct rpmsg_socket_conn_s *conn = psock->s_conn;
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
if (psock->s_type != SOCK_STREAM && _SS_ISBOUND(psock->s_flags)
|
if (psock->s_type != SOCK_STREAM && _SS_ISBOUND(conn->sconn.s_flags)
|
||||||
&& !_SS_ISCONNECTED(psock->s_flags))
|
&& !_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
ret = rpmsg_socket_connect_internal(psock);
|
ret = rpmsg_socket_connect_internal(psock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@@ -1174,7 +1179,7 @@ static ssize_t rpmsg_socket_recvmsg(FAR struct socket *psock,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
return -EISCONN;
|
return -EISCONN;
|
||||||
}
|
}
|
||||||
@@ -1216,7 +1221,7 @@ static ssize_t rpmsg_socket_recvmsg(FAR struct socket *psock,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags) || (flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
ret = -EAGAIN;
|
ret = -EAGAIN;
|
||||||
goto out;
|
goto out;
|
||||||
|
|||||||
@@ -401,11 +401,11 @@ static uint16_t tcp_send_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL);
|
DEBUGASSERT(psock != NULL);
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Report the disconnection event to all socket clones */
|
/* Report the disconnection event to all socket clones */
|
||||||
|
|
||||||
tcp_lost_connection(psock, sinfo->s_cb, flags);
|
tcp_lost_connection(conn, sinfo->s_cb, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Report not connected to the sender */
|
/* Report not connected to the sender */
|
||||||
@@ -730,18 +730,18 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
return (ssize_t)-EBADF;
|
return (ssize_t)-EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the underlying TCP connection structure */
|
||||||
|
|
||||||
|
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
||||||
|
|
||||||
/* Make sure that this is a connected TCP socket */
|
/* Make sure that this is a connected TCP socket */
|
||||||
|
|
||||||
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
|
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Not connected\n");
|
nerr("ERROR: Not connected\n");
|
||||||
return (ssize_t)-ENOTCONN;
|
return (ssize_t)-ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the underlying TCP connection structure */
|
|
||||||
|
|
||||||
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_IPv4
|
#ifdef CONFIG_NET_IPv4
|
||||||
/* Ignore if not IPv6 domain */
|
/* Ignore if not IPv6 domain */
|
||||||
|
|
||||||
|
|||||||
@@ -293,8 +293,8 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ret = sixlowpan_send(dev,
|
ret = sixlowpan_send(dev,
|
||||||
&conn->list,
|
&conn->sconn.list,
|
||||||
&conn->list_tail,
|
&conn->sconn.list_tail,
|
||||||
(FAR const struct ipv6_hdr_s *)&ipv6udp,
|
(FAR const struct ipv6_hdr_s *)&ipv6udp,
|
||||||
buf, buflen, &destmac,
|
buf, buflen, &destmac,
|
||||||
_SO_TIMEOUT(psock->s_sndtimeo));
|
_SO_TIMEOUT(psock->s_sndtimeo));
|
||||||
@@ -349,19 +349,19 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
return (ssize_t)-EBADF;
|
return (ssize_t)-EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the underlying UDP "connection" structure */
|
||||||
|
|
||||||
|
conn = (FAR struct udp_conn_s *)psock->s_conn;
|
||||||
|
|
||||||
/* Was the UDP socket connected via connect()? */
|
/* Was the UDP socket connected via connect()? */
|
||||||
|
|
||||||
if (psock->s_type != SOCK_DGRAM || !_SS_ISCONNECTED(psock->s_flags))
|
if (psock->s_type != SOCK_DGRAM || !_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* No, then it is not legal to call send() with this socket. */
|
/* No, then it is not legal to call send() with this socket. */
|
||||||
|
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the underlying UDP "connection" structure */
|
|
||||||
|
|
||||||
conn = (FAR struct udp_conn_s *)psock->s_conn;
|
|
||||||
|
|
||||||
/* Ignore if not IPv6 domain */
|
/* Ignore if not IPv6 domain */
|
||||||
|
|
||||||
if (conn->domain != PF_INET6)
|
if (conn->domain != PF_INET6)
|
||||||
|
|||||||
+12
-11
@@ -113,6 +113,7 @@
|
|||||||
int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
||||||
FAR socklen_t *addrlen, FAR struct socket *newsock)
|
FAR socklen_t *addrlen, FAR struct socket *newsock)
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && newsock != NULL);
|
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && newsock != NULL);
|
||||||
@@ -127,7 +128,8 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
|
|
||||||
/* Is the socket listening for a connection? */
|
/* Is the socket listening for a connection? */
|
||||||
|
|
||||||
if (!_SS_ISLISTENING(psock->s_flags))
|
conn = psock->s_conn;
|
||||||
|
if (!_SS_ISLISTENING(conn->s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Socket is not listening for a connection.\n");
|
nerr("ERROR: Socket is not listening for a connection.\n");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
@@ -139,20 +141,19 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
|
|
||||||
net_lock();
|
net_lock();
|
||||||
ret = psock->s_sockif->si_accept(psock, addr, addrlen, newsock);
|
ret = psock->s_sockif->si_accept(psock, addr, addrlen, newsock);
|
||||||
if (ret < 0)
|
if (ret >= 0)
|
||||||
|
{
|
||||||
|
/* Mark the new socket as connected. */
|
||||||
|
|
||||||
|
conn = newsock->s_conn;
|
||||||
|
conn->s_flags |= _SF_CONNECTED;
|
||||||
|
conn->s_flags &= ~_SF_CLOSED;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
nerr("ERROR: si_accept failed: %d\n", ret);
|
nerr("ERROR: si_accept failed: %d\n", ret);
|
||||||
goto errout_with_lock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark the new socket as connected. */
|
|
||||||
|
|
||||||
newsock->s_flags |= _SF_CONNECTED;
|
|
||||||
newsock->s_flags &= ~_SF_CLOSED;
|
|
||||||
|
|
||||||
ret = OK;
|
|
||||||
|
|
||||||
errout_with_lock:
|
|
||||||
net_unlock();
|
net_unlock();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -92,16 +92,16 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
|
|||||||
|
|
||||||
/* Was the bind successful */
|
/* Was the bind successful */
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
return ret;
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
|
/* Mark the socket bound */
|
||||||
|
|
||||||
|
conn->s_flags |= _SF_BOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mark the socket bound */
|
return ret;
|
||||||
|
|
||||||
psock->s_flags |= _SF_BOUND;
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
+12
-12
@@ -137,21 +137,21 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
|
|||||||
DEBUGASSERT(psock->s_sockif != NULL &&
|
DEBUGASSERT(psock->s_sockif != NULL &&
|
||||||
psock->s_sockif->si_connect != NULL);
|
psock->s_sockif->si_connect != NULL);
|
||||||
ret = psock->s_sockif->si_connect(psock, addr, addrlen);
|
ret = psock->s_sockif->si_connect(psock, addr, addrlen);
|
||||||
if (ret < 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
return ret;
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
|
if (addr != NULL)
|
||||||
|
{
|
||||||
|
conn->s_flags |= _SF_CONNECTED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
conn->s_flags &= ~_SF_CONNECTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addr != NULL)
|
return ret;
|
||||||
{
|
|
||||||
psock->s_flags |= _SF_CONNECTED;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
psock->s_flags &= ~_SF_CONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
|||||||
FAR void *value,
|
FAR void *value,
|
||||||
FAR socklen_t *value_len)
|
FAR socklen_t *value_len)
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
/* Verify that the socket option if valid (but might not be supported ) */
|
/* Verify that the socket option if valid (but might not be supported ) */
|
||||||
|
|
||||||
if (!_SO_GETVALID(option) || !value || !value_len)
|
if (!_SO_GETVALID(option) || !value || !value_len)
|
||||||
@@ -134,11 +136,11 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
|||||||
{
|
{
|
||||||
if (option == SO_TYPE)
|
if (option == SO_TYPE)
|
||||||
{
|
{
|
||||||
FAR struct usrsock_conn_s *conn = psock->s_conn;
|
FAR struct usrsock_conn_s *uconn = psock->s_conn;
|
||||||
|
|
||||||
/* Return the actual socket type */
|
/* Return the actual socket type */
|
||||||
|
|
||||||
*(FAR int *)value = conn->type;
|
*(FAR int *)value = uconn->type;
|
||||||
*value_len = sizeof(int);
|
*value_len = sizeof(int);
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
@@ -156,7 +158,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(FAR int *)value = _SS_ISLISTENING(psock->s_flags);
|
*(FAR int *)value = _SS_ISLISTENING(conn->s_flags);
|
||||||
*value_len = sizeof(int);
|
*value_len = sizeof(int);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -84,14 +84,17 @@ int psock_listen(FAR struct socket *psock, int backlog)
|
|||||||
|
|
||||||
DEBUGASSERT(psock->s_sockif != NULL && psock->s_sockif->si_listen != NULL);
|
DEBUGASSERT(psock->s_sockif != NULL && psock->s_sockif->si_listen != NULL);
|
||||||
ret = psock->s_sockif->si_listen(psock, backlog);
|
ret = psock->s_sockif->si_listen(psock, backlog);
|
||||||
if (ret < 0)
|
if (ret >= 0)
|
||||||
|
{
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
conn->s_flags |= _SF_LISTENING;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
nerr("ERROR: si_listen failed: %d\n", ret);
|
nerr("ERROR: si_listen failed: %d\n", ret);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psock->s_flags |= _SF_LISTENING;
|
return ret;
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -81,6 +81,8 @@ int psock_close(FAR struct socket *psock)
|
|||||||
|
|
||||||
if (psock->s_conn != NULL)
|
if (psock->s_conn != NULL)
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
/* Assume that the socket close operation will be successful. Save
|
/* Assume that the socket close operation will be successful. Save
|
||||||
* the current flags and mark the socket uninitialized. This avoids
|
* the current flags and mark the socket uninitialized. This avoids
|
||||||
* race conditions in the SMP case. We save the flags as a type
|
* race conditions in the SMP case. We save the flags as a type
|
||||||
@@ -88,9 +90,9 @@ int psock_close(FAR struct socket *psock)
|
|||||||
* (currently uint8_t).
|
* (currently uint8_t).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned int saveflags = psock->s_flags;
|
unsigned int saveflags = conn->s_flags;
|
||||||
|
|
||||||
psock->s_flags &= ~_SF_INITD;
|
conn->s_flags &= ~_SF_INITD;
|
||||||
|
|
||||||
/* Let the address family's close() method handle the operation */
|
/* Let the address family's close() method handle the operation */
|
||||||
|
|
||||||
@@ -105,7 +107,7 @@ int psock_close(FAR struct socket *psock)
|
|||||||
{
|
{
|
||||||
/* No.. restore the socket flags */
|
/* No.. restore the socket flags */
|
||||||
|
|
||||||
psock->s_flags = saveflags;
|
conn->s_flags = saveflags;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2)
|
|||||||
psock2->s_domain = psock1->s_domain; /* IP domain: PF_INET, PF_INET6, or PF_PACKET */
|
psock2->s_domain = psock1->s_domain; /* IP domain: PF_INET, PF_INET6, or PF_PACKET */
|
||||||
psock2->s_type = psock1->s_type; /* Protocol type: Only SOCK_STREAM or SOCK_DGRAM */
|
psock2->s_type = psock1->s_type; /* Protocol type: Only SOCK_STREAM or SOCK_DGRAM */
|
||||||
psock2->s_sockif = psock1->s_sockif; /* Socket interface */
|
psock2->s_sockif = psock1->s_sockif; /* Socket interface */
|
||||||
psock2->s_flags = psock1->s_flags; /* See _SF_* definitions */
|
|
||||||
#ifdef CONFIG_NET_SOCKOPTS
|
#ifdef CONFIG_NET_SOCKOPTS
|
||||||
psock2->s_options = psock1->s_options; /* Selected socket options */
|
psock2->s_options = psock1->s_options; /* Selected socket options */
|
||||||
psock2->s_rcvtimeo = psock1->s_rcvtimeo; /* Receive timeout value (in deciseconds) */
|
psock2->s_rcvtimeo = psock1->s_rcvtimeo; /* Receive timeout value (in deciseconds) */
|
||||||
|
|||||||
+10
-6
@@ -58,6 +58,7 @@
|
|||||||
|
|
||||||
int psock_fstat(FAR struct socket *psock, FAR struct stat *buf)
|
int psock_fstat(FAR struct socket *psock, FAR struct stat *buf)
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
if (psock == NULL)
|
if (psock == NULL)
|
||||||
@@ -82,7 +83,9 @@ int psock_fstat(FAR struct socket *psock, FAR struct stat *buf)
|
|||||||
* devices, each supporting a different MSS.
|
* devices, each supporting a different MSS.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (psock->s_conn == NULL || !_SS_ISCONNECTED(psock->s_flags))
|
conn = psock->s_conn;
|
||||||
|
|
||||||
|
if (conn == NULL || !_SS_ISCONNECTED(conn->s_flags))
|
||||||
{
|
{
|
||||||
/* Not connected.. Return an optimal blocksize of zero (or, perhaps,
|
/* Not connected.. Return an optimal blocksize of zero (or, perhaps,
|
||||||
* even an error?)
|
* even an error?)
|
||||||
@@ -105,14 +108,14 @@ int psock_fstat(FAR struct socket *psock, FAR struct stat *buf)
|
|||||||
#if defined(NET_TCP_HAVE_STACK)
|
#if defined(NET_TCP_HAVE_STACK)
|
||||||
case SOCK_STREAM:
|
case SOCK_STREAM:
|
||||||
{
|
{
|
||||||
FAR struct tcp_conn_s *conn =
|
FAR struct tcp_conn_s *tcp_conn =
|
||||||
(FAR struct tcp_conn_s *)psock->s_conn;
|
(FAR struct tcp_conn_s *)psock->s_conn;
|
||||||
|
|
||||||
/* For TCP, the MSS is a dynamic value that maintained in the
|
/* For TCP, the MSS is a dynamic value that maintained in the
|
||||||
* connection structure.
|
* connection structure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
buf->st_blksize = conn->mss;
|
buf->st_blksize = tcp_conn->mss;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
@@ -120,7 +123,7 @@ int psock_fstat(FAR struct socket *psock, FAR struct stat *buf)
|
|||||||
#if defined(NET_UDP_HAVE_STACK)
|
#if defined(NET_UDP_HAVE_STACK)
|
||||||
case SOCK_DGRAM:
|
case SOCK_DGRAM:
|
||||||
{
|
{
|
||||||
FAR struct udp_conn_s *conn =
|
FAR struct udp_conn_s *udp_conn =
|
||||||
(FAR struct udp_conn_s *)psock->s_conn;
|
(FAR struct udp_conn_s *)psock->s_conn;
|
||||||
FAR struct net_driver_s *dev;
|
FAR struct net_driver_s *dev;
|
||||||
uint16_t iplen;
|
uint16_t iplen;
|
||||||
@@ -133,7 +136,7 @@ int psock_fstat(FAR struct socket *psock, FAR struct stat *buf)
|
|||||||
* order to get the MTU and LL_HDRLEN:
|
* order to get the MTU and LL_HDRLEN:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
dev = udp_find_raddr_device(conn, NULL);
|
dev = udp_find_raddr_device(udp_conn, NULL);
|
||||||
if (dev == NULL)
|
if (dev == NULL)
|
||||||
{
|
{
|
||||||
/* This should never happen except perhaps in some rare race
|
/* This should never happen except perhaps in some rare race
|
||||||
@@ -150,7 +153,8 @@ int psock_fstat(FAR struct socket *psock, FAR struct stat *buf)
|
|||||||
/* We need the length of the IP header */
|
/* We need the length of the IP header */
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
iplen = (conn->domain == PF_INET) ? IPv4_HDRLEN : IPv6_HDRLEN;
|
iplen = (udp_conn->domain == PF_INET) ? IPv4_HDRLEN :
|
||||||
|
IPv6_HDRLEN;
|
||||||
#elif defined(CONFIG_NET_IPv4)
|
#elif defined(CONFIG_NET_IPv4)
|
||||||
iplen = IPv4_HDRLEN;
|
iplen = IPv4_HDRLEN;
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
|
|
||||||
int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap)
|
int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap)
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn;
|
||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
ninfo("sockfd=%p cmd=%d\n", psock, cmd);
|
ninfo("sockfd=%p cmd=%d\n", psock, cmd);
|
||||||
@@ -71,6 +72,8 @@ int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap)
|
|||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn = psock->s_conn;
|
||||||
|
|
||||||
/* Interrupts must be disabled in order to perform operations on socket
|
/* Interrupts must be disabled in order to perform operations on socket
|
||||||
* structures
|
* structures
|
||||||
*/
|
*/
|
||||||
@@ -104,7 +107,7 @@ int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap)
|
|||||||
sockcaps = psock->s_sockif->si_sockcaps(psock);
|
sockcaps = psock->s_sockif->si_sockcaps(psock);
|
||||||
|
|
||||||
if ((sockcaps & SOCKCAP_NONBLOCKING) != 0 &&
|
if ((sockcaps & SOCKCAP_NONBLOCKING) != 0 &&
|
||||||
_SS_ISNONBLOCK(psock->s_flags))
|
_SS_ISNONBLOCK(conn->s_flags))
|
||||||
{
|
{
|
||||||
ret |= O_NONBLOCK;
|
ret |= O_NONBLOCK;
|
||||||
}
|
}
|
||||||
@@ -138,11 +141,11 @@ int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap)
|
|||||||
{
|
{
|
||||||
if ((mode & O_NONBLOCK) != 0)
|
if ((mode & O_NONBLOCK) != 0)
|
||||||
{
|
{
|
||||||
psock->s_flags |= _SF_NONBLOCK;
|
conn->s_flags |= _SF_NONBLOCK;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
psock->s_flags &= ~_SF_NONBLOCK;
|
conn->s_flags &= ~_SF_NONBLOCK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = OK;
|
ret = OK;
|
||||||
|
|||||||
+19
-16
@@ -87,14 +87,7 @@ int psock_socket(int domain, int type, int protocol,
|
|||||||
psock->s_domain = domain;
|
psock->s_domain = domain;
|
||||||
psock->s_proto = protocol;
|
psock->s_proto = protocol;
|
||||||
psock->s_conn = NULL;
|
psock->s_conn = NULL;
|
||||||
|
psock->s_type = type & SOCK_TYPE_MASK;
|
||||||
if (type & SOCK_NONBLOCK)
|
|
||||||
{
|
|
||||||
psock->s_flags |= _SF_NONBLOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
type &= SOCK_TYPE_MASK;
|
|
||||||
psock->s_type = type;
|
|
||||||
|
|
||||||
#ifdef CONFIG_NET_USRSOCK
|
#ifdef CONFIG_NET_USRSOCK
|
||||||
if (domain != PF_LOCAL && domain != PF_UNSPEC && domain != PF_RPMSG)
|
if (domain != PF_LOCAL && domain != PF_UNSPEC && domain != PF_RPMSG)
|
||||||
@@ -111,7 +104,7 @@ int psock_socket(int domain, int type, int protocol,
|
|||||||
{
|
{
|
||||||
/* Get the socket interface */
|
/* Get the socket interface */
|
||||||
|
|
||||||
sockif = net_sockif(domain, type, protocol);
|
sockif = net_sockif(domain, psock->s_type, protocol);
|
||||||
if (sockif == NULL)
|
if (sockif == NULL)
|
||||||
{
|
{
|
||||||
nerr("ERROR: socket address family unsupported: %d\n", domain);
|
nerr("ERROR: socket address family unsupported: %d\n", domain);
|
||||||
@@ -126,16 +119,26 @@ int psock_socket(int domain, int type, int protocol,
|
|||||||
psock->s_sockif = sockif;
|
psock->s_sockif = sockif;
|
||||||
|
|
||||||
ret = sockif->si_setup(psock, protocol);
|
ret = sockif->si_setup(psock, protocol);
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
nerr("ERROR: socket si_setup() failed: %d\n", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The socket has been successfully initialized */
|
if (ret >= 0)
|
||||||
|
{
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
|
if (type & SOCK_NONBLOCK)
|
||||||
|
{
|
||||||
|
conn->s_flags |= _SF_NONBLOCK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The socket has been successfully initialized */
|
||||||
|
|
||||||
|
conn->s_flags |= _SF_INITD;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nerr("ERROR: socket si_setup() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
psock->s_flags |= _SF_INITD;
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ int psock_tcp_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
* return EAGAIN if there is no pending connection in the backlog.
|
* return EAGAIN if there is no pending connection in the backlog.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
else if (_SS_ISNONBLOCK(psock->s_flags))
|
else if (_SS_ISNONBLOCK(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-8
@@ -219,15 +219,18 @@ static uint16_t psock_connect_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
else if ((flags & TCP_CONNECTED) != 0)
|
else if ((flags & TCP_CONNECTED) != 0)
|
||||||
{
|
{
|
||||||
FAR struct socket *psock = pstate->tc_psock;
|
FAR struct socket *psock = pstate->tc_psock;
|
||||||
|
FAR struct socket_conn_s *conn;
|
||||||
DEBUGASSERT(psock);
|
DEBUGASSERT(psock);
|
||||||
|
|
||||||
|
conn = psock->s_conn;
|
||||||
|
|
||||||
/* Mark the connection bound and connected. NOTE this is
|
/* Mark the connection bound and connected. NOTE this is
|
||||||
* is done here (vs. later) in order to avoid any race condition
|
* is done here (vs. later) in order to avoid any race condition
|
||||||
* in the socket state. It is known to connected here and now,
|
* in the socket state. It is known to connected here and now,
|
||||||
* but not necessarily at any time later.
|
* but not necessarily at any time later.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
psock->s_flags |= (_SF_BOUND | _SF_CONNECTED);
|
conn->s_flags |= (_SF_BOUND | _SF_CONNECTED);
|
||||||
|
|
||||||
/* Indicate that the socket is no longer connected */
|
/* Indicate that the socket is no longer connected */
|
||||||
|
|
||||||
@@ -293,8 +296,9 @@ static uint16_t psock_connect_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
int psock_tcp_connect(FAR struct socket *psock,
|
int psock_tcp_connect(FAR struct socket *psock,
|
||||||
FAR const struct sockaddr *addr)
|
FAR const struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
struct tcp_connect_s state;
|
FAR struct tcp_conn_s *conn;
|
||||||
int ret = OK;
|
struct tcp_connect_s state;
|
||||||
|
int ret = OK;
|
||||||
|
|
||||||
/* Interrupts must be disabled through all of the following because
|
/* Interrupts must be disabled through all of the following because
|
||||||
* we cannot allow the network callback to occur until we are completely
|
* we cannot allow the network callback to occur until we are completely
|
||||||
@@ -303,9 +307,11 @@ int psock_tcp_connect(FAR struct socket *psock,
|
|||||||
|
|
||||||
net_lock();
|
net_lock();
|
||||||
|
|
||||||
|
conn = psock->s_conn;
|
||||||
|
|
||||||
/* Get the connection reference from the socket */
|
/* Get the connection reference from the socket */
|
||||||
|
|
||||||
if (!psock->s_conn) /* Should always be non-NULL */
|
if (conn == NULL) /* Should always be non-NULL */
|
||||||
{
|
{
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -313,20 +319,20 @@ int psock_tcp_connect(FAR struct socket *psock,
|
|||||||
{
|
{
|
||||||
/* Perform the TCP connection operation */
|
/* Perform the TCP connection operation */
|
||||||
|
|
||||||
ret = tcp_connect(psock->s_conn, addr);
|
ret = tcp_connect(conn, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
{
|
{
|
||||||
/* Notify the device driver that new connection is available. */
|
/* Notify the device driver that new connection is available. */
|
||||||
|
|
||||||
netdev_txnotify_dev(((FAR struct tcp_conn_s *)psock->s_conn)->dev);
|
netdev_txnotify_dev(conn->dev);
|
||||||
|
|
||||||
/* Non-blocking connection ? set the socket error
|
/* Non-blocking connection ? set the socket error
|
||||||
* and start the monitor
|
* and start the monitor
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags))
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
ret = -EINPROGRESS;
|
ret = -EINPROGRESS;
|
||||||
}
|
}
|
||||||
@@ -385,7 +391,7 @@ int psock_tcp_connect(FAR struct socket *psock,
|
|||||||
* happen in this context, but just in case...
|
* happen in this context, but just in case...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
tcp_stop_monitor(psock->s_conn, TCP_ABORT);
|
tcp_stop_monitor(conn, TCP_ABORT);
|
||||||
ret = ret2;
|
ret = ret2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-7
@@ -69,6 +69,8 @@ static uint16_t tcp_monitor_event(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
static void tcp_close_connection(FAR struct socket *psock, uint16_t flags)
|
static void tcp_close_connection(FAR struct socket *psock, uint16_t flags)
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
/* These loss-of-connection events may be reported:
|
/* These loss-of-connection events may be reported:
|
||||||
*
|
*
|
||||||
* TCP_CLOSE: The remote host has closed the connection
|
* TCP_CLOSE: The remote host has closed the connection
|
||||||
@@ -92,8 +94,8 @@ static void tcp_close_connection(FAR struct socket *psock, uint16_t flags)
|
|||||||
* not handle as an error but as an "end-of-file"
|
* not handle as an error but as an "end-of-file"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
psock->s_flags &= ~_SF_CONNECTED;
|
conn->s_flags &= ~_SF_CONNECTED;
|
||||||
psock->s_flags |= _SF_CLOSED;
|
conn->s_flags |= _SF_CLOSED;
|
||||||
}
|
}
|
||||||
else if ((flags & (TCP_ABORT | TCP_TIMEDOUT | NETDEV_DOWN)) != 0)
|
else if ((flags & (TCP_ABORT | TCP_TIMEDOUT | NETDEV_DOWN)) != 0)
|
||||||
{
|
{
|
||||||
@@ -101,7 +103,7 @@ static void tcp_close_connection(FAR struct socket *psock, uint16_t flags)
|
|||||||
* (eventually) be reported as an ENOTCONN error.
|
* (eventually) be reported as an ENOTCONN error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
psock->s_flags &= ~(_SF_CONNECTED | _SF_CLOSED);
|
conn->s_flags &= ~(_SF_CONNECTED | _SF_CLOSED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,10 +131,11 @@ static uint16_t tcp_monitor_event(FAR struct net_driver_s *dev,
|
|||||||
uint16_t flags)
|
uint16_t flags)
|
||||||
{
|
{
|
||||||
FAR struct socket *psock = (FAR struct socket *)pvpriv;
|
FAR struct socket *psock = (FAR struct socket *)pvpriv;
|
||||||
|
FAR struct socket_conn_s *conn = psock->s_conn;
|
||||||
|
|
||||||
if (psock != NULL)
|
if (psock != NULL)
|
||||||
{
|
{
|
||||||
ninfo("flags: %04x s_flags: %02x\n", flags, psock->s_flags);
|
ninfo("flags: %04x s_flags: %02x\n", flags, conn->s_flags);
|
||||||
|
|
||||||
/* TCP_DISCONN_EVENTS: TCP_CLOSE, TCP_ABORT, TCP_TIMEDOUT, or
|
/* TCP_DISCONN_EVENTS: TCP_CLOSE, TCP_ABORT, TCP_TIMEDOUT, or
|
||||||
* NETDEV_DOWN. All loss-of-connection events.
|
* NETDEV_DOWN. All loss-of-connection events.
|
||||||
@@ -170,8 +173,8 @@ static uint16_t tcp_monitor_event(FAR struct net_driver_s *dev,
|
|||||||
|
|
||||||
/* Indicate that the socket is now connected */
|
/* Indicate that the socket is now connected */
|
||||||
|
|
||||||
psock->s_flags |= (_SF_BOUND | _SF_CONNECTED);
|
sconn->s_flags |= (_SF_BOUND | _SF_CONNECTED);
|
||||||
psock->s_flags &= ~_SF_CLOSED;
|
sconn->s_flags &= ~_SF_CLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +262,7 @@ int tcp_start_monitor(FAR struct socket *psock)
|
|||||||
/* Non-blocking connection ? */
|
/* Non-blocking connection ? */
|
||||||
|
|
||||||
nonblock_conn = (conn->tcpstateflags == TCP_SYN_SENT &&
|
nonblock_conn = (conn->tcpstateflags == TCP_SYN_SENT &&
|
||||||
_SS_ISNONBLOCK(psock->s_flags));
|
_SS_ISNONBLOCK(conn->sconn.s_flags));
|
||||||
|
|
||||||
/* Check if the connection has already been closed before any callbacks
|
/* Check if the connection has already been closed before any callbacks
|
||||||
* have been registered. (Maybe the connection is lost before accept has
|
* have been registered. (Maybe the connection is lost before accept has
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ int tcp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds)
|
|||||||
/* Non-blocking connection ? */
|
/* Non-blocking connection ? */
|
||||||
|
|
||||||
nonblock_conn = (conn->tcpstateflags == TCP_SYN_SENT &&
|
nonblock_conn = (conn->tcpstateflags == TCP_SYN_SENT &&
|
||||||
_SS_ISNONBLOCK(psock->s_flags));
|
_SS_ISNONBLOCK(conn->sconn.s_flags));
|
||||||
|
|
||||||
/* Find a container to hold the poll information */
|
/* Find a container to hold the poll information */
|
||||||
|
|
||||||
@@ -331,8 +331,8 @@ int tcp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds)
|
|||||||
* Action: Return with POLLHUP|POLLERR events
|
* Action: Return with POLLHUP|POLLERR events
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!nonblock_conn && !_SS_ISCONNECTED(psock->s_flags) &&
|
if (!nonblock_conn && !_SS_ISCONNECTED(conn->sconn.s_flags) &&
|
||||||
!_SS_ISLISTENING(psock->s_flags))
|
!_SS_ISLISTENING(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* We were previously connected but lost the connection either due
|
/* We were previously connected but lost the connection either due
|
||||||
* to a graceful shutdown by the remote peer or because of some
|
* to a graceful shutdown by the remote peer or because of some
|
||||||
@@ -341,7 +341,8 @@ int tcp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds)
|
|||||||
|
|
||||||
fds->revents |= (POLLERR | POLLHUP);
|
fds->revents |= (POLLERR | POLLHUP);
|
||||||
}
|
}
|
||||||
else if (_SS_ISCONNECTED(psock->s_flags) && psock_tcp_cansend(psock) >= 0)
|
else if (_SS_ISCONNECTED(conn->sconn.s_flags) &&
|
||||||
|
psock_tcp_cansend(psock) >= 0)
|
||||||
{
|
{
|
||||||
fds->revents |= (POLLWRNORM & fds->events);
|
fds->revents |= (POLLWRNORM & fds->events);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -462,6 +462,7 @@ static uint16_t tcp_recvhandler(FAR struct net_driver_s *dev,
|
|||||||
else if ((flags & TCP_DISCONN_EVENTS) != 0)
|
else if ((flags & TCP_DISCONN_EVENTS) != 0)
|
||||||
{
|
{
|
||||||
FAR struct socket *psock = pstate->ir_sock;
|
FAR struct socket *psock = pstate->ir_sock;
|
||||||
|
FAR struct socket_conn_s *conn;
|
||||||
|
|
||||||
nwarn("WARNING: Lost connection\n");
|
nwarn("WARNING: Lost connection\n");
|
||||||
|
|
||||||
@@ -471,7 +472,8 @@ static uint16_t tcp_recvhandler(FAR struct net_driver_s *dev,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
DEBUGASSERT(psock != NULL);
|
DEBUGASSERT(psock != NULL);
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
conn = psock->s_conn;
|
||||||
|
if (_SS_ISCONNECTED(conn->s_flags))
|
||||||
{
|
{
|
||||||
/* Handle loss-of-connection event */
|
/* Handle loss-of-connection event */
|
||||||
|
|
||||||
@@ -660,7 +662,7 @@ ssize_t psock_tcp_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|||||||
|
|
||||||
/* Verify that the SOCK_STREAM has been and still is connected */
|
/* Verify that the SOCK_STREAM has been and still is connected */
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Was any data transferred from the readahead buffer after we were
|
/* Was any data transferred from the readahead buffer after we were
|
||||||
* disconnected? If so, then return the number of bytes received. We
|
* disconnected? If so, then return the number of bytes received. We
|
||||||
@@ -673,7 +675,7 @@ ssize_t psock_tcp_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|||||||
* recvfrom() will get an end-of-file indication.
|
* recvfrom() will get an end-of-file indication.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (ret <= 0 && !_SS_ISCLOSED(psock->s_flags))
|
if (ret <= 0 && !_SS_ISCLOSED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Nothing was previously received from the read-ahead buffers.
|
/* Nothing was previously received from the read-ahead buffers.
|
||||||
* The SOCK_STREAM must be (re-)connected in order to receive any
|
* The SOCK_STREAM must be (re-)connected in order to receive any
|
||||||
@@ -690,7 +692,8 @@ ssize_t psock_tcp_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|||||||
* return EAGAIN if no data was obtained from the read-ahead buffers.
|
* return EAGAIN if no data was obtained from the read-ahead buffers.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
else if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
else if (_SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
||||||
|
(flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
/* Return the number of bytes read from the read-ahead buffer if
|
/* Return the number of bytes read from the read-ahead buffer if
|
||||||
* something was received (already in 'ret'); EAGAIN if not.
|
* something was received (already in 'ret'); EAGAIN if not.
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
* already been disconnected.
|
* already been disconnected.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (psock->s_conn != NULL && _SS_ISCONNECTED(psock->s_flags))
|
if (psock->s_conn != NULL && _SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Report not connected */
|
/* Report not connected */
|
||||||
|
|
||||||
@@ -1069,7 +1069,9 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
||||||
|
|
||||||
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Not connected\n");
|
nerr("ERROR: Not connected\n");
|
||||||
ret = -ENOTCONN;
|
ret = -ENOTCONN;
|
||||||
@@ -1078,8 +1080,6 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
|
|
||||||
/* Make sure that we have the IP address mapping */
|
/* Make sure that we have the IP address mapping */
|
||||||
|
|
||||||
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
|
||||||
|
|
||||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||||
#ifdef CONFIG_NET_ARP_SEND
|
#ifdef CONFIG_NET_ARP_SEND
|
||||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||||
@@ -1113,7 +1113,8 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
|
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||||
|
|
||||||
nonblock = _SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0;
|
nonblock = _SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
||||||
|
(flags & MSG_DONTWAIT) != 0;
|
||||||
|
|
||||||
/* Dump the incoming buffer */
|
/* Dump the incoming buffer */
|
||||||
|
|
||||||
@@ -1133,7 +1134,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||||||
* state again to ensure the connection is still valid.
|
* state again to ensure the connection is still valid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: No longer connected\n");
|
nerr("ERROR: No longer connected\n");
|
||||||
ret = -ENOTCONN;
|
ret = -ENOTCONN;
|
||||||
@@ -1420,6 +1421,8 @@ errout:
|
|||||||
|
|
||||||
int psock_tcp_cansend(FAR struct socket *psock)
|
int psock_tcp_cansend(FAR struct socket *psock)
|
||||||
{
|
{
|
||||||
|
FAR struct socket_conn_s *conn;
|
||||||
|
|
||||||
/* Verify that we received a valid socket */
|
/* Verify that we received a valid socket */
|
||||||
|
|
||||||
if (!psock || !psock->s_conn)
|
if (!psock || !psock->s_conn)
|
||||||
@@ -1428,9 +1431,11 @@ int psock_tcp_cansend(FAR struct socket *psock)
|
|||||||
return -EBADF;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn = psock->s_conn;
|
||||||
|
|
||||||
/* Verify that this is connected TCP socket */
|
/* Verify that this is connected TCP socket */
|
||||||
|
|
||||||
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
|
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(conn->s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Not connected\n");
|
nerr("ERROR: Not connected\n");
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ static uint16_t tcpsend_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
* already been disconnected.
|
* already been disconnected.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Report not connected */
|
/* Report not connected */
|
||||||
|
|
||||||
@@ -545,12 +545,14 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
||||||
|
|
||||||
/* Check early if this is an un-connected socket, if so, then
|
/* Check early if this is an un-connected socket, if so, then
|
||||||
* return -ENOTCONN. Note, we will have to check this again, as we can't
|
* return -ENOTCONN. Note, we will have to check this again, as we can't
|
||||||
* guarantee the state won't change until we have the network locked.
|
* guarantee the state won't change until we have the network locked.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Not connected\n");
|
nerr("ERROR: Not connected\n");
|
||||||
ret = -ENOTCONN;
|
ret = -ENOTCONN;
|
||||||
@@ -559,8 +561,6 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
|
|||||||
|
|
||||||
/* Make sure that we have the IP address mapping */
|
/* Make sure that we have the IP address mapping */
|
||||||
|
|
||||||
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
|
||||||
|
|
||||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||||
#ifdef CONFIG_NET_ARP_SEND
|
#ifdef CONFIG_NET_ARP_SEND
|
||||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||||
@@ -607,7 +607,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
|
|||||||
* state again to ensure the connection is still valid.
|
* state again to ensure the connection is still valid.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: No longer connected\n");
|
nerr("ERROR: No longer connected\n");
|
||||||
net_unlock();
|
net_unlock();
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
* already been disconnected.
|
* already been disconnected.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Report not connected */
|
/* Report not connected */
|
||||||
|
|
||||||
@@ -457,9 +457,12 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile,
|
|||||||
off_t startpos;
|
off_t startpos;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
conn = psock->s_conn;
|
||||||
|
DEBUGASSERT(conn != NULL);
|
||||||
|
|
||||||
/* If this is an un-connected socket, then return ENOTCONN */
|
/* If this is an un-connected socket, then return ENOTCONN */
|
||||||
|
|
||||||
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(psock->s_flags))
|
if (psock->s_type != SOCK_STREAM || !_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
nerr("ERROR: Not connected\n");
|
nerr("ERROR: Not connected\n");
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
@@ -467,9 +470,6 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile,
|
|||||||
|
|
||||||
/* Make sure that we have the IP address mapping */
|
/* Make sure that we have the IP address mapping */
|
||||||
|
|
||||||
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
|
||||||
DEBUGASSERT(conn != NULL);
|
|
||||||
|
|
||||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||||
#ifdef CONFIG_NET_ARP_SEND
|
#ifdef CONFIG_NET_ARP_SEND
|
||||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ ssize_t psock_udp_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|||||||
|
|
||||||
/* Handle non-blocking UDP sockets */
|
/* Handle non-blocking UDP sockets */
|
||||||
|
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags) || (flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
/* Return the number of bytes read from the read-ahead buffer if
|
/* Return the number of bytes read from the read-ahead buffer if
|
||||||
* something was received (already in 'ret'); EAGAIN if not.
|
* something was received (already in 'ret'); EAGAIN if not.
|
||||||
|
|||||||
@@ -539,19 +539,24 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
size_t len, int flags,
|
size_t len, int flags,
|
||||||
FAR const struct sockaddr *to, socklen_t tolen)
|
FAR const struct sockaddr *to, socklen_t tolen)
|
||||||
{
|
{
|
||||||
FAR struct udp_conn_s *conn;
|
|
||||||
FAR struct udp_wrbuffer_s *wrb;
|
FAR struct udp_wrbuffer_s *wrb;
|
||||||
|
FAR struct udp_conn_s *conn;
|
||||||
bool nonblock;
|
bool nonblock;
|
||||||
bool empty;
|
bool empty;
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
|
/* Get the underlying the UDP connection structure. */
|
||||||
|
|
||||||
|
conn = psock->s_conn;
|
||||||
|
DEBUGASSERT(conn);
|
||||||
|
|
||||||
/* If the UDP socket was previously assigned a remote peer address via
|
/* If the UDP socket was previously assigned a remote peer address via
|
||||||
* connect(), then as with connection-mode socket, sendto() may not be
|
* connect(), then as with connection-mode socket, sendto() may not be
|
||||||
* used with a non-NULL destination address. Normally send() would be
|
* used with a non-NULL destination address. Normally send() would be
|
||||||
* used with such connected UDP sockets.
|
* used with such connected UDP sockets.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (to != NULL && _SS_ISCONNECTED(psock->s_flags))
|
if (to != NULL && _SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* EISCONN - A destination address was specified and the socket is
|
/* EISCONN - A destination address was specified and the socket is
|
||||||
* already connected.
|
* already connected.
|
||||||
@@ -564,7 +569,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
* must be provided.
|
* must be provided.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
else if (to == NULL && !_SS_ISCONNECTED(psock->s_flags))
|
else if (to == NULL && !_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* EDESTADDRREQ - The socket is not connection-mode and no peer
|
/* EDESTADDRREQ - The socket is not connection-mode and no peer
|
||||||
* address is set.
|
* address is set.
|
||||||
@@ -573,11 +578,6 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
return -EDESTADDRREQ;
|
return -EDESTADDRREQ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the underlying the UDP connection structure. */
|
|
||||||
|
|
||||||
conn = (FAR struct udp_conn_s *)psock->s_conn;
|
|
||||||
DEBUGASSERT(conn);
|
|
||||||
|
|
||||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||||
#ifdef CONFIG_NET_ARP_SEND
|
#ifdef CONFIG_NET_ARP_SEND
|
||||||
/* Assure the the IPv4 destination address maps to a valid MAC address in
|
/* Assure the the IPv4 destination address maps to a valid MAC address in
|
||||||
@@ -592,7 +592,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
|
|
||||||
/* Check if the socket is connection mode */
|
/* Check if the socket is connection mode */
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Yes.. use the connected remote address (the 'to' address is
|
/* Yes.. use the connected remote address (the 'to' address is
|
||||||
* null).
|
* null).
|
||||||
@@ -631,7 +631,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
|
|
||||||
/* Check if the socket is connection mode */
|
/* Check if the socket is connection mode */
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Yes.. use the connected remote address (the 'to' address is
|
/* Yes.. use the connected remote address (the 'to' address is
|
||||||
* null).
|
* null).
|
||||||
@@ -666,7 +666,8 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
}
|
}
|
||||||
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
|
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||||
|
|
||||||
nonblock = _SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0;
|
nonblock = _SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
||||||
|
(flags & MSG_DONTWAIT) != 0;
|
||||||
|
|
||||||
/* Dump the incoming buffer */
|
/* Dump the incoming buffer */
|
||||||
|
|
||||||
@@ -720,7 +721,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
* Check if the socket is connected
|
* Check if the socket is connected
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Yes.. get the connection address from the connection structure */
|
/* Yes.. get the connection address from the connection structure */
|
||||||
|
|
||||||
|
|||||||
@@ -264,13 +264,24 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
struct sendto_s state;
|
struct sendto_s state;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/* Verify that the sockfd corresponds to valid, allocated socket */
|
||||||
|
|
||||||
|
if (psock == NULL || psock->s_type != SOCK_DGRAM ||
|
||||||
|
psock->s_conn == NULL)
|
||||||
|
{
|
||||||
|
nerr("ERROR: Invalid socket\n");
|
||||||
|
return -EBADF;
|
||||||
|
}
|
||||||
|
|
||||||
/* If the UDP socket was previously assigned a remote peer address via
|
/* If the UDP socket was previously assigned a remote peer address via
|
||||||
* connect(), then as with connection-mode socket, sendto() may not be
|
* connect(), then as with connection-mode socket, sendto() may not be
|
||||||
* used with a non-NULL destination address. Normally send() would be
|
* used with a non-NULL destination address. Normally send() would be
|
||||||
* used with such connected UDP sockets.
|
* used with such connected UDP sockets.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (to != NULL && _SS_ISCONNECTED(psock->s_flags))
|
conn = psock->s_conn;
|
||||||
|
|
||||||
|
if (to != NULL && _SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* EISCONN - A destination address was specified and the socket is
|
/* EISCONN - A destination address was specified and the socket is
|
||||||
* already connected.
|
* already connected.
|
||||||
@@ -283,7 +294,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
* must be provided.
|
* must be provided.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
else if (to == NULL && !_SS_ISCONNECTED(psock->s_flags))
|
else if (to == NULL && !_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* EDESTADDRREQ - The socket is not connection-mode and no peer\
|
/* EDESTADDRREQ - The socket is not connection-mode and no peer\
|
||||||
* address is set.
|
* address is set.
|
||||||
@@ -292,11 +303,6 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
return -EDESTADDRREQ;
|
return -EDESTADDRREQ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get the underlying the UDP connection structure. */
|
|
||||||
|
|
||||||
conn = (FAR struct udp_conn_s *)psock->s_conn;
|
|
||||||
DEBUGASSERT(conn);
|
|
||||||
|
|
||||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||||
#ifdef CONFIG_NET_ARP_SEND
|
#ifdef CONFIG_NET_ARP_SEND
|
||||||
/* Assure the the IPv4 destination address maps to a valid MAC address in
|
/* Assure the the IPv4 destination address maps to a valid MAC address in
|
||||||
@@ -311,7 +317,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
|
|
||||||
/* Check if the socket is connection mode */
|
/* Check if the socket is connection mode */
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Yes.. use the connected remote address (the 'to' address is
|
/* Yes.. use the connected remote address (the 'to' address is
|
||||||
* null).
|
* null).
|
||||||
@@ -350,7 +356,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
|
|
||||||
/* Check if the socket is connection mode */
|
/* Check if the socket is connection mode */
|
||||||
|
|
||||||
if (_SS_ISCONNECTED(psock->s_flags))
|
if (_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Yes.. use the connected remote address (the 'to' address is
|
/* Yes.. use the connected remote address (the 'to' address is
|
||||||
* null).
|
* null).
|
||||||
@@ -413,7 +419,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||||||
|
|
||||||
/* Check if the socket is connected */
|
/* Check if the socket is connected */
|
||||||
|
|
||||||
if (!_SS_ISCONNECTED(psock->s_flags))
|
if (!_SS_ISCONNECTED(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* No.. Call udp_connect() to set the remote address in the connection
|
/* No.. Call udp_connect() to set the remote address in the connection
|
||||||
* structure to the sendto() destination address.
|
* structure to the sendto() destination address.
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ int usrsock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
|
|||||||
|
|
||||||
if (!(conn->flags & USRSOCK_EVENT_RECVFROM_AVAIL))
|
if (!(conn->flags & USRSOCK_EVENT_RECVFROM_AVAIL))
|
||||||
{
|
{
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags))
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Nothing to receive from daemon side. */
|
/* Nothing to receive from daemon side. */
|
||||||
|
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ int usrsock_connect(FAR struct socket *psock,
|
|||||||
|
|
||||||
/* Do not block on waiting for request completion if nonblocking socket. */
|
/* Do not block on waiting for request completion if nonblocking socket. */
|
||||||
|
|
||||||
if (!conn->resp.inprogress || !_SS_ISNONBLOCK(psock->s_flags))
|
if (!conn->resp.inprogress || !_SS_ISNONBLOCK(conn->sconn.s_flags))
|
||||||
{
|
{
|
||||||
/* Wait for completion of request (or signal). */
|
/* Wait for completion of request (or signal). */
|
||||||
|
|
||||||
|
|||||||
@@ -302,7 +302,8 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
|||||||
|
|
||||||
if (!(conn->flags & USRSOCK_EVENT_RECVFROM_AVAIL))
|
if (!(conn->flags & USRSOCK_EVENT_RECVFROM_AVAIL))
|
||||||
{
|
{
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
||||||
|
(flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
/* Nothing to receive from daemon side. */
|
/* Nothing to receive from daemon side. */
|
||||||
|
|
||||||
|
|||||||
@@ -283,7 +283,8 @@ ssize_t usrsock_sendmsg(FAR struct socket *psock,
|
|||||||
|
|
||||||
if (!(conn->flags & USRSOCK_EVENT_SENDTO_READY))
|
if (!(conn->flags & USRSOCK_EVENT_SENDTO_READY))
|
||||||
{
|
{
|
||||||
if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
|
if (_SS_ISNONBLOCK(conn->sconn.s_flags) ||
|
||||||
|
(flags & MSG_DONTWAIT) != 0)
|
||||||
{
|
{
|
||||||
/* Send busy at daemon side. */
|
/* Send busy at daemon side. */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user