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.
This commit is contained in:
parent
ac103febad
commit
f5558cd10e
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user