commit 959c855734e3af12f35532d76deb1ab85474f8f4
parent a9164839e6f091ff66b6684c65d55ed7f5a09ebb
Author: Laslo Hunhold <dev@frign.de>
Date:   Sun, 17 Jan 2021 13:22:53 +0100
Fix compilation on OpenBSD
The OpenBSD-code was written "blindly" only with the manuals. The
errors that occured are now fixed. It shows how well-written the
OpenBSD manuals are that you can write such a nontrivial state-machine
and it just works (once the syntax-errors are fixed).
Signed-off-by: Laslo Hunhold <dev@frign.de>
Diffstat:
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/main.c b/main.c
@@ -243,7 +243,7 @@ thread_method(void *data)
 
 		/* handle events */
 		for (i = 0; i < (size_t)nready; i++) {
-			if (event[i].events & (EPOLLERR | EPOLLHUP)) {
+			if (queue_event_is_dropped(&event[i])) {
 				fd = queue_event_get_fd(&event[i]);
 
 				if (fd != d->insock) {
diff --git a/queue.c b/queue.c
@@ -80,11 +80,11 @@ queue_add_fd(int qfd, int fd, enum queue_event_type t, int shared,
 			return 1;
 		}
 	#else
-		kevent e;
+		struct kevent e;
 		int events;
 
 		/* prepare event flag */
-		event = (shared) ? 0 : EV_CLEAR;
+		events = (shared) ? 0 : EV_CLEAR;
 
 		switch (t) {
 		case QUEUE_EVENT_IN:
@@ -95,7 +95,7 @@ queue_add_fd(int qfd, int fd, enum queue_event_type t, int shared,
 			break;
 		}
 
-		EV_SET(&e, fd, events, EV_ADD, 0, 0, 0);
+		EV_SET(&e, fd, events, EV_ADD, 0, 0, (void *)data);
 
 		if (kevent(qfd, &e, 1, NULL, 0, NULL) < 0) {
 			warn("kevent:");
@@ -139,7 +139,7 @@ queue_mod_fd(int qfd, int fd, enum queue_event_type t, const void *data)
 			return 1;
 		}
 	#else
-		kevent e;
+		struct kevent e;
 		int events;
 
 		events = EV_CLEAR;
@@ -153,7 +153,7 @@ queue_mod_fd(int qfd, int fd, enum queue_event_type t, const void *data)
 			break;
 		}
 
-		EV_SET(&e, fd, events, EV_ADD, 0, 0, 0);
+		EV_SET(&e, fd, events, EV_ADD, 0, 0, (void *)data);
 
 		if (kevent(qfd, &e, 1, NULL, 0, NULL) < 0) {
 			warn("kevent:");
@@ -175,7 +175,7 @@ queue_rem_fd(int qfd, int fd)
 			return 1;
 		}
 	#else
-		kevent e;
+		struct kevent e;
 
 		EV_SET(&e, fd, 0, EV_DELETE, 0, 0, 0);
 
@@ -199,7 +199,7 @@ queue_wait(int qfd, queue_event *e, size_t elen)
 			return -1;
 		}
 	#else
-		if ((nready = kevent(qfd, NULL, 0, e, elen, NULL) < 0) {
+		if ((nready = kevent(qfd, NULL, 0, e, elen, NULL)) < 0) {
 			warn("kevent:");
 			return 1;
 		}
@@ -227,3 +227,13 @@ queue_event_get_ptr(const queue_event *e)
 		return e->udata;
 	#endif
 }
+
+int
+queue_event_is_dropped(const queue_event *e)
+{
+	#ifdef __linux__
+		return (e->events & (EPOLLERR | EPOLLHUP)) ? 1 : 0;
+	#else
+		return (e->flags & EV_EOF) ? 1 : 0;
+	#endif
+}
diff --git a/queue.h b/queue.h
@@ -29,4 +29,6 @@ ssize_t queue_wait(int, queue_event *, size_t);
 int queue_event_get_fd(const queue_event *);
 void *queue_event_get_ptr(const queue_event *);
 
+int queue_event_is_dropped(const queue_event *e);
+
 #endif /* QUEUE_H */