You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Poll doesn't return the correct bits and ioctl stops working when one end of the socket is closed and the other end is open with incoming data still in the buffer. The expected results and the results I am getting are in the comments in the code below.
Poll doesn't return the correct bits and ioctl stops working when one end of the socket is closed and the other end is open with incoming data still in the buffer. The expected results and the results I am getting are in the comments in the code below.
define _GNU_SOURCE
include <poll.h>
include <sys/ioctl.h>
include <sys/types.h>
include <sys/socket.h>
include <errno.h>
include <stdio.h>
include <unistd.h>
ifndef POLLRDHUP
define POLLRDHUP 0
endif
/*
Output under Linux:
POLL: 1 2011 (hup:10,rdhup:2000,in:1,err:0,rdnorm:0)
IOCTL 0 5
GOT BYTES: size=5 value='test'
Output under windows 10:
POLL: 1 11 (hup:10,rdhup:0,in:1,err:0,rdnorm:0)
IOCTL 0 0
GOT BYTES: size=5 value='test'
*/
int main(void)
{
int err;
int sv[2];
char buf[5] = { 0 };
struct pollfd pfd;
int n;
socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
write(sv[1], "test", 5);
close(sv[1]);
pfd.fd = sv[0];
pfd.events = POLLIN | POLLRDHUP;
pfd.revents = 0;
err = poll(&pfd, 1, -1);
printf("POLL: %d %hx (hup:%x,rdhup:%x,in:%x,err:%x,rdnorm:%x)\n",
err,
pfd.revents,
pfd.revents & POLLHUP,
pfd.revents & POLLRDHUP,
pfd.revents & POLLIN,
pfd.revents & POLLERR,
pfd.revents & POLLRDNORM);
err = ioctl(pfd.fd, FIONREAD, &n);
printf("IOCTL %d %d\n", err, n);
err = read(pfd.fd, buf, 5);
if ( err == 0 )
{
printf("Unexpected EOF\n");
return 1;
} else if ( err < 0 )
{
perror("read");
return 1;
}
printf("GOT BYTES: size=%d value='%s'\n", err, buf);
return 0;
}
The text was updated successfully, but these errors were encountered: