diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-01-30 11:14:24 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-01-30 11:14:24 -0600 |
commit | 958a1b5aa2523827242e714dd17c64956ab26806 (patch) | |
tree | ba29aba4ac6428a34bff418e315640238de71054 /apps/examples | |
parent | 26555d8d49e6379bfb175439f29c30e2b4dbc239 (diff) | |
download | nuttx-958a1b5aa2523827242e714dd17c64956ab26806.tar.gz nuttx-958a1b5aa2523827242e714dd17c64956ab26806.tar.bz2 nuttx-958a1b5aa2523827242e714dd17c64956ab26806.zip |
Unix domain/FIFOs: Fix a race condition between FIFO buffer operations and the opening and closing of FIFOs which necessary when the FIFOs are used to support Unix domain, datagram sockets. The default policy is the deallocate FIFO buffering when the last client closes the pipe. When when used for datagram communicatinos, packets left in the FIFO will be lost. Some like UDP read-ahead is needed: The buffered data in the FIFO needs to be retained until the reader gets a chance to re-open the FIFO. Added an ioctl (PIPEIOC_POLICY) to control the buffer policy. Default (0) is the legacy behavior; Unix domain datagram logic sets the alternative policy so that the packet data persists after the FIFO is closed.
Diffstat (limited to 'apps/examples')
-rw-r--r-- | apps/examples/udgram/udgram_client.c | 6 | ||||
-rw-r--r-- | apps/examples/udgram/udgram_server.c | 12 |
2 files changed, 9 insertions, 9 deletions
diff --git a/apps/examples/udgram/udgram_client.c b/apps/examples/udgram/udgram_client.c index cec238d05..f3ce4558f 100644 --- a/apps/examples/udgram/udgram_client.c +++ b/apps/examples/udgram/udgram_client.c @@ -93,7 +93,7 @@ int client_main(int argc, char *argv[]) sockfd = socket(PF_LOCAL, SOCK_DGRAM, 0); if (sockfd < 0) { - printf("client socket failure %d\n", errno); + printf("client: ERROR socket failure %d\n", errno); return 1; } @@ -127,13 +127,13 @@ int client_main(int argc, char *argv[]) if (nbytes < 0) { - printf("client: %d. sendto failed: %d\n", offset, errno); + printf("client: %d. ERROR sendto failed: %d\n", offset, errno); close(sockfd); return 1; } else if (nbytes != SENDSIZE) { - printf("client: %d. Bad send length: %d Expected: %d\n", + printf("client: %d. ERROR Bad send length: %d Expected: %d\n", offset, nbytes, SENDSIZE); close(sockfd); return 1; diff --git a/apps/examples/udgram/udgram_server.c b/apps/examples/udgram/udgram_server.c index f09904881..5a114e50f 100644 --- a/apps/examples/udgram/udgram_server.c +++ b/apps/examples/udgram/udgram_server.c @@ -122,7 +122,7 @@ int server_main(int argc, char *argv[]) if (bind(sockfd, (struct sockaddr*)&server, addrlen) < 0) { - printf("server: bind failure: %d\n", errno); + printf("server: ERROR bind failure: %d\n", errno); return 1; } @@ -137,7 +137,7 @@ int server_main(int argc, char *argv[]) if (nbytes < 0) { - printf("server: %d. recv failed: %d\n", offset, errno); + printf("server: %d. ERROR recv failed: %d\n", offset, errno); close(sockfd); return 1; } @@ -178,7 +178,7 @@ int server_main(int argc, char *argv[]) if (nbytes != SENDSIZE) { - printf("server: %d. recv size incorrect: %d vs %d\n", + printf("server: %d. ERROR recv size incorrect: %d vs %d\n", offset, nbytes, SENDSIZE); close(sockfd); return 1; @@ -186,13 +186,13 @@ int server_main(int argc, char *argv[]) if (offset < inbuf[0]) { - printf("server: %d. %d packets lost, resetting offset\n", + printf("server: %d. ERROR %d packets lost, resetting offset\n", offset, inbuf[0] - offset); offset = inbuf[0]; } else if (offset > inbuf[0]) { - printf("server: %d. Bad offset in buffer: %d\n", + printf("server: %d. ERROR Bad offset in buffer: %d\n", offset, inbuf[0]); close(sockfd); return 1; @@ -200,7 +200,7 @@ int server_main(int argc, char *argv[]) if (!check_buffer(inbuf)) { - printf("server: %d. Bad buffer contents\n", offset); + printf("server: %d. ERROR Bad buffer contents\n", offset); close(sockfd); return 1; } |