#include <sys/event.h>
+/* INT_TO_UDATA() macros from https://github.com/libevent/libevent */
+
+/* Some platforms apparently define the udata field of struct kevent as
+ * intptr_t, whereas others define it as void*. There doesn't seem to be an
+ * easy way to tell them apart via autoconf, so we need to use OS macros. */
+#if defined(HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__darwin__) && !defined(__APPLE__)
+#define INT_TO_UDATA(x) ((intptr_t)(x))
+#else
+#define INT_TO_UDATA(x) ((void*)(intptr_t)(x))
+#endif
+
#define SU_ENABLE_MULTISHOT_KQUEUE 1
#include <stdlib.h>
i = ser->ser_id;
flags = (wait->events & SU_WAIT_IN) ? EV_ADD : EV_ADD | EV_DISABLE;
- EV_SET(ev, wait->fd, EVFILT_READ, flags, 0, 0, (void *)(intptr_t)i);
+ EV_SET(ev, wait->fd, EVFILT_READ, flags, 0, 0, INT_TO_UDATA(i));
if (kevent(self->sup_kqueue, ev, 1, NULL, 0, NULL) == -1) {
SU_DEBUG_0(("kevent((%u, %s, %u, %p)) failed: %s\n",
wait->fd, "EVFILT_READ", flags, (void *)(intptr_t)i, strerror(errno)));
}
flags = (wait->events & SU_WAIT_OUT) ? EV_ADD : EV_ADD | EV_DISABLE;
- EV_SET(ev, wait->fd, EVFILT_WRITE, flags, 0, 0, (void *)(intptr_t)i);
+ EV_SET(ev, wait->fd, EVFILT_WRITE, flags, 0, 0, INT_TO_UDATA(i));
if (kevent(self->sup_kqueue, ev, 1, NULL, 0, NULL) == -1) {
int error = errno;
SU_DEBUG_0(("kevent((%u, %s, %u, %p)) failed: %s\n",
wait->fd, "EVFILT_WRITE", flags, (void *)(intptr_t)i, strerror(error)));
- EV_SET(ev, wait->fd, EVFILT_READ, EV_DELETE, 0, 0, (void *)(intptr_t)i);
+ EV_SET(ev, wait->fd, EVFILT_READ, EV_DELETE, 0, 0, INT_TO_UDATA(i));
kevent(self->sup_kqueue, ev, 1, NULL, 0, NULL);
errno = error;
wait = ser->ser_wait;
- EV_SET(ev, wait->fd, EVFILT_READ, EV_DELETE, 0, 0, (void *)(intptr_t)i);
+ EV_SET(ev, wait->fd, EVFILT_READ, EV_DELETE, 0, 0, INT_TO_UDATA(i));
if (kevent(self->sup_kqueue, ev, 1, NULL, 0, NULL) == -1) {
SU_DEBUG_0(("remove kevent((%u, %s, %s, %p)) failed: %s\n",
wait->fd, "EVFILT_READ", "EV_DELETE", (void *)(intptr_t)i,
strerror(errno)));
}
- EV_SET(ev, wait->fd, EVFILT_WRITE, EV_DELETE, 0, 0, (void *)(intptr_t)i);
+ EV_SET(ev, wait->fd, EVFILT_WRITE, EV_DELETE, 0, 0, INT_TO_UDATA(i));
if (kevent(self->sup_kqueue, ev, 1, NULL, 0, NULL) == -1) {
SU_DEBUG_0(("remove kevent((%u, %s, %s, %p)) failed: %s\n",
wait->fd, "EVFILT_WRITE", "EV_DELETE", (void *)(intptr_t)i,
wait->events = events;
flags = (wait->events & SU_WAIT_IN) ? EV_ADD | EV_ENABLE : EV_ADD | EV_DISABLE;
- EV_SET(ev, wait->fd, EVFILT_READ, flags, 0, 0, (void *)(intptr_t)index);
+ EV_SET(ev, wait->fd, EVFILT_READ, flags, 0, 0, INT_TO_UDATA(index));
if (kevent(self->sup_kqueue, ev, 1, NULL, 0, NULL) == -1) {
SU_DEBUG_0(("modify kevent((%u, %s, %s, %p)) failed: %s\n",
wait->fd, "EVFILT_READ",
}
flags = (wait->events & SU_WAIT_OUT) ? EV_ADD | EV_ENABLE : EV_ADD | EV_DISABLE;
- EV_SET(ev, wait->fd, EVFILT_WRITE, flags, 0, 0, (void *)(intptr_t)index);
+ EV_SET(ev, wait->fd, EVFILT_WRITE, flags, 0, 0, INT_TO_UDATA(index));
if (kevent(self->sup_kqueue, ev, 1, NULL, 0, NULL) == -1) {
SU_DEBUG_0(("modify kevent((%u, %s, %s, %p)) failed: %s\n",
wait->fd, "EVFILT_WRITE",