[PATCH] Separate event loop implementation by specific macros
Masashi Honma
masashi.honma
Fri Apr 11 01:33:13 PDT 2014
Is there any comment ?
If this patch is acceptable, I will modify following epoll patch based on this.
2014-04-02 18:52 GMT+09:00 Masashi Honma <masashi.honma at gmail.com>:
> I modified my patch to use CONFIG_ELOOP=eloop_win.
> I hope I understood what you want :).
>
> 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 | 19 +++++++++++----
> wpa_supplicant/android.config | 8 +++----
> wpa_supplicant/defconfig | 8 +++----
> 7 files changed, 62 insertions(+), 42 deletions(-)
>
> diff --git a/hostapd/Makefile b/hostapd/Makefile
> index ac6373e..59c17af 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), eloop_win)
> +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 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/tests/hwsim/example-wpa_supplicant.config b/tests/hwsim/example-wpa_supplicant.config
> index 7a77ac7..ef722bf 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 a60a26a..13cc4b7 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
>
> @@ -1492,7 +1495,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..ba38be0 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
> +
> +ifeq ($(CONFIG_ELOOP), eloop_win)
> OBJS += ../src/utils/$(CONFIG_ELOOP).o
> OBJS_c += ../src/utils/$(CONFIG_ELOOP).o
> +else
> +OBJS += ../src/utils/eloop.o
> +OBJS_c += ../src/utils/eloop.o
>
> -ifeq ($(CONFIG_ELOOP), eloop)
> # 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
> @@ -1510,7 +1515,11 @@ ifdef CONFIG_PRIVSEP
> OBJS_priv += $(OBJS_d) ../src/drivers/drivers.o
> OBJS_priv += $(OBJS_l2)
> OBJS_priv += ../src/utils/os_$(CONFIG_OS).o
> +ifeq ($(CONFIG_ELOOP), eloop_win)
> OBJS_priv += ../src/utils/$(CONFIG_ELOOP).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 ffa2f01..e06c835 100644
> --- a/wpa_supplicant/android.config
> +++ b/wpa_supplicant/android.config
> @@ -244,12 +244,10 @@ CONFIG_BACKEND=file
> 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..710c15c 100644
> --- a/wpa_supplicant/defconfig
> +++ b/wpa_supplicant/defconfig
> @@ -260,12 +260,10 @@ CONFIG_BACKEND=file
> #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