diff --git a/net/local/local.h b/net/local/local.h index 44a5b24093..7b5356f371 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -502,7 +502,8 @@ int local_create_fifos(FAR struct local_conn_s *conn); * ****************************************************************************/ -int local_create_halfduplex(FAR struct local_conn_s *conn); +int local_create_halfduplex(FAR struct local_conn_s *conn, + FAR const char *path); /**************************************************************************** * Name: local_destroy_fifos @@ -582,7 +583,7 @@ int local_open_receiver(FAR struct local_conn_s *conn); * ****************************************************************************/ -int local_open_sender(FAR struct local_conn_s *conn, FAR char *path); +int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path); #undef EXTERN #ifdef __cplusplus diff --git a/net/local/local_fifo.c b/net/local/local_fifo.c index 24439e1dcd..85e2468b0e 100644 --- a/net/local/local_fifo.c +++ b/net/local/local_fifo.c @@ -320,14 +320,14 @@ int local_create_fifos(FAR struct local_conn_s *conn) * ****************************************************************************/ -int local_create_halfduplex(FAR struct local_conn_s *conn) +int local_create_halfduplex(FAR struct local_conn_s *conn, FAR const char *path) { - char path[LOCAL_FULLPATH_LEN]; + char fullpath[LOCAL_FULLPATH_LEN]; /* Create the half duplex FIFO if it does not already exist. */ - local_hd_name(conn->lc_path, path); - return local_create_fifo(path); + local_hd_name(path, fullpath); + return local_create_fifo(fullpath); } /**************************************************************************** @@ -490,7 +490,7 @@ int local_open_receiver(FAR struct local_conn_s *conn) * ****************************************************************************/ -int local_open_sender(FAR struct local_conn_s *conn, FAR char *path) +int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path) { char fullpath[LOCAL_FULLPATH_LEN]; diff --git a/net/local/local_recvfrom.c b/net/local/local_recvfrom.c index 731b5cc99c..cfcf7f325e 100644 --- a/net/local/local_recvfrom.c +++ b/net/local/local_recvfrom.c @@ -266,7 +266,7 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, /* Make sure that half duplex FIFO has been created */ - ret = local_create_halfduplex(conn); + ret = local_create_halfduplex(conn, conn->lc_path); if (ret < 0) { ndbg("ERROR: Failed to create FIFO for %s: %d\n", diff --git a/net/local/local_sendpacket.c b/net/local/local_sendpacket.c index 3658175d64..d32a09f34f 100644 --- a/net/local/local_sendpacket.c +++ b/net/local/local_sendpacket.c @@ -152,7 +152,7 @@ int local_send_packet(int fd, FAR const uint8_t *buf, size_t len) len16 = len; ret = local_fifo_write(fd, (FAR const uint8_t *)&len16, sizeof(uint16_t)); - if(ret == OK) + if (ret == OK) { /* Send the packet data */ diff --git a/net/local/local_sendto.c b/net/local/local_sendto.c index 57871b2d9c..9c242c87a4 100644 --- a/net/local/local_sendto.c +++ b/net/local/local_sendto.c @@ -95,13 +95,17 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf, DEBUGASSERT(buf && len <= UINT16_MAX); - /* Verify that this is a bound, un-connected peer socket */ + /* 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. + */ - if (conn->lc_state != LOCAL_STATE_BOUND) + if (conn->lc_state != LOCAL_STATE_UNBOUND && + conn->lc_state != LOCAL_STATE_BOUND) { /* Either not bound to address or it is connected */ - ndbg("ERROR: Connected or not bound\n"); + ndbg("ERROR: Connected state\n"); return -EISCONN; } @@ -122,7 +126,7 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf, * REVISIT: Or should be just make sure that it already exists? */ - ret = local_create_halfduplex(conn); + ret = local_create_halfduplex(conn, unaddr->sun_path); if (ret < 0) { ndbg("ERROR: Failed to create FIFO for %s: %d\n", @@ -147,6 +151,12 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf, { ndbg("ERROR: Failed to send the packet: %d\n", ret); } + else + { + /* local_send_packet returns 0 if all 'len' bytes were sent */ + + nsent = len; + } /* Now we can close the write-only socket descriptor */ diff --git a/net/socket/sendto.c b/net/socket/sendto.c index 02cb929295..9c40da238b 100644 --- a/net/socket/sendto.c +++ b/net/socket/sendto.c @@ -127,7 +127,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf, { socklen_t minlen; #if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_LOCAL) - int ret; + ssize_t nsent; #endif int err; @@ -209,7 +209,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf, if (psock->s_domain == PF_LOCAL) #endif { - ret = psock_local_sendto(psock, buf, len, flags, to, tolen); + nsent = psock_local_sendto(psock, buf, len, flags, to, tolen); } #endif /* CONFIG_NET_LOCAL */ @@ -218,20 +218,20 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf, else #endif { - ret = psock_udp_sendto(psock, buf, len, flags, to, tolen); + nsent = psock_udp_sendto(psock, buf, len, flags, to, tolen); } #endif /* CONFIG_NET_UDP */ /* Check if the domain-specific sendto() logic failed */ - if (ret < 0) + if (nsent < 0) { - ndbg("ERROR: Domain sendto() failed: %d\n", ret); - err = -ret; + ndbg("ERROR: Unix domain sendto() failed: %d\n", ret); + err = -nsent; goto errout; } - return OK; + return nsent; #else err = ENOSYS; #endif /* CONFIG_NET_UDP || CONFIG_NET_LOCAL */