zhhyu7 commented on code in PR #21418:
URL: https://github.com/apache/nuttx/pull/21418#discussion_r4475834613
##########
net/local/local_sendmsg.c:
##########
@@ -286,11 +202,13 @@ static ssize_t local_sendto(FAR struct socket *psock,
/* Verify that this is not a connected peer socket. It need not be
* bound, however. If unbound, recvfrom will see this as a nameless
- * connection.
+ * connection. DGRAM connected state is allowed since connect() only
+ * sets the default peer address without establishing a FIFO link.
*/
if (conn->lc_state != LOCAL_STATE_UNBOUND &&
- conn->lc_state != LOCAL_STATE_BOUND)
+ conn->lc_state != LOCAL_STATE_BOUND &&
+ conn->lc_state != LOCAL_STATE_CONNECTED)
Review Comment:
Done.
##########
net/local/local_sockif.c:
##########
@@ -822,9 +855,70 @@ static int local_connect(FAR struct socket *psock,
#ifdef CONFIG_NET_LOCAL_DGRAM
case SOCK_DGRAM:
{
- /* Perform the datagram connection logic */
+ FAR struct local_conn_s *conn = psock->s_conn;
+ FAR const struct sockaddr_un *unaddr =
+ (FAR const struct sockaddr_un *)addr;
+
+ if (addr->sa_family == AF_UNSPEC)
+ {
+ memset(&conn->lc_daddr, 0, sizeof(conn->lc_daddr));
+ if (conn->lc_state == LOCAL_STATE_CONNECTED)
+ {
+ conn->lc_state = conn->lc_type == LOCAL_TYPE_UNNAMED
+ ? LOCAL_STATE_UNBOUND
+ : LOCAL_STATE_BOUND;
+ }
+
+ return OK;
+ }
+
+ /* Validate the destination before recording it, so that
+ * connect() reports a bad name instead of letting every later
+ * send() fail. POSIX allows a connectionless connect() to
+ * check the address.
+ */
+
+ if (conn->lc_peer == NULL)
Review Comment:
Done.
##########
net/local/local_sockif.c:
##########
@@ -822,9 +855,70 @@ static int local_connect(FAR struct socket *psock,
#ifdef CONFIG_NET_LOCAL_DGRAM
case SOCK_DGRAM:
{
- /* Perform the datagram connection logic */
+ FAR struct local_conn_s *conn = psock->s_conn;
+ FAR const struct sockaddr_un *unaddr =
+ (FAR const struct sockaddr_un *)addr;
+
+ if (addr->sa_family == AF_UNSPEC)
+ {
+ memset(&conn->lc_daddr, 0, sizeof(conn->lc_daddr));
+ if (conn->lc_state == LOCAL_STATE_CONNECTED)
+ {
+ conn->lc_state = conn->lc_type == LOCAL_TYPE_UNNAMED
+ ? LOCAL_STATE_UNBOUND
+ : LOCAL_STATE_BOUND;
+ }
+
+ return OK;
+ }
+
+ /* Validate the destination before recording it, so that
+ * connect() reports a bad name instead of letting every later
+ * send() fail. POSIX allows a connectionless connect() to
+ * check the address.
+ */
+
+ if (conn->lc_peer == NULL)
+ {
+ FAR struct local_conn_s *server;
+
+ local_lock();
+ server = local_findconn(conn, unaddr);
+ local_unlock();
+
+ if (server == NULL)
+ {
+ FAR const char *path =
+ &unaddr->sun_path[unaddr->sun_path[0] == '\0' ? 1 : 0];
+ struct stat buf;
+
+ /* No socket of that name. A name that exists in the
+ * file system but is not one of our sockets is a
+ * connection refused, anything else does not exist.
+ */
- return -ENOSYS;
+ if (stat(path, &buf) == 0)
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]