[PATCH] Separate event loop implementation by specific macros

Masashi Honma masashi.honma
Sun Apr 20 01:23:03 PDT 2014


This patch separates event loop implementation by macros to introduce
following epoll() option.

> Close, but I wanted to switch it the other way around, i.e., the
> CONFIG_ELOOP=<arbitrary name> should work for all other cases than
> eloop.c and not just that eloop_win.c (i.e., for any version that is not
> included in this repository as well). In addition, CONFIG_ELOOP_POLL=y
> should remain to work like it used to work before.

OK, I considered backward compatibility.
If CONFIG_ELOOP=eloop, CONFIG_ELOOP_POLL should be worked. Because eloop is
traditional value and backward compatibility is required.

If CONFIG_ELOOP=select/poll/epoll, CONFIG_ELOOP_POLL should be ignored.
Because select/poll/epoll are new value and backward compatibility is not
required.

This is a table of the policy.
+--------------+-------------+-------------+
|              |     CONFIG_ELOOP_POLL     |
+--------------+-------------+-------------+
| CONFIG_ELOOP | (undefined) |      Y      |
+==============+=============+=============+
| (undefined)  | eloop.c     | eloop.c     |
|              | select      | poll        |
+--------------+-------------+-------------+
| eloop        | eloop.c     | eloop.c     |
|              | select      | poll        |
+--------------+-------------+-------------+
| eloop_win    | eloop_win.c | eloop_win.c |
|              |             |             |
+--------------+-------------+-------------+
| select       | eloop.c     | eloop.c     |
|              | select      | select      |
+--------------+-------------+-------------+
| poll         | eloop.c     | eloop.c     |
|              | poll        | poll        |
+--------------+-------------+-------------+
| epoll        | eloop.c     | eloop.c     |
|              | epoll       | epoll       |
+--------------+-------------+-------------+

Signed-off-by: Masashi Honma <masashi.honma at gmail.com>
---
 hostapd/Makefile              | 33 ++++++++++++++++++++++++++++-----
 src/utils/eloop.c             | 39 +++++++++++++++++++++++----------------
 wpa_supplicant/Android.mk     | 27 +++++++++++++++++++++------
 wpa_supplicant/Makefile       | 40 ++++++++++++++++++++++++++++++----------
 wpa_supplicant/android.config | 10 ++++------
 wpa_supplicant/defconfig      | 10 ++++------
 6 files changed, 110 insertions(+), 49 deletions(-)

diff --git a/hostapd/Makefile b/hostapd/Makefile
index ac6373e..dceccc3 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -89,20 +89,43 @@ LIBS_h += -lbfd -ldl -liberty -lz
 endif
 endif
 
-ifndef CONFIG_ELOOP
-CONFIG_ELOOP=eloop
+ifdef CONFIG_ELOOP
+ifeq ($(CONFIG_ELOOP), eloop)
+ifdef CONFIG_ELOOP_POLL
+CONFIG_ELOOP=poll
+else
+CONFIG_ELOOP=select
+endif
+endif
+else
+ifdef CONFIG_ELOOP_POLL
+CONFIG_ELOOP=poll
+else
+CONFIG_ELOOP=select
+endif
 endif
-OBJS += ../src/utils/$(CONFIG_ELOOP).o
-OBJS_c += ../src/utils/$(CONFIG_ELOOP).o
 
-ifeq ($(CONFIG_ELOOP), eloop)
+ifeq ($(CONFIG_ELOOP), select)
+CFLAGS += -DCONFIG_ELOOP_SELECT
+ELOOP_SHARED=y
+endif
+ifeq ($(CONFIG_ELOOP), poll)
+CFLAGS += -DCONFIG_ELOOP_POLL
+ELOOP_SHARED=y
+endif
+
+ifdef ELOOP_SHARED
 # Using glibc < 2.17 requires -lrt for clock_gettime()
 LIBS += -lrt
 LIBS_c += -lrt
 LIBS_h += -lrt
 LIBS_n += -lrt
+ELOOP_FILE=eloop
 endif
 
+OBJS += ../src/utils/$(ELOOP_FILE).o
+OBJS_c += ../src/utils/$(ELOOP_FILE).o
+
 OBJS += ../src/utils/common.o
 OBJS += ../src/utils/wpa_debug.o
 OBJS_c += ../src/utils/wpa_debug.o
diff --git a/src/utils/eloop.c b/src/utils/eloop.c
index 2667c8c..fa7cb81 100644
--- a/src/utils/eloop.c
+++ b/src/utils/eloop.c
@@ -362,7 +362,9 @@ static void eloop_sock_table_dispatch(struct eloop_sock_table *readers,
 					max_pollfd_map, POLLERR | POLLHUP);
 }
 
-#else /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_POLL */
+
+#ifdef CONFIG_ELOOP_SELECT
 
 static void eloop_sock_table_set_fds(struct eloop_sock_table *table,
 				     fd_set *fds)
@@ -401,7 +403,7 @@ static void eloop_sock_table_dispatch(struct eloop_sock_table *table,
 	}
 }
 
-#endif /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_SELECT */
 
 
 static void eloop_sock_table_destroy(struct eloop_sock_table *table)
@@ -776,20 +778,21 @@ void eloop_run(void)
 #ifdef CONFIG_ELOOP_POLL
 	int num_poll_fds;
 	int timeout_ms = 0;
-#else /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_POLL */
+#ifdef CONFIG_ELOOP_SELECT
 	fd_set *rfds, *wfds, *efds;
 	struct timeval _tv;
-#endif /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_SELECT */
 	int res;
 	struct os_reltime tv, now;
 
-#ifndef CONFIG_ELOOP_POLL
+#ifdef CONFIG_ELOOP_SELECT
 	rfds = os_malloc(sizeof(*rfds));
 	wfds = os_malloc(sizeof(*wfds));
 	efds = os_malloc(sizeof(*efds));
 	if (rfds == NULL || wfds == NULL || efds == NULL)
 		goto out;
-#endif /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_SELECT */
 
 	while (!eloop.terminate &&
 	       (!dl_list_empty(&eloop.timeout) || eloop.readers.count > 0 ||
@@ -805,10 +808,11 @@ void eloop_run(void)
 				tv.sec = tv.usec = 0;
 #ifdef CONFIG_ELOOP_POLL
 			timeout_ms = tv.sec * 1000 + tv.usec / 1000;
-#else /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_POLL */
+#ifdef CONFIG_ELOOP_SELECT
 			_tv.tv_sec = tv.sec;
 			_tv.tv_usec = tv.usec;
-#endif /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_SELECT */
 		}
 
 #ifdef CONFIG_ELOOP_POLL
@@ -824,7 +828,8 @@ void eloop_run(void)
 				   strerror(errno));
 			goto out;
 		}
-#else /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_POLL */
+#ifdef CONFIG_ELOOP_SELECT
 		eloop_sock_table_set_fds(&eloop.readers, rfds);
 		eloop_sock_table_set_fds(&eloop.writers, wfds);
 		eloop_sock_table_set_fds(&eloop.exceptions, efds);
@@ -835,7 +840,7 @@ void eloop_run(void)
 				   strerror(errno));
 			goto out;
 		}
-#endif /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_SELECT */
 		eloop_process_pending_signals();
 
 		/* check if some registered timeouts have occurred */
@@ -861,20 +866,21 @@ void eloop_run(void)
 		eloop_sock_table_dispatch(&eloop.readers, &eloop.writers,
 					  &eloop.exceptions, eloop.pollfds_map,
 					  eloop.max_pollfd_map);
-#else /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_POLL */
+#ifdef CONFIG_ELOOP_SELECT
 		eloop_sock_table_dispatch(&eloop.readers, rfds);
 		eloop_sock_table_dispatch(&eloop.writers, wfds);
 		eloop_sock_table_dispatch(&eloop.exceptions, efds);
-#endif /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_SELECT */
 	}
 
 	eloop.terminate = 0;
 out:
-#ifndef CONFIG_ELOOP_POLL
+#ifdef CONFIG_ELOOP_SELECT
 	os_free(rfds);
 	os_free(wfds);
 	os_free(efds);
-#endif /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_SELECT */
 	return;
 }
 
@@ -940,7 +946,8 @@ void eloop_wait_for_read_sock(int sock)
 	pfd.events = POLLIN;
 
 	poll(&pfd, 1, -1);
-#else /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_POLL */
+#ifdef CONFIG_ELOOP_SELECT
 	fd_set rfds;
 
 	if (sock < 0)
@@ -949,5 +956,5 @@ void eloop_wait_for_read_sock(int sock)
 	FD_ZERO(&rfds);
 	FD_SET(sock, &rfds);
 	select(sock + 1, &rfds, NULL, NULL, NULL);
-#endif /* CONFIG_ELOOP_POLL */
+#endif /* CONFIG_ELOOP_SELECT */
 }
diff --git a/wpa_supplicant/Android.mk b/wpa_supplicant/Android.mk
index a60a26a..268e48d 100644
--- a/wpa_supplicant/Android.mk
+++ b/wpa_supplicant/Android.mk
@@ -130,13 +130,28 @@ LIBS_c += -lbfd
 endif
 endif
 
-ifndef CONFIG_ELOOP
-CONFIG_ELOOP=eloop
+ifdef CONFIG_ELOOP
+ifeq ($(CONFIG_ELOOP), eloop)
+ifdef CONFIG_ELOOP_POLL
+CONFIG_ELOOP=poll
+else
+CONFIG_ELOOP=select
 endif
-OBJS += src/utils/$(CONFIG_ELOOP).c
-OBJS_c += src/utils/$(CONFIG_ELOOP).c
-
+endif
+else
 ifdef CONFIG_ELOOP_POLL
+CONFIG_ELOOP=poll
+else
+CONFIG_ELOOP=select
+endif
+endif
+OBJS += src/utils/eloop.c
+OBJS_c += src/utils/eloop.c
+
+ifeq ($(CONFIG_ELOOP), select)
+L_CFLAGS += -DCONFIG_ELOOP_SELECT
+endif
+ifeq ($(CONFIG_ELOOP), poll)
 L_CFLAGS += -DCONFIG_ELOOP_POLL
 endif
 
@@ -1492,7 +1507,7 @@ ifdef CONFIG_PRIVSEP
 OBJS_priv += $(OBJS_d) src/drivers/drivers.c
 OBJS_priv += $(OBJS_l2)
 OBJS_priv += src/utils/os_$(CONFIG_OS).c
-OBJS_priv += src/utils/$(CONFIG_ELOOP).c
+OBJS_priv += src/utils/eloop.c
 OBJS_priv += src/utils/common.c
 OBJS_priv += src/utils/wpa_debug.c
 OBJS_priv += src/utils/wpabuf.c
diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index 19dae70..0a68f9b 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -121,23 +121,43 @@ LIBS_c += -lbfd -ldl -liberty -lz
 endif
 endif
 
-ifndef CONFIG_ELOOP
-CONFIG_ELOOP=eloop
+ifdef CONFIG_ELOOP
+ifeq ($(CONFIG_ELOOP), eloop)
+ifdef CONFIG_ELOOP_POLL
+CONFIG_ELOOP=poll
+else
+CONFIG_ELOOP=select
+endif
+endif
+else
+ifdef CONFIG_ELOOP_POLL
+CONFIG_ELOOP=poll
+else
+CONFIG_ELOOP=select
+endif
 endif
-OBJS += ../src/utils/$(CONFIG_ELOOP).o
-OBJS_c += ../src/utils/$(CONFIG_ELOOP).o
 
-ifeq ($(CONFIG_ELOOP), eloop)
+ifeq ($(CONFIG_ELOOP), select)
+CFLAGS += -DCONFIG_ELOOP_SELECT
+ELOOP_SHARED=y
+endif
+ifeq ($(CONFIG_ELOOP), poll)
+CFLAGS += -DCONFIG_ELOOP_POLL
+ELOOP_SHARED=y
+endif
+
+ifdef ELOOP_SHARED
 # Using glibc < 2.17 requires -lrt for clock_gettime()
 LIBS += -lrt
 LIBS_c += -lrt
 LIBS_p += -lrt
+ELOOP_FILE=eloop
+else
+ELOOP_FILE=$(CONFIG_ELOOP)
 endif
 
-ifdef CONFIG_ELOOP_POLL
-CFLAGS += -DCONFIG_ELOOP_POLL
-endif
-
+OBJS += ../src/utils/$(ELOOP_FILE).o
+OBJS_c += ../src/utils/$(ELOOP_FILE).o
 
 ifdef CONFIG_EAPOL_TEST
 CFLAGS += -Werror -DEAPOL_TEST
@@ -1510,7 +1530,7 @@ ifdef CONFIG_PRIVSEP
 OBJS_priv += $(OBJS_d) ../src/drivers/drivers.o
 OBJS_priv += $(OBJS_l2)
 OBJS_priv += ../src/utils/os_$(CONFIG_OS).o
-OBJS_priv += ../src/utils/$(CONFIG_ELOOP).o
+OBJS_priv += ../src/utils/$(ELOOP_FILE).o
 OBJS_priv += ../src/utils/common.o
 OBJS_priv += ../src/utils/wpa_debug.o
 OBJS_priv += ../src/utils/wpabuf.o
diff --git a/wpa_supplicant/android.config b/wpa_supplicant/android.config
index ffa2f01..7f2fe9e 100644
--- a/wpa_supplicant/android.config
+++ b/wpa_supplicant/android.config
@@ -237,19 +237,17 @@ CONFIG_BACKEND=file
 # main_none = Very basic example (development use only)
 #CONFIG_MAIN=main
 
-# Select wrapper for operatins system and C library specific functions
+# Select wrapper for operating system and C library specific functions
 # unix = UNIX/POSIX like systems (default)
 # win32 = Windows systems
 # none = Empty template
 CONFIG_OS=unix
 
 # Select event loop implementation
-# eloop = select() loop (default)
+# select = select() loop (default)
+# poll = poll() loop
 # eloop_win = Windows events and WaitForMultipleObject() loop
-CONFIG_ELOOP=eloop
-
-# Should we use poll instead of select? Select is used by default.
-#CONFIG_ELOOP_POLL=y
+#CONFIG_ELOOP=select
 
 # Select layer 2 packet implementation
 # linux = Linux packet socket (default)
diff --git a/wpa_supplicant/defconfig b/wpa_supplicant/defconfig
index d194eb8..2a1cfa3 100644
--- a/wpa_supplicant/defconfig
+++ b/wpa_supplicant/defconfig
@@ -253,19 +253,17 @@ CONFIG_BACKEND=file
 # main_none = Very basic example (development use only)
 #CONFIG_MAIN=main
 
-# Select wrapper for operatins system and C library specific functions
+# Select wrapper for operating system and C library specific functions
 # unix = UNIX/POSIX like systems (default)
 # win32 = Windows systems
 # none = Empty template
 #CONFIG_OS=unix
 
 # Select event loop implementation
-# eloop = select() loop (default)
+# select = select() loop (default)
+# poll = poll() loop
 # eloop_win = Windows events and WaitForMultipleObject() loop
-#CONFIG_ELOOP=eloop
-
-# Should we use poll instead of select? Select is used by default.
-#CONFIG_ELOOP_POLL=y
+#CONFIG_ELOOP=select
 
 # Select layer 2 packet implementation
 # linux = Linux packet socket (default)
-- 
1.8.1.2




More information about the Hostap mailing list