commit 3281308ec18b9a18ac2250a9f841a8906218f7ec
parent 39bc8f5c76f844e56a04d5993ccfee9f2b41d17e
Author: Christian Grothoff <christian@grothoff.org>
Date: Sun, 4 Sep 2016 15:16:58 +0000
also add tests for external select/epoll for connection upgrades
Diffstat:
4 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
@@ -1323,6 +1323,7 @@ enum MHD_DaemonInfoType
* No extra arguments should be passed.
*/
MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY,
+ MHD_DAEMON_INFO_EPOLL_FD = MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY,
/**
* Request the number of current connections handled by the daemon.
@@ -2695,7 +2696,7 @@ union MHD_DaemonInfo
size_t mac_key_size;
/**
- * Listen socket file descriptor, for #MHD_DAEMON_INFO_EPOLL_FD_LINUX_ONLY
+ * Socket, returned for #MHD_DAEMON_INFO_EPOLL_FD
* and #MHD_DAEMON_INFO_LISTEN_FD.
*/
MHD_socket listen_fd;
diff --git a/src/microhttpd/test_upgrade.c b/src/microhttpd/test_upgrade.c
@@ -56,6 +56,7 @@ test_upgrade (int flags,
MHD_socket sock;
struct sockaddr_in sa;
+ done = 0;
if (0 == (flags & MHD_USE_THREAD_PER_CONNECTION))
flags |= MHD_USE_SUSPEND_RESUME;
d = MHD_start_daemon (flags | MHD_USE_DEBUG,
@@ -101,6 +102,10 @@ main (int argc,
/* try external select */
error_count += test_upgrade (0,
0);
+#ifdef EPOLL_SUPPORT
+ error_count += test_upgrade (MHD_USE_EPOLL,
+ 0);
+#endif
/* Test thread-per-connection */
error_count += test_upgrade (MHD_USE_THREAD_PER_CONNECTION,
@@ -125,7 +130,6 @@ main (int argc,
error_count += test_upgrade (MHD_USE_EPOLL_INTERNALLY,
2);
#endif
-
/* report result */
if (0 != error_count)
fprintf (stderr,
diff --git a/src/microhttpd/test_upgrade_common.c b/src/microhttpd/test_upgrade_common.c
@@ -413,7 +413,7 @@ run_mhd_select_loop (struct MHD_Daemon *daemon)
static void
run_mhd_poll_loop (struct MHD_Daemon *daemon)
{
- abort (); // not implemented
+ abort (); /* currently not implementable with existing MHD API */
}
@@ -426,7 +426,32 @@ run_mhd_poll_loop (struct MHD_Daemon *daemon)
static void
run_mhd_epoll_loop (struct MHD_Daemon *daemon)
{
- abort (); // not implemented
+ const union MHD_DaemonInfo *di;
+ MHD_socket ep;
+ fd_set rs;
+ MHD_UNSIGNED_LONG_LONG to;
+ struct timeval tv;
+
+ di = MHD_get_daemon_info (daemon,
+ MHD_DAEMON_INFO_EPOLL_FD);
+ ep = di->listen_fd;
+ while (! done)
+ {
+ FD_ZERO (&rs);
+ to = 1000;
+
+ FD_SET (ep, &rs);
+ MHD_get_timeout (daemon,
+ &to);
+ tv.tv_sec = to / 1000;
+ tv.tv_usec = 1000 * (to % 1000);
+ select (ep + 1,
+ &rs,
+ NULL,
+ NULL,
+ &tv);
+ MHD_run (daemon);
+ }
}
diff --git a/src/microhttpd/test_upgrade_ssl.c b/src/microhttpd/test_upgrade_ssl.c
@@ -108,6 +108,7 @@ test_upgrade (int flags,
MHD_socket sock;
pid_t pid;
+ done = 0;
if (0 == (flags & MHD_USE_THREAD_PER_CONNECTION))
flags |= MHD_USE_SUSPEND_RESUME;
d = MHD_start_daemon (flags | MHD_USE_DEBUG | MHD_USE_TLS,
@@ -160,6 +161,10 @@ main (int argc,
/* try external select */
error_count += test_upgrade (0,
0);
+#ifdef EPOLL_SUPPORT
+ error_count += test_upgrade (MHD_USE_TLS_EPOLL_UPGRADE,
+ 0);
+#endif
/* Test thread-per-connection */
error_count += test_upgrade (MHD_USE_THREAD_PER_CONNECTION,