[PATCH 06/13] mghttpd: Use poll() replacement.

Christian Mauderer christian.mauderer at embedded-brains.de
Thu Apr 21 08:49:46 UTC 2016


From: Christian Mauderer <Christian.Mauderer at embedded-brains.de>

This patch provides a poll() replacement based on the poll() used for
civetweb on windows.

A similar patch based on the one on
http://forums.bannister.org/ubbthreads.php?ubb=showflat&topic=7600&gonew=1
had been integrated into the RTEMS version of mongoose in commit
b5d2d4a61ce91765e9cac1b02271a8f4b049c558.
---
 cpukit/mghttpd/civetweb.c | 93 +++++++++++++++++++++++------------------------
 1 file changed, 46 insertions(+), 47 deletions(-)

diff --git a/cpukit/mghttpd/civetweb.c b/cpukit/mghttpd/civetweb.c
index 32cee56..5c5cd72 100644
--- a/cpukit/mghttpd/civetweb.c
+++ b/cpukit/mghttpd/civetweb.c
@@ -376,17 +376,6 @@ typedef struct DIR {
 	struct dirent result;
 } DIR;
 
-#if defined(_WIN32) && !defined(POLLIN)
-#ifndef HAVE_POLL
-struct pollfd {
-	SOCKET fd;
-	short events;
-	short revents;
-};
-#define POLLIN (0x0300)
-#endif
-#endif
-
 /* Mark required libraries */
 #if defined(_MSC_VER)
 #pragma comment(lib, "Ws2_32.lib")
@@ -397,7 +386,9 @@ struct pollfd {
 
 #include <sys/wait.h>
 #include <sys/socket.h>
+#ifdef HAVE_POLL
 #include <sys/poll.h>
+#endif
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/time.h>
@@ -467,6 +458,15 @@ typedef int SOCKET;
 #endif /* defined(_WIN32) && !defined(__SYMBIAN32__) - WINDOWS / UNIX include  \
           block */
 
+#ifndef HAVE_POLL
+struct pollfd {
+	SOCKET fd;
+	short events;
+	short revents;
+};
+#define POLLIN (0x0300)
+#endif
+
 /* va_copy should always be a macro, C99 and C++11 - DTL */
 #ifndef va_copy
 #define va_copy(x, y) ((x) = (y))
@@ -3096,42 +3096,6 @@ readdir(DIR *dir)
 }
 
 
-#ifndef HAVE_POLL
-static int
-poll(struct pollfd *pfd, unsigned int n, int milliseconds)
-{
-	struct timeval tv;
-	fd_set set;
-	unsigned int i;
-	int result;
-	SOCKET maxfd = 0;
-
-	memset(&tv, 0, sizeof(tv));
-	tv.tv_sec = milliseconds / 1000;
-	tv.tv_usec = (milliseconds % 1000) * 1000;
-	FD_ZERO(&set);
-
-	for (i = 0; i < n; i++) {
-		FD_SET((SOCKET)pfd[i].fd, &set);
-		pfd[i].revents = 0;
-
-		if (pfd[i].fd > maxfd) {
-			maxfd = pfd[i].fd;
-		}
-	}
-
-	if ((result = select((int)maxfd + 1, &set, NULL, NULL, &tv)) > 0) {
-		for (i = 0; i < n; i++) {
-			if (FD_ISSET(pfd[i].fd, &set)) {
-				pfd[i].revents = POLLIN;
-			}
-		}
-	}
-
-	return result;
-}
-#endif /* HAVE_POLL */
-
 #if defined(__MINGW32__)
 /* Enable unused function warning again */
 #pragma GCC diagnostic pop
@@ -3637,6 +3601,41 @@ set_non_blocking_mode(SOCKET sock)
 #endif /* _WIN32 */
 /* End of initial operating system specific define block. */
 
+#ifndef HAVE_POLL
+static int
+poll(struct pollfd *pfd, unsigned int n, int milliseconds)
+{
+	struct timeval tv;
+	fd_set set;
+	unsigned int i;
+	int result;
+	SOCKET maxfd = 0;
+
+	memset(&tv, 0, sizeof(tv));
+	tv.tv_sec = milliseconds / 1000;
+	tv.tv_usec = (milliseconds % 1000) * 1000;
+	FD_ZERO(&set);
+
+	for (i = 0; i < n; i++) {
+		FD_SET((SOCKET)pfd[i].fd, &set);
+		pfd[i].revents = 0;
+
+		if (pfd[i].fd > maxfd) {
+			maxfd = pfd[i].fd;
+		}
+	}
+
+	if ((result = select((int)maxfd + 1, &set, NULL, NULL, &tv)) > 0) {
+		for (i = 0; i < n; i++) {
+			if (FD_ISSET(pfd[i].fd, &set)) {
+				pfd[i].revents = POLLIN;
+			}
+		}
+	}
+
+	return result;
+}
+#endif /* HAVE_POLL */
 
 /* Get a random number (independent of C rand function) */
 static uint64_t
-- 
1.8.4.5



More information about the devel mailing list