[PATCH] Separate event loop implementation by specific macros
Masashi Honma
masashi.honma
Fri Mar 21 23:16:17 PDT 2014
This patch separates event loop implementation by macros to introduce
following epoll() option.
Signed-off-by: Masashi Honma <masashi.honma at gmail.com>
---
hostapd/Makefile | 15 ++++++++----
src/utils/eloop.c | 39 ++++++++++++++++++-------------
tests/hwsim/example-wpa_supplicant.config | 2 --
wpa_supplicant/Android.mk | 13 +++++++----
wpa_supplicant/Makefile | 25 +++++++++++++-------
wpa_supplicant/android.config | 10 ++++----
wpa_supplicant/defconfig | 10 ++++----
7 files changed, 67 insertions(+), 47 deletions(-)
diff --git a/hostapd/Makefile b/hostapd/Makefile
index 1496888..c681b5f 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -90,12 +90,19 @@ endif
endif
ifndef CONFIG_ELOOP
-CONFIG_ELOOP=eloop
+CONFIG_ELOOP=select
+endif
+OBJS += ../src/utils/eloop.o
+OBJS_c += ../src/utils/eloop.o
+
+ifneq ($(CONFIG_ELOOP), windows)
+ifeq ($(CONFIG_ELOOP), select)
+CFLAGS += -DCONFIG_ELOOP_SELECT
+endif
+ifeq ($(CONFIG_ELOOP), poll)
+CFLAGS += -DCONFIG_ELOOP_POLL
endif
-OBJS += ../src/utils/$(CONFIG_ELOOP).o
-OBJS_c += ../src/utils/$(CONFIG_ELOOP).o
-ifeq ($(CONFIG_ELOOP), eloop)
# Using glibc < 2.17 requires -lrt for clock_gettime()
LIBS += -lrt
LIBS_c += -lrt
diff --git a/src/utils/eloop.c b/src/utils/eloop.c
index f83a232..c4012b3 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)
@@ -399,7 +401,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)
@@ -773,20 +775,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 ||
@@ -802,10 +805,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
@@ -821,7 +825,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);
@@ -832,7 +837,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 */
@@ -858,20 +863,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;
}
@@ -937,7 +943,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)
@@ -946,5 +953,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/tests/hwsim/example-wpa_supplicant.config b/tests/hwsim/example-wpa_supplicant.config
index c603baa..5edd911 100644
--- a/tests/hwsim/example-wpa_supplicant.config
+++ b/tests/hwsim/example-wpa_supplicant.config
@@ -47,8 +47,6 @@ CONFIG_WPA_CLI_EDIT=y
CONFIG_OCSP=y
-#CONFIG_ELOOP_POLL=y
-
#CONFIG_CTRL_IFACE_DBUS=y
#CONFIG_CTRL_IFACE_DBUS_NEW=y
#CONFIG_CTRL_IFACE_DBUS_INTRO=y
diff --git a/wpa_supplicant/Android.mk b/wpa_supplicant/Android.mk
index b8690f5..4d6a7d2 100644
--- a/wpa_supplicant/Android.mk
+++ b/wpa_supplicant/Android.mk
@@ -131,12 +131,15 @@ endif
endif
ifndef CONFIG_ELOOP
-CONFIG_ELOOP=eloop
+CONFIG_ELOOP=select
endif
-OBJS += src/utils/$(CONFIG_ELOOP).c
-OBJS_c += src/utils/$(CONFIG_ELOOP).c
+OBJS += src/utils/eloop.c
+OBJS_c += src/utils/eloop.c
-ifdef CONFIG_ELOOP_POLL
+ifeq ($(CONFIG_ELOOP), select)
+L_CFLAGS += -DCONFIG_ELOOP_SELECT
+endif
+ifeq ($(CONFIG_ELOOP), poll)
L_CFLAGS += -DCONFIG_ELOOP_POLL
endif
@@ -1496,7 +1499,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 ce98068..8dc3850 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -122,22 +122,27 @@ endif
endif
ifndef CONFIG_ELOOP
-CONFIG_ELOOP=eloop
+CONFIG_ELOOP=select
endif
-OBJS += ../src/utils/$(CONFIG_ELOOP).o
-OBJS_c += ../src/utils/$(CONFIG_ELOOP).o
-ifeq ($(CONFIG_ELOOP), eloop)
+ifeq ($(CONFIG_ELOOP), windows)
+OBJS += ../src/utils/eloop_win.o
+OBJS_c += ../src/utils/eloop_win.o
+else
+OBJS += ../src/utils/eloop.o
+OBJS_c += ../src/utils/eloop.o
+
# Using glibc < 2.17 requires -lrt for clock_gettime()
LIBS += -lrt
LIBS_c += -lrt
LIBS_p += -lrt
+ifeq ($(CONFIG_ELOOP), select)
+CFLAGS += -DCONFIG_ELOOP_SELECT
endif
-
-ifdef CONFIG_ELOOP_POLL
+ifeq ($(CONFIG_ELOOP), poll)
CFLAGS += -DCONFIG_ELOOP_POLL
endif
-
+endif
ifdef CONFIG_EAPOL_TEST
CFLAGS += -Werror -DEAPOL_TEST
@@ -1514,7 +1519,11 @@ 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
+ifeq ($(CONFIG_ELOOP), windows)
+OBJS_priv += ../src/utils/eloop_win.o
+else
+OBJS_priv += ../src/utils/eloop.o
+endif
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 184b41e..8fd7624 100644
--- a/wpa_supplicant/android.config
+++ b/wpa_supplicant/android.config
@@ -246,12 +246,10 @@ CONFIG_BACKEND=file
CONFIG_OS=unix
# Select event loop implementation
-# eloop = select() loop (default)
-# 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
+# select = select() loop (default)
+# poll = poll() loop
+# windows = Windows events and WaitForMultipleObject() loop
+CONFIG_ELOOP=select
# Select layer 2 packet implementation
# linux = Linux packet socket (default)
diff --git a/wpa_supplicant/defconfig b/wpa_supplicant/defconfig
index 91eea35..2ba4a98 100644
--- a/wpa_supplicant/defconfig
+++ b/wpa_supplicant/defconfig
@@ -262,12 +262,10 @@ CONFIG_BACKEND=file
#CONFIG_OS=unix
# Select event loop implementation
-# eloop = select() loop (default)
-# 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
+# select = select() loop (default)
+# poll = poll() loop
+# windows = Windows events and WaitForMultipleObject() loop
+#CONFIG_ELOOP=select
# Select layer 2 packet implementation
# linux = Linux packet socket (default)
--
1.8.1.2
More information about the Hostap
mailing list