2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
10 # define WIN32_LEAN_AND_MEAN
11 # include <winsock2.h>
12 # undef WIN32_LEAN_AND_MEAN
13 # ifndef USER_TIMER_MINIMUM
14 # define USER_TIMER_MINIMUM 0x0a
26 #include <sys/types.h>
41 # include <sys/param.h>
53 #include "ecore_private.h"
56 struct _Ecore_Fd_Handler
61 Ecore_Fd_Handler_Flags flags;
62 int (*func) (void *data, Ecore_Fd_Handler *fd_handler);
64 int (*buf_func) (void *data, Ecore_Fd_Handler *fd_handler);
66 void (*prep_func) (void *data, Ecore_Fd_Handler *fd_handler);
69 Eina_Bool read_active : 1;
70 Eina_Bool write_active : 1;
71 Eina_Bool error_active : 1;
72 Eina_Bool delete_me : 1;
76 struct _Ecore_Win32_Handler
81 int (*func) (void *data, Ecore_Win32_Handler *win32_handler);
84 Eina_Bool delete_me : 1;
89 static int _ecore_main_select(double timeout);
90 static void _ecore_main_fd_handlers_cleanup(void);
92 static void _ecore_main_fd_handlers_bads_rem(void);
94 static void _ecore_main_fd_handlers_call(void);
95 static int _ecore_main_fd_handlers_buf_call(void);
96 static void _ecore_main_loop_iterate_internal(int once_only);
99 static int _ecore_main_win32_select(int nfds, fd_set *readfds, fd_set *writefds,
100 fd_set *exceptfds, struct timeval *timeout);
101 static void _ecore_main_win32_handlers_cleanup(void);
104 static int in_main_loop = 0;
105 static int do_quit = 0;
106 static Ecore_Fd_Handler *fd_handlers = NULL;
107 static Ecore_Fd_Handler *fd_handler_current = NULL;
108 static int fd_handlers_delete_me = 0;
110 static Ecore_Win32_Handler *win32_handlers = NULL;
111 static Ecore_Win32_Handler *win32_handler_current = NULL;
112 static int win32_handlers_delete_me = 0;
116 static int (*main_loop_select)(int , fd_set *, fd_set *, fd_set *, struct timeval *) = _ecore_main_win32_select;
118 static int (*main_loop_select)(int , fd_set *, fd_set *, fd_set *, struct timeval *) = select;
121 static double t1 = 0.0;
122 static double t2 = 0.0;
125 * @defgroup Ecore_Main_Loop_Group Main Loop Functions
127 * These functions control the Ecore event handling loop. This loop is
128 * designed to work on embedded systems all the way to large and
129 * powerful mutli-cpu workstations.
131 * It serialises all system signals and events into a single event
132 * queue, that can be easily processed without needing to worry about
133 * concurrency. A properly written, event-driven program using this
134 * kind of programming does not need threads. It makes the program very
135 * robust and easy to follow.
137 * Here is an example of simple program and its basic event loop flow:
138 * @image html prog_flow.png
140 * For examples of setting up and using a main loop, see
141 * @ref event_handler_example.c and @ref timer_example.c.
145 * Runs a single iteration of the main loop to process everything on the
147 * @ingroup Ecore_Main_Loop_Group
150 ecore_main_loop_iterate(void)
152 _ecore_main_loop_iterate_internal(1);
156 * Runs the application main loop.
158 * This function will not return until @ref ecore_main_loop_quit is called.
160 * @ingroup Ecore_Main_Loop_Group
163 ecore_main_loop_begin(void)
166 for (;do_quit == 0;) _ecore_main_loop_iterate_internal(0);
172 * Quits the main loop once all the events currently on the queue have
174 * @ingroup Ecore_Main_Loop_Group
177 ecore_main_loop_quit(void)
183 * Sets the function to use when monitoring multiple file descriptors,
184 * and waiting until one of more of the file descriptors before ready
185 * for some class of I/O operation.
187 * This function will be used instead of the system call select and
188 * could possible be used to integrate the Ecore event loop with an
189 * external event loop.
191 * @warning you don't know how to use, don't even try to use it.
193 * @ingroup Ecore_Main_Loop_Group
196 ecore_main_loop_select_func_set(int (*func)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout))
198 main_loop_select = func;
202 * Gets the select function set by ecore_select_func_set(),
203 * or the native select function if none was set.
205 * @ingroup Ecore_Main_Loop_Group
208 ecore_main_loop_select_func_get(void)
210 return main_loop_select;
214 * @defgroup Ecore_FD_Handler_Group File Event Handling Functions
216 * Functions that deal with file descriptor handlers.
220 * Adds a callback for activity on the given file descriptor.
222 * @p func will be called during the execution of @ref ecore_main_loop_begin
223 * when the file descriptor is available for reading, or writing, or both.
225 * Normally the return value from the @p func is "zero means this handler is
226 * finished and can be deleted" as is usual for handler callbacks. However,
227 * if the @p buf_func is supplied, then the return value from the @p func is
228 * "non zero means the handler should be called again in a tight loop".
230 * @p buf_func is called during event loop handling to check if data that has
231 * been read from the file descriptor is in a buffer and is available to
232 * read. Some systems (notably xlib) handle their own buffering, and would
233 * otherwise not work with select(). These systems should use a @p buf_func.
234 * This is a most annoying hack, only ecore_x uses it, so refer to that for
235 * an example. NOTE - @p func should probably return "one" always if
236 * @p buf_func is used, to avoid confusion with the other return value
239 * @param fd The file descriptor to watch.
240 * @param flags To watch it for read (@c ECORE_FD_READ) and/or
241 * (@c ECORE_FD_WRITE) write ability. @c ECORE_FD_ERROR
243 * @param func The callback function.
244 * @param data The data to pass to the callback.
245 * @param buf_func The function to call to check if any data has been
246 * buffered and already read from the fd. Can be @c NULL.
247 * @param buf_data The data to pass to the @p buf_func function.
248 * @return A fd handler handle if successful. @c NULL otherwise.
249 * @ingroup Ecore_FD_Handler_Group
251 EAPI Ecore_Fd_Handler *
252 ecore_main_fd_handler_add(int fd, Ecore_Fd_Handler_Flags flags, int (*func) (void *data, Ecore_Fd_Handler *fd_handler), const void *data, int (*buf_func) (void *buf_data, Ecore_Fd_Handler *fd_handler), const void *buf_data)
254 Ecore_Fd_Handler *fdh;
258 (!func)) return NULL;
260 fdh = calloc(1, sizeof(Ecore_Fd_Handler));
261 if (!fdh) return NULL;
262 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_FD_HANDLER);
265 fdh->read_active = 0;
266 fdh->write_active = 0;
267 fdh->error_active = 0;
270 fdh->data = (void *)data;
271 fdh->buf_func = buf_func;
272 fdh->buf_data = (void *)buf_data;
273 fd_handlers = (Ecore_Fd_Handler *) eina_inlist_append(EINA_INLIST_GET(fd_handlers),
274 EINA_INLIST_GET(fdh));
279 EAPI Ecore_Win32_Handler *
280 ecore_main_win32_handler_add(void *h,
281 int (*func) (void *data, Ecore_Win32_Handler *wh),
284 Ecore_Win32_Handler *wh;
289 wh = calloc(1, sizeof(Ecore_Win32_Handler));
290 if (!wh) return NULL;
291 ECORE_MAGIC_SET(wh, ECORE_MAGIC_WIN32_HANDLER);
295 wh->data = (void *)data;
296 win32_handlers = (Ecore_Win32_Handler *)eina_inlist_append(EINA_INLIST_GET(win32_handlers),
297 EINA_INLIST_GET(wh));
301 EAPI Ecore_Win32_Handler *
302 ecore_main_win32_handler_add(void *h __UNUSED__,
303 int (*func) (void *data, Ecore_Win32_Handler *wh) __UNUSED__,
304 const void *data __UNUSED__)
311 * Deletes the given FD handler.
312 * @param fd_handler The given FD handler.
313 * @return The data pointer set using @ref ecore_main_fd_handler_add,
314 * for @p fd_handler on success. @c NULL otherwise.
315 * @ingroup Ecore_FD_Handler_Group
318 ecore_main_fd_handler_del(Ecore_Fd_Handler *fd_handler)
320 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
322 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
323 "ecore_main_fd_handler_del");
326 fd_handler->delete_me = 1;
327 fd_handlers_delete_me = 1;
328 return fd_handler->data;
333 ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler)
335 if (!ECORE_MAGIC_CHECK(win32_handler, ECORE_MAGIC_WIN32_HANDLER))
337 ECORE_MAGIC_FAIL(win32_handler, ECORE_MAGIC_WIN32_HANDLER,
338 "ecore_main_win32_handler_del");
341 win32_handler->delete_me = 1;
342 win32_handlers_delete_me = 1;
343 return win32_handler->data;
347 ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler __UNUSED__)
354 ecore_main_fd_handler_prepare_callback_set(Ecore_Fd_Handler *fd_handler, void (*func) (void *data, Ecore_Fd_Handler *fd_handler), const void *data)
356 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
358 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
359 "ecore_main_fd_handler_prepare_callback_set");
362 fd_handler->prep_func = func;
363 fd_handler->prep_data = (void *) data;
367 * Retrieves the file descriptor that the given handler is handling.
368 * @param fd_handler The given FD handler.
369 * @return The file descriptor the handler is watching.
370 * @ingroup Ecore_FD_Handler_Group
373 ecore_main_fd_handler_fd_get(Ecore_Fd_Handler *fd_handler)
375 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
377 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
378 "ecore_main_fd_handler_fd_get");
381 return fd_handler->fd;
385 * Return if read, write or error, or a combination thereof, is active on the
386 * file descriptor of the given FD handler.
387 * @param fd_handler The given FD handler.
388 * @param flags The flags, @c ECORE_FD_READ, @c ECORE_FD_WRITE or
389 * @c ECORE_FD_ERROR to query.
390 * @return @c 1 if any of the given flags are active. @c 0 otherwise.
391 * @ingroup Ecore_FD_Handler_Group
394 ecore_main_fd_handler_active_get(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags)
398 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
400 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
401 "ecore_main_fd_handler_active_get");
405 if ((flags & ECORE_FD_READ) && (fd_handler->read_active)) ret = 1;
406 if ((flags & ECORE_FD_WRITE) && (fd_handler->write_active)) ret = 1;
407 if ((flags & ECORE_FD_ERROR) && (fd_handler->error_active)) ret = 1;
412 * Set what active streams the given FD handler should be monitoring.
413 * @param fd_handler The given FD handler.
414 * @param flags The flags to be watching.
415 * @ingroup Ecore_FD_Handler_Group
418 ecore_main_fd_handler_active_set(Ecore_Fd_Handler *fd_handler, Ecore_Fd_Handler_Flags flags)
420 if (!ECORE_MAGIC_CHECK(fd_handler, ECORE_MAGIC_FD_HANDLER))
422 ECORE_MAGIC_FAIL(fd_handler, ECORE_MAGIC_FD_HANDLER,
423 "ecore_main_fd_handler_active_set");
426 fd_handler->flags = flags;
430 _ecore_main_shutdown(void)
435 "*** ECORE WARINING: Calling ecore_shutdown() while still in the main loop.\n"
436 "*** Program may crash or behave strangely now.");
441 Ecore_Fd_Handler *fdh;
444 fd_handlers = (Ecore_Fd_Handler *) eina_inlist_remove(EINA_INLIST_GET(fd_handlers),
445 EINA_INLIST_GET(fdh));
446 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE);
449 fd_handlers_delete_me = 0;
450 fd_handler_current = NULL;
453 while (win32_handlers)
455 Ecore_Win32_Handler *wh;
458 win32_handlers = (Ecore_Win32_Handler *) eina_inlist_remove(EINA_INLIST_GET(win32_handlers),
459 EINA_INLIST_GET(wh));
460 ECORE_MAGIC_SET(wh, ECORE_MAGIC_NONE);
463 win32_handlers_delete_me = 0;
464 win32_handler_current = NULL;
469 _ecore_main_select(double timeout)
471 struct timeval tv, *t;
472 fd_set rfds, wfds, exfds;
475 Ecore_Fd_Handler *fdh;
478 if ((!finite(timeout)) || (timeout == 0.0)) /* finite() tests for NaN, too big, too small, and infinity. */
484 else if (timeout > 0.0)
489 timeout += (0.5 / HZ);
491 usec = (int)((timeout - (double)sec) * 1000000);
494 usec = (int)((timeout - (double)sec) * 1000000);
505 /* call the prepare callback for all handlers */
506 EINA_INLIST_FOREACH(fd_handlers, fdh)
507 if (!fdh->delete_me && fdh->prep_func)
510 fdh->prep_func (fdh->prep_data, fdh);
513 EINA_INLIST_FOREACH(fd_handlers, fdh)
516 if (fdh->flags & ECORE_FD_READ)
518 FD_SET(fdh->fd, &rfds);
519 if (fdh->fd > max_fd) max_fd = fdh->fd;
521 if (fdh->flags & ECORE_FD_WRITE)
523 FD_SET(fdh->fd, &wfds);
524 if (fdh->fd > max_fd) max_fd = fdh->fd;
526 if (fdh->flags & ECORE_FD_ERROR)
528 FD_SET(fdh->fd, &exfds);
529 if (fdh->fd > max_fd) max_fd = fdh->fd;
532 if (_ecore_signal_count_get()) return -1;
534 ret = main_loop_select(max_fd + 1, &rfds, &wfds, &exfds, t);
536 _ecore_loop_time = ecore_time_get();
540 if (errno == EINTR) return -1;
541 else if (errno == EBADF)
542 _ecore_main_fd_handlers_bads_rem();
547 EINA_INLIST_FOREACH(fd_handlers, fdh)
550 if (FD_ISSET(fdh->fd, &rfds))
551 fdh->read_active = 1;
552 if (FD_ISSET(fdh->fd, &wfds))
553 fdh->write_active = 1;
554 if (FD_ISSET(fdh->fd, &exfds))
555 fdh->error_active = 1;
557 _ecore_main_fd_handlers_cleanup();
559 _ecore_main_win32_handlers_cleanup();
568 _ecore_main_fd_handlers_bads_rem(void)
570 Ecore_Fd_Handler *fdh;
574 ERR("Removing bad fds");
575 for (l = EINA_INLIST_GET(fd_handlers); l; )
577 fdh = (Ecore_Fd_Handler *) l;
581 if ((fcntl(fdh->fd, F_GETFD) < 0) && (errno == EBADF))
583 ERR("Found bad fd at index %d", fdh->fd);
584 if (fdh->flags & ECORE_FD_ERROR)
586 ERR("Fd set for error! calling user");
588 if (!fdh->func(fdh->data, fdh))
590 ERR("Fd function err returned 0, remove it");
592 fd_handlers_delete_me = 1;
599 ERR("Problematic fd found at %d! setting it for delete", fdh->fd);
601 fd_handlers_delete_me = 1;
609 ERR("No bad fd found. Maybe a foreign fd from glib?");
611 ERR("No bad fd found. EEEK!");
614 _ecore_main_fd_handlers_cleanup();
619 _ecore_main_fd_handlers_cleanup(void)
621 Ecore_Fd_Handler *fdh;
623 int deleted_in_use = 0;
625 if (!fd_handlers_delete_me) return;
626 for (l = EINA_INLIST_GET(fd_handlers); l; )
628 fdh = (Ecore_Fd_Handler *) l;
633 // ERR("Removing fd %d", fdh->fd);
641 fd_handlers = (Ecore_Fd_Handler *) eina_inlist_remove(EINA_INLIST_GET(fd_handlers),
642 EINA_INLIST_GET(fdh));
643 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE);
648 fd_handlers_delete_me = 0;
653 _ecore_main_win32_handlers_cleanup(void)
655 Ecore_Win32_Handler *wh;
657 int deleted_in_use = 0;
659 if (!win32_handlers_delete_me) return;
660 for (l = EINA_INLIST_GET(win32_handlers); l; )
662 wh = (Ecore_Win32_Handler *)l;
673 win32_handlers = (Ecore_Win32_Handler *)eina_inlist_remove(EINA_INLIST_GET(win32_handlers),
674 EINA_INLIST_GET(wh));
675 ECORE_MAGIC_SET(wh, ECORE_MAGIC_NONE);
680 win32_handlers_delete_me = 0;
685 _ecore_main_fd_handlers_call(void)
687 if (!fd_handler_current)
689 /* regular main loop, start from head */
690 fd_handler_current = fd_handlers;
694 /* recursive main loop, continue from where we were */
695 fd_handler_current = (Ecore_Fd_Handler *)EINA_INLIST_GET(fd_handler_current)->next;
698 while (fd_handler_current)
700 Ecore_Fd_Handler *fdh = fd_handler_current;
704 if ((fdh->read_active) ||
705 (fdh->write_active) ||
709 if (!fdh->func(fdh->data, fdh))
712 fd_handlers_delete_me = 1;
716 fdh->read_active = 0;
717 fdh->write_active = 0;
718 fdh->error_active = 0;
722 if (fd_handler_current) /* may have changed in recursive main loops */
723 fd_handler_current = (Ecore_Fd_Handler *)EINA_INLIST_GET(fd_handler_current)->next;
728 _ecore_main_fd_handlers_buf_call(void)
730 Ecore_Fd_Handler *fdh;
734 EINA_INLIST_FOREACH(fd_handlers, fdh)
740 if (fdh->buf_func(fdh->buf_data, fdh))
742 ret |= fdh->func(fdh->data, fdh);
743 fdh->read_active = 1;
753 _ecore_main_loop_iterate_internal(int once_only)
755 double next_time = -1.0;
760 /* expire any timers */
761 while (_ecore_timer_call(_ecore_loop_time));
762 _ecore_timer_cleanup();
764 /* process signals into events .... */
765 while (_ecore_signal_count_get()) _ecore_signal_call();
766 if (_ecore_event_exist())
768 _ecore_idle_enterer_call();
770 _ecore_main_select(0.0);
771 _ecore_loop_time = ecore_time_get();
772 _ecore_timer_enable_new();
775 /* call idle enterers ... */
776 if (!once_only) _ecore_idle_enterer_call();
779 have_event = have_signal = 0;
781 if (_ecore_main_select(0.0) > 0) have_event = 1;
782 if (_ecore_signal_count_get() > 0) have_signal = 1;
783 if (have_signal || have_event)
785 _ecore_loop_time = ecore_time_get();
786 _ecore_timer_enable_new();
791 /* if these calls caused any buffered events to appear - deal with them */
792 _ecore_main_fd_handlers_buf_call();
794 /* if ther are any - jump to processing them */
795 if (_ecore_event_exist())
798 _ecore_main_select(0.0);
799 _ecore_loop_time = ecore_time_get();
800 _ecore_timer_enable_new();
805 _ecore_idle_enterer_call();
807 _ecore_loop_time = ecore_time_get();
808 _ecore_timer_enable_new();
812 if (_ecore_fps_debug)
814 t2 = ecore_time_get();
815 if ((t1 > 0.0) && (t2 > 0.0))
816 _ecore_fps_debug_runtime_add(t2 - t1);
819 /* any timers re-added as a result of these are allowed to go */
820 _ecore_timer_enable_new();
823 _ecore_loop_time = ecore_time_get();
825 _ecore_timer_enable_new();
828 if (!_ecore_event_exist())
831 have_event = have_signal = 0;
832 next_time = _ecore_timer_next_get();
837 if (!_ecore_idler_exist())
839 if (_ecore_main_select(-1.0) > 0) have_event = 1;
846 if (!_ecore_idler_call()) goto start_loop;
847 if (_ecore_event_exist()) break;
848 if (_ecore_main_select(0.0) > 0) have_event = 1;
849 if (_ecore_signal_count_get() > 0) have_signal = 1;
850 if (have_event || have_signal) break;
851 if (_ecore_timers_exists()) goto start_loop;
860 if (!_ecore_idler_exist())
862 if (_ecore_main_select(next_time) > 0) have_event = 1;
869 if (!_ecore_idler_call()) goto start_loop;
870 if (_ecore_event_exist()) break;
871 if (_ecore_main_select(0.0) > 0) have_event = 1;
872 if (_ecore_signal_count_get() > 0) have_signal = 1;
873 if (have_event || have_signal) break;
874 next_time = _ecore_timer_next_get();
875 if (next_time <= 0) break;
880 _ecore_loop_time = ecore_time_get();
882 if (_ecore_fps_debug)
884 t1 = ecore_time_get();
886 /* we came out of our "wait state" so idle has exited */
888 _ecore_idle_exiter_call();
889 /* call the fd handler per fd that became alive... */
890 /* this should read or write any data to the monitored fd and then */
891 /* post events onto the ecore event pipe if necessary */
894 _ecore_main_fd_handlers_call();
895 _ecore_main_fd_handlers_buf_call();
898 /* process signals into events .... */
899 while (_ecore_signal_count_get()) _ecore_signal_call();
900 /* handle events ... */
902 _ecore_main_fd_handlers_cleanup();
904 // while (_ecore_main_fd_handlers_buf_call());
906 /* ok - too much optimising. let's call idle enterers more often. if we
907 * have events that place more events or jobs etc. on the event queue
908 * we may never get to call an idle enterer
912 _ecore_idle_enterer_call();
918 _ecore_main_win32_select(int nfds __UNUSED__, fd_set *readfds, fd_set *writefds,
919 fd_set *exceptfds, struct timeval *tv)
921 HANDLE objects[MAXIMUM_WAIT_OBJECTS];
922 int sockets[MAXIMUM_WAIT_OBJECTS];
923 Ecore_Fd_Handler *fdh;
924 Ecore_Win32_Handler *wh;
925 unsigned int objects_nbr = 0;
926 unsigned int handles_nbr = 0;
927 unsigned int events_nbr = 0;
934 /* Create an event object per socket */
935 EINA_INLIST_FOREACH(fd_handlers, fdh)
941 if(FD_ISSET(fdh->fd, readfds))
942 network_event |= FD_READ;
943 if(FD_ISSET(fdh->fd, writefds))
944 network_event |= FD_WRITE;
945 if(FD_ISSET(fdh->fd, exceptfds))
946 network_event |= FD_OOB;
950 event = WSACreateEvent();
951 WSAEventSelect(fdh->fd, event, network_event);
952 objects[objects_nbr] = event;
953 sockets[events_nbr] = fdh->fd;
959 /* store the HANDLEs in the objects to wait for */
960 EINA_INLIST_FOREACH(win32_handlers, wh)
962 objects[objects_nbr] = wh->h;
967 /* Empty the queue before waiting */
968 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
970 TranslateMessage(&msg);
971 DispatchMessage(&msg);
974 /* Wait for any message sent or posted to this queue */
975 /* or for one of the passed handles be set to signaled. */
979 timeout = (DWORD)(tv->tv_sec * 1000.0 + tv->tv_usec / 1000.0);
981 if (timeout == 0) return 0;
983 result = MsgWaitForMultipleObjects(objects_nbr, (const HANDLE *)objects, EINA_FALSE,
984 timeout, QS_ALLINPUT);
990 /* The result tells us the type of event we have. */
991 if (result == WAIT_FAILED)
995 msg = evil_last_error_get();
1000 else if (result == WAIT_TIMEOUT)
1005 else if (result == (WAIT_OBJECT_0 + objects_nbr))
1007 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
1009 TranslateMessage(&msg);
1010 DispatchMessage(&msg);
1015 else if ((result >= 0) && (result < WAIT_OBJECT_0 + events_nbr))
1017 WSANETWORKEVENTS network_event;
1019 WSAEnumNetworkEvents(sockets[result], objects[result], &network_event);
1021 if(network_event.lNetworkEvents & FD_READ)
1022 FD_SET(sockets[result], readfds);
1023 if(network_event.lNetworkEvents & FD_WRITE)
1024 FD_SET(sockets[result], writefds);
1025 if(network_event.lNetworkEvents & FD_OOB)
1026 FD_SET(sockets[result], exceptfds);
1030 else if ((result >= WAIT_OBJECT_0 + events_nbr) && (result < WAIT_OBJECT_0 + objects_nbr))
1032 if (!win32_handler_current)
1034 /* regular main loop, start from head */
1035 win32_handler_current = win32_handlers;
1039 /* recursive main loop, continue from where we were */
1040 win32_handler_current = (Ecore_Win32_Handler *)EINA_INLIST_GET(win32_handler_current)->next;
1043 while (win32_handler_current)
1045 wh = win32_handler_current;
1047 if (objects[result - WAIT_OBJECT_0] == wh->h)
1051 if (!wh->func(wh->data, wh))
1054 win32_handlers_delete_me = 1;
1059 if (win32_handler_current) /* may have changed in recursive main loops */
1060 win32_handler_current = (Ecore_Win32_Handler *)EINA_INLIST_GET(win32_handler_current)->next;
1066 ERR("unknown result...\n");
1070 /* Remove event objects again */
1071 for(i = 0; i < events_nbr; i++)
1072 WSACloseEvent(objects[i]);