Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unix domain sockets are buggy #207

Closed
tsmith201604 opened this issue Apr 15, 2016 · 2 comments
Closed

Unix domain sockets are buggy #207

tsmith201604 opened this issue Apr 15, 2016 · 2 comments

Comments

@tsmith201604
Copy link

tsmith201604 commented Apr 15, 2016

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;

}

@patryk9200
Copy link

Known issue. Related to: #134

@benhillis
Copy link
Member

Closing this out as a duplicate of #134.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants