diff --git a/apps/examples/ustream/ustream_client.c b/apps/examples/ustream/ustream_client.c index 797a5a18c..b09e9558b 100644 --- a/apps/examples/ustream/ustream_client.c +++ b/apps/examples/ustream/ustream_client.c @@ -103,7 +103,7 @@ int client_main(int argc, char *argv[]) strncpy(myaddr.sun_path, CONFIG_EXAMPLES_USTREAM_ADDR, addrlen); myaddr.sun_path[addrlen] = '\0'; - printf("client: Connecting...\n"); + printf("client: Connecting to %s...\n", CONFIG_EXAMPLES_USTREAM_ADDR); addrlen += sizeof(sa_family_t) + 1; ret = connect( sockfd, (struct sockaddr *)&myaddr, addrlen); if (ret < 0) @@ -176,6 +176,7 @@ int client_main(int argc, char *argv[]) goto errout_with_socket; } + printf("client: Terminating\n"); close(sockfd); free(outbuf); free(inbuf); diff --git a/apps/examples/ustream/ustream_server.c b/apps/examples/ustream/ustream_server.c index 4432019a4..0bd8467f0 100644 --- a/apps/examples/ustream/ustream_server.c +++ b/apps/examples/ustream/ustream_server.c @@ -113,6 +113,8 @@ int server_main(int argc, char *argv[]) /* Listen for connections on the bound socket */ + printf("server: Accepting connections on %s ...\n", CONFIG_EXAMPLES_USTREAM_ADDR); + if (listen(listensd, 5) < 0) { printf("server: listen failure %d\n", errno); @@ -121,7 +123,6 @@ int server_main(int argc, char *argv[]) /* Accept only one connection */ - printf("server: Accepting connections on %s\n", CONFIG_EXAMPLES_USTREAM_ADDR); acceptsd = accept(listensd, (struct sockaddr*)&myaddr, &addrlen); if (acceptsd < 0) { @@ -187,14 +188,7 @@ int server_main(int argc, char *argv[]) } printf("server: Sent %d bytes\n", nbytessent); - - /* If this platform only does abortive disconnects, then wait a bit to get the - * client side a change to receive the data. - */ - - printf("server: Wait before closing\n"); - sleep(60); - + printf("server: Terminating\n"); close(listensd); close(acceptsd); free(buffer); diff --git a/nuttx/arch/sim/src/nuttx-names.dat b/nuttx/arch/sim/src/nuttx-names.dat index bfd3c051c..5456f2722 100644 --- a/nuttx/arch/sim/src/nuttx-names.dat +++ b/nuttx/arch/sim/src/nuttx-names.dat @@ -26,10 +26,14 @@ nanosleep NXnanosleep pthread_create NXpthread_create read NXread realloc NXrealloc +recv NXrecv +recvfrom NXrecvfrom rewinddir NXrewinddir rmdir NXrmdir seekdir NXseekdir select NXselect +send NXsend +sendto NXsendto sleep NXsleep socket NXsocket stat NXstat diff --git a/nuttx/net/local/local_connect.c b/nuttx/net/local/local_connect.c index c10de214a..57e32a1b1 100644 --- a/nuttx/net/local/local_connect.c +++ b/nuttx/net/local/local_connect.c @@ -176,7 +176,7 @@ int inline local_stream_connect(FAR struct local_conn_s *client, /* Yes.. open the read-only FIFO */ - ret = local_open_client_tx(client); + ret = local_open_client_rx(client); if (ret < 0) { ndbg("ERROR: Failed to open write-only FIFOs for %s: %d\n", @@ -268,21 +268,27 @@ int local_connect(FAR struct local_conn_s *client, { if (strncmp(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1) == 0) { + int ret = OK; + /* Bind the address and protocol */ client->lc_proto = conn->lc_proto; strncpy(client->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1); client->lc_path[UNIX_PATH_MAX-1] = '\0'; + /* The client is now bound to an address */ + + client->lc_state = LOCAL_STATE_BOUND; + /* We have to do more for the SOCK_STREAM family */ if (conn->lc_proto == SOCK_STREAM) { - return local_stream_connect(client, conn, state); + ret = local_stream_connect(client, conn, state); } net_unlock(state); - return OK; + return ret; } } break; diff --git a/nuttx/net/local/local_fifo.c b/nuttx/net/local/local_fifo.c index 15ded2932..ee5cb1072 100644 --- a/nuttx/net/local/local_fifo.c +++ b/nuttx/net/local/local_fifo.c @@ -237,8 +237,8 @@ static inline int local_rx_open(FAR struct local_conn_s *conn, static inline int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path) { - conn->lc_infd = open(path, O_WRONLY); - if (conn->lc_infd < 0) + conn->lc_outfd = open(path, O_WRONLY); + if (conn->lc_outfd < 0) { int errcode = errno; DEBUGASSERT(errcode > 0); diff --git a/nuttx/net/local/local_recvfrom.c b/nuttx/net/local/local_recvfrom.c index c4c9e6a6c..7ce5bb0da 100644 --- a/nuttx/net/local/local_recvfrom.c +++ b/nuttx/net/local/local_recvfrom.c @@ -179,7 +179,7 @@ ssize_t psock_local_recvfrom(FAR struct socket *psock, FAR void *buf, * the size of the next packet. */ - ret = local_sync(conn->lc_infd); + ret = local_sync(conn->lc_infd); if (ret < 0) { ndbg("ERROR: Failed to get packet length: %d\n", ret); diff --git a/nuttx/net/local/local_recvutils.c b/nuttx/net/local/local_recvutils.c index a7eee1c4a..7457268ec 100644 --- a/nuttx/net/local/local_recvutils.c +++ b/nuttx/net/local/local_recvutils.c @@ -76,16 +76,16 @@ int local_fifo_read(int fd, FAR uint8_t *buf, size_t *len) { - ssize_t total; + ssize_t remaining; ssize_t nread; int ret; DEBUGASSERT(buf && len); - total = 0; - while (len > 0) + remaining = *len; + while (remaining > 0) { - nread = read(fd, buf, *len); + nread = read(fd, buf, remaining); if (nread < 0) { int errcode = errno; @@ -112,15 +112,15 @@ int local_fifo_read(int fd, FAR uint8_t *buf, size_t *len) else { DEBUGASSERT(nread <= len); - len -= nread; - buf += nread; + remaining -= nread; + buf += nread; } } ret = OK; errout: - *len = total; + *len -= remaining; return ret; } diff --git a/nuttx/net/local/local_send.c b/nuttx/net/local/local_send.c index 74bf7f0a4..7910612e4 100644 --- a/nuttx/net/local/local_send.c +++ b/nuttx/net/local/local_send.c @@ -76,6 +76,7 @@ ssize_t psock_local_send(FAR struct socket *psock, FAR const void *buf, size_t len, int flags) { FAR struct local_conn_s *peer; + int ret; DEBUGASSERT(psock && psock->s_conn && buf); peer = (FAR struct local_conn_s *)psock->s_conn; @@ -84,14 +85,20 @@ ssize_t psock_local_send(FAR struct socket *psock, FAR const void *buf, * outgoing FIFO for write-only access. */ - if (peer->lc_type != LOCAL_STATE_CONNECTED || + if (peer->lc_state != LOCAL_STATE_CONNECTED || peer->lc_outfd < 0) { ndbg("ERROR: not connected\n"); return -ENOTCONN; } - return local_send_packet(peer->lc_outfd, (FAR uint8_t *)buf, len); + /* Send the packet */ + + ret = local_send_packet(peer->lc_outfd, (FAR uint8_t *)buf, len); + + /* If the send was successful, then the full packet will have been sent */ + + return ret < 0 ? ret : len; } #endif /* CONFIG_NET && CONFIG_NET_LOCAL */ diff --git a/nuttx/net/socket/send.c b/nuttx/net/socket/send.c index ddcc97ea3..6ac569cb1 100644 --- a/nuttx/net/socket/send.c +++ b/nuttx/net/socket/send.c @@ -38,7 +38,7 @@ ****************************************************************************/ #include -#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) +#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_LOCAL) #include #include @@ -243,4 +243,4 @@ ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags) return psock_send(sockfd_socket(sockfd), buf, len, flags); } -#endif /* CONFIG_NET && CONFIG_NET_TCP */ +#endif /* CONFIG_NET_TCP || CONFIG_NET_LOCAL */