Lines Matching refs:eloop
14 #include "eloop.h"
72 static struct eloop_data eloop;
77 os_memset(&eloop, 0, sizeof(eloop));
78 dl_list_init(&eloop.timeout);
79 eloop.num_handles = 1;
80 eloop.handles = os_malloc(eloop.num_handles *
81 sizeof(eloop.handles[0]));
82 if (eloop.handles == NULL)
85 eloop.term_event = CreateEvent(NULL, FALSE, FALSE, NULL);
86 if (eloop.term_event == NULL) {
89 os_free(eloop.handles);
101 if (eloop.num_handles > eloop.reader_count + eloop.event_count + 8)
103 n = os_realloc_array(eloop.handles, eloop.num_handles * 2,
104 sizeof(eloop.handles[0]));
107 eloop.handles = n;
108 eloop.num_handles *= 2;
133 tmp = os_realloc_array(eloop.readers, eloop.reader_count + 1,
141 tmp[eloop.reader_count].sock = sock;
142 tmp[eloop.reader_count].eloop_data = eloop_data;
143 tmp[eloop.reader_count].user_data = user_data;
144 tmp[eloop.reader_count].handler = handler;
145 tmp[eloop.reader_count].event = event;
146 eloop.reader_count++;
147 eloop.readers = tmp;
148 if (sock > eloop.max_sock)
149 eloop.max_sock = sock;
150 eloop.reader_table_changed = 1;
160 if (eloop.readers == NULL || eloop.reader_count == 0)
163 for (i = 0; i < eloop.reader_count; i++) {
164 if (eloop.readers[i].sock == sock)
167 if (i == eloop.reader_count)
170 WSAEventSelect(eloop.readers[i].sock, eloop.readers[i].event, 0);
171 WSACloseEvent(eloop.readers[i].event);
173 if (i != eloop.reader_count - 1) {
174 os_memmove(&eloop.readers[i], &eloop.readers[i + 1],
175 (eloop.reader_count - i - 1) *
178 eloop.reader_count--;
179 eloop.reader_table_changed = 1;
196 tmp = os_realloc_array(eloop.events, eloop.event_count + 1,
201 tmp[eloop.event_count].eloop_data = eloop_data;
202 tmp[eloop.event_count].user_data = user_data;
203 tmp[eloop.event_count].handler = handler;
204 tmp[eloop.event_count].event = h;
205 eloop.event_count++;
206 eloop.events = tmp;
217 if (eloop.events == NULL || eloop.event_count == 0 ||
221 for (i = 0; i < eloop.event_count; i++) {
222 if (eloop.events[i].event == h)
225 if (i == eloop.event_count)
228 if (i != eloop.event_count - 1) {
229 os_memmove(&eloop.events[i], &eloop.events[i + 1],
230 (eloop.event_count - i - 1) *
233 eloop.event_count--;
258 wpa_printf(MSG_DEBUG, "ELOOP: Too long timeout (secs=%u) to "
273 dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
279 dl_list_add_tail(&eloop.timeout, &timeout->list);
298 dl_list_for_each_safe(timeout, prev, &eloop.timeout,
325 dl_list_for_each_safe(timeout, prev, &eloop.timeout,
346 dl_list_for_each(tmp, &eloop.timeout, struct eloop_timeout, list) {
363 eloop.signaled++;
364 for (i = 0; i < eloop.signal_count; i++) {
365 if (eloop.signals[i].sig == sig) {
366 eloop.signals[i].signaled++;
378 if (eloop.signaled == 0)
380 eloop.signaled = 0;
382 if (eloop.pending_terminate) {
383 eloop.pending_terminate = 0;
386 for (i = 0; i < eloop.signal_count; i++) {
387 if (eloop.signals[i].signaled) {
388 eloop.signals[i].signaled = 0;
389 eloop.signals[i].handler(eloop.signals[i].sig,
390 eloop.signals[i].user_data);
394 if (eloop.term_signal.signaled) {
395 eloop.term_signal.signaled = 0;
396 eloop.term_signal.handler(eloop.term_signal.sig,
397 eloop.term_signal.user_data);
407 tmp = os_realloc_array(eloop.signals, eloop.signal_count + 1,
412 tmp[eloop.signal_count].sig = sig;
413 tmp[eloop.signal_count].user_data = user_data;
414 tmp[eloop.signal_count].handler = handler;
415 tmp[eloop.signal_count].signaled = 0;
416 eloop.signal_count++;
417 eloop.signals = tmp;
431 eloop.signaled++;
432 eloop.term_signal.signaled++;
433 SetEvent(eloop.term_event);
454 eloop.term_signal.handler = handler;
455 eloop.term_signal.user_data = user_data;
475 while (!eloop.terminate &&
476 (!dl_list_empty(&eloop.timeout) || eloop.reader_count > 0 ||
477 eloop.event_count > 0)) {
480 timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
489 for (i = 0; i < eloop.event_count; i++)
490 eloop.handles[count++] = eloop.events[i].event;
492 for (i = 0; i < eloop.reader_count; i++)
493 eloop.handles[count++] = eloop.readers[i].event;
495 if (eloop.term_event)
496 eloop.handles[count++] = eloop.term_event;
510 ret = WaitForMultipleObjects(count, eloop.handles, FALSE,
513 ret = WaitForMultipleObjectsEx(count, eloop.handles, FALSE,
521 timeout = dl_list_first(&eloop.timeout, struct eloop_timeout,
552 ret < WAIT_OBJECT_0 + eloop.event_count) {
553 eloop.events[ret].handler(
554 eloop.events[ret].eloop_data,
555 eloop.events[ret].user_data);
556 ret = WaitForMultipleObjects(eloop.event_count,
557 eloop.handles, FALSE, 0);
560 eloop.reader_table_changed = 0;
561 for (i = 0; i < eloop.reader_count; i++) {
563 if (WSAEnumNetworkEvents(eloop.readers[i].sock,
564 eloop.readers[i].event,
567 eloop.readers[i].handler(
568 eloop.readers[i].sock,
569 eloop.readers[i].eloop_data,
570 eloop.readers[i].user_data);
571 if (eloop.reader_table_changed)
581 eloop.terminate = 1;
582 SetEvent(eloop.term_event);
590 dl_list_for_each_safe(timeout, prev, &eloop.timeout,
594 os_free(eloop.readers);
595 os_free(eloop.signals);
596 if (eloop.term_event)
597 CloseHandle(eloop.term_event);
598 os_free(eloop.handles);
599 eloop.handles = NULL;
600 os_free(eloop.events);
601 eloop.events = NULL;
607 return eloop.terminate;