Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/wpa/dist/src/utils Sync upstream changes for eloop



details:   https://anonhg.NetBSD.org/src/rev/59d3eb5582d1
branches:  trunk
changeset: 343042:59d3eb5582d1
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Jan 20 15:26:13 2016 +0000

description:
Sync upstream changes for eloop

diffstat:

 external/bsd/wpa/dist/src/utils/eloop.c |  58 ++++++++++++++++++++++++++------
 1 files changed, 46 insertions(+), 12 deletions(-)

diffs (144 lines):

diff -r cc522be088c5 -r 59d3eb5582d1 external/bsd/wpa/dist/src/utils/eloop.c
--- a/external/bsd/wpa/dist/src/utils/eloop.c   Wed Jan 20 15:13:33 2016 +0000
+++ b/external/bsd/wpa/dist/src/utils/eloop.c   Wed Jan 20 15:26:13 2016 +0000
@@ -44,8 +44,8 @@
        void *eloop_data;
        void *user_data;
        eloop_sock_handler handler;
-       WPA_TRACE_REF(eloop)
-       WPA_TRACE_REF(user)
+       WPA_TRACE_REF(eloop);
+       WPA_TRACE_REF(user);
        WPA_TRACE_INFO
 };
 
@@ -55,8 +55,8 @@
        void *eloop_data;
        void *user_data;
        eloop_timeout_handler handler;
-       WPA_TRACE_REF(eloop)
-       WPA_TRACE_REF(user)
+       WPA_TRACE_REF(eloop);
+       WPA_TRACE_REF(user);
        WPA_TRACE_INFO
 };
 
@@ -70,11 +70,8 @@
 struct eloop_sock_table {
        int count;
        struct eloop_sock *table;
-#if defined(CONFIG_ELOOP_EPOLL) || defined(CONFIG_ELOOP_KQUEUE)
        eloop_event_type type;
-#else /* CONFIG_ELOOP_EPOLL */
        int changed;
-#endif /* CONFIG_ELOOP_EPOLL */
 };
 
 struct eloop_data {
@@ -302,9 +299,7 @@
        table->table = tmp;
        eloop.max_sock = new_max_sock;
        eloop.count++;
-#if !defined(CONFIG_ELOOP_EPOLL) && !defined(CONFIG_ELOOP_KQUEUE)
        table->changed = 1;
-#endif /* CONFIG_ELOOP_EPOLL */
        eloop_trace_sock_add_ref(table);
 
 #ifdef CONFIG_ELOOP_EPOLL
@@ -383,9 +378,7 @@
        }
        table->count--;
        eloop.count--;
-#if !defined(CONFIG_ELOOP_EPOLL) && !defined(CONFIG_ELOOP_KQUEUE)
        table->changed = 1;
-#endif /* CONFIG_ELOOP_EPOLL */
        eloop_trace_sock_add_ref(table);
 #ifdef CONFIG_ELOOP_EPOLL
        if (epoll_ctl(eloop.epollfd, EPOLL_CTL_DEL, sock, NULL) < 0) {
@@ -601,6 +594,10 @@
                        continue;
                table->handler(table->sock, table->eloop_data,
                               table->user_data);
+               if (eloop.readers.changed ||
+                   eloop.writers.changed ||
+                   eloop.exceptions.changed)
+                       break;
        }
 }
 #endif /* CONFIG_ELOOP_EPOLL */
@@ -618,6 +615,10 @@
                        continue;
                table->handler(table->sock, table->eloop_data,
                               table->user_data);
+               if (eloop.readers.changed ||
+                   eloop.writers.changed ||
+                   eloop.exceptions.changed)
+                       break;
        }
 }
 #endif /* CONFIG_ELOOP_KQUEUE */
@@ -1020,6 +1021,20 @@
               (!dl_list_empty(&eloop.timeout) || eloop.readers.count > 0 ||
                eloop.writers.count > 0 || eloop.exceptions.count > 0)) {
                struct eloop_timeout *timeout;
+
+               if (eloop.pending_terminate) {
+                       /*
+                        * This may happen in some corner cases where a signal
+                        * is received during a blocking operation. We need to
+                        * process the pending signals and exit if requested to
+                        * avoid hitting the SIGALRM limit if the blocking
+                        * operation took more than two seconds.
+                        */
+                       eloop_process_pending_signals();
+                       if (eloop.terminate)
+                               break;
+               }
+
                timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
                                        list);
                if (timeout) {
@@ -1091,8 +1106,14 @@
                                   , strerror(errno));
                        goto out;
                }
+
+               eloop.readers.changed = 0;
+               eloop.writers.changed = 0;
+               eloop.exceptions.changed = 0;
+
                eloop_process_pending_signals();
 
+
                /* check if some registered timeouts have occurred */
                timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
                                        list);
@@ -1112,6 +1133,19 @@
                if (res <= 0)
                        continue;
 
+               if (eloop.readers.changed ||
+                   eloop.writers.changed ||
+                   eloop.exceptions.changed) {
+                        /*
+                         * Sockets may have been closed and reopened with the
+                         * same FD in the signal or timeout handlers, so we
+                         * must skip the previous results and check again
+                         * whether any of the currently registered sockets have
+                         * events.
+                         */
+                       continue;
+               }
+
 #ifdef CONFIG_ELOOP_POLL
                eloop_sock_table_dispatch(&eloop.readers, &eloop.writers,
                                          &eloop.exceptions, eloop.pollfds_map,
@@ -1196,7 +1230,7 @@
 
 int eloop_terminated(void)
 {
-       return eloop.terminate;
+       return eloop.terminate || eloop.pending_terminate;
 }
 
 



Home | Main Index | Thread Index | Old Index