Skip to content

Unix domain sockets are buggy #207

Closed

Description

@tsmith201604

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;

}

Activity

  1. patryk9200 commented on Apr 18, 2016

    @patryk9200

    Known issue. Related to: #134

  2. benhillis commented on Jun 1, 2016

    @benhillis
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions