#include <sys/epoll.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/socket.h>

#define DIE(s) do { perror(s); exit(1); } while(0)

int main(int argc, char **argv)
{
	int epoll_fd, fds1[2], fds2[2];
	struct epoll_event ev;

	epoll_fd = epoll_create(32000);
	if (epoll_fd < 0)
		DIE("epoll_create");

	if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds1) < 0)
		DIE("socketpair (1)");

	memset(&ev, 0, sizeof(ev));
	ev.events = EPOLLIN;
	if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fds1[0], &ev)<0)
		DIE("epoll_ctl add 1");

	close(fds1[0]);
	close(fds1[1]);

#if 0
	if (epoll_ctl(epoll_fd, EPOLL_CTL_DEL, fds1[0], &ev)<0)
		DIE("epoll_ctl del 1");
#endif

	if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds2) < 0)
		DIE("socketpair (2)");

	if (fds2[0] != fds1[0]) {
		fprintf(stderr, "fd mismatch; can't procede");
		return -1;
	}

	if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fds2[0], &ev)<0)
		DIE("epoll_ctl add 2");

	return 0;
}
