From 78ed0c58cfe0a80d529e52a29dda8f902ce2d44a Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Fri, 9 Jun 2006 19:33:43 +0000
Subject: [PATCH] Handle I/O for OSX, can't process stdin without polling.

---
 src/common/eio.c | 55 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 45 insertions(+), 10 deletions(-)

diff --git a/src/common/eio.c b/src/common/eio.c
index ac7cb76a24f..f29f3d4a555 100644
--- a/src/common/eio.c
+++ b/src/common/eio.c
@@ -285,20 +285,55 @@ _poll_dispatch(struct pollfd *pfds, unsigned int nfds, eio_obj_t *map[],
 static void
 _poll_handle_event(short revents, eio_obj_t *obj, List objList)
 {
-	if ((revents & POLLERR ) && obj->ops->handle_error) {
-		if ((*obj->ops->handle_error) (obj, objList) < 0) 
-			return;
+	if (revents & POLLNVAL) {
+		debug("POLLNVAL on fd %d, shutting down eio object", obj->fd);
+		obj->shutdown = true;
+		return;
+	}
+
+	if (revents & POLLERR) {
+		if (obj->ops->handle_error) {
+			(*obj->ops->handle_error) (obj, objList);
+		} else if (obj->ops->handle_read) {
+			(*obj->ops->handle_read) (obj, objList);
+		} else if (obj->ops->handle_write) {
+			(*obj->ops->handle_write) (obj, objList);
+		} else {
+			debug("No handler for POLLERR");
+			obj->shutdown = true;
+		}
+		return;
+	}
+
+	if (revents & POLLHUP) {
+		if (obj->ops->handle_close) {
+			(*obj->ops->handle_close) (obj, objList);
+		} else if (obj->ops->handle_read) {
+			(*obj->ops->handle_read) (obj, objList);
+		} else if (obj->ops->handle_write) {
+			(*obj->ops->handle_write) (obj, objList);
+		} else {
+			debug("No handler for POLLHUP");
+			obj->shutdown = true;
+		}
 	}
 
-	if ((revents & POLLHUP) && obj->ops->handle_close) {
-		(*obj->ops->handle_close) (obj, objList);
-	} else if (((revents & POLLIN) || (revents & POLLHUP)) 
-	    && obj->ops->handle_read ) {
-		(*obj->ops->handle_read ) (obj, objList);
+	if (revents & POLLIN) {
+		if (obj->ops->handle_read) {
+			(*obj->ops->handle_read ) (obj, objList);
+		} else {
+			debug("No handler for POLLIN");
+			obj->shutdown = true;
+		}
 	}
 
-	if ((revents & POLLOUT) && obj->ops->handle_write) {
-		(*obj->ops->handle_write) (obj, objList);
+	if (revents & POLLOUT) {
+		if (obj->ops->handle_write) {
+			(*obj->ops->handle_write) (obj, objList);
+		} else {
+			debug("No handler for POLLOUT");
+			obj->shutdown = true;
+		}
 	}
 }
 
-- 
GitLab