static int _ecore_main_select(double timeout);
static void _ecore_main_fd_handlers_cleanup(void);
+#ifndef _WIN32
static void _ecore_main_fd_handlers_bads_rem(void);
+#endif
static void _ecore_main_fd_handlers_call(void);
static int _ecore_main_fd_handlers_buf_call(void);
static void _ecore_main_loop_iterate_internal(int once_only);
#ifdef _WIN32
static int _ecore_main_win32_select(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
+static void _ecore_main_win32_handlers_cleanup(void);
#endif
static int in_main_loop = 0;
static int fd_handlers_delete_me = 0;
#ifdef _WIN32
static Ecore_Win32_Handler *win32_handlers = NULL;
+static int win32_handlers_delete_me = 0;
#endif
#ifdef _WIN32
if (!wh) return NULL;
ECORE_MAGIC_SET(wh, ECORE_MAGIC_WIN32_HANDLER);
wh->h = (HANDLE)h;
+ wh->delete_me = 0;
wh->func = func;
wh->data = (void *)data;
win32_handlers = (Ecore_Win32_Handler *)eina_inlist_append(EINA_INLIST_GET(win32_handlers),
return fd_handler->data;
}
+#ifdef _WIN32
+EAPI void *
+ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler)
+{
+ if (!ECORE_MAGIC_CHECK(win32_handler, ECORE_MAGIC_WIN32_HANDLER))
+ {
+ ECORE_MAGIC_FAIL(win32_handler, ECORE_MAGIC_WIN32_HANDLER,
+ "ecore_main_win32_handler_del");
+ return NULL;
+ }
+ win32_handler->delete_me = 1;
+ win32_handlers_delete_me = 1;
+ return win32_handler->data;
+}
+#else
+EAPI void *
+ecore_main_win32_handler_del(Ecore_Win32_Handler *win32_handler)
+{
+ return NULL;
+}
+#endif
+
EAPI void
ecore_main_fd_handler_prepare_callback_set(Ecore_Fd_Handler *fd_handler, void (*func) (void *data, Ecore_Fd_Handler *fd_handler), const void *data)
{
free(fdh);
}
fd_handlers_delete_me = 0;
+
+#ifdef _WIN32
+ while (win32_handlers)
+ {
+ Ecore_Win32_Handler *wh;
+
+ wh = win32_handlers;
+ win32_handlers = (Ecore_Win32_Handler *) eina_inlist_remove(EINA_INLIST_GET(win32_handlers),
+ EINA_INLIST_GET(wh));
+ ECORE_MAGIC_SET(wh, ECORE_MAGIC_NONE);
+ free(wh);
+ }
+ win32_handlers_delete_me = 0;
+#endif
}
static int
_ecore_loop_time = ecore_time_get();
if (ret < 0)
{
-#ifdef _WIN32
- fprintf(stderr, "main_loop_select error %d\n", WSAGetLastError());
- if (WSAEINTR == WSAGetLastError()) return -1;
-#else
+#ifndef _WIN32
if (errno == EINTR) return -1;
else if (errno == EBADF)
_ecore_main_fd_handlers_bads_rem();
fdh->error_active = 1;
}
_ecore_main_fd_handlers_cleanup();
+#ifdef _WIN32
+ _ecore_main_win32_handlers_cleanup();
+#endif
return 1;
}
return 0;
}
+#ifndef _WIN32
static void
_ecore_main_fd_handlers_bads_rem(void)
{
_ecore_main_fd_handlers_cleanup();
}
+#endif
static void
_ecore_main_fd_handlers_cleanup(void)
fd_handlers_delete_me = 0;
}
+#ifdef _WIN32
+static void
+_ecore_main_win32_handlers_cleanup(void)
+{
+ Ecore_Win32_Handler *wh;
+ Eina_Inlist *l;
+
+ if (!win32_handlers_delete_me) return;
+ for (l = EINA_INLIST_GET(win32_handlers); l; )
+ {
+ wh = (Ecore_Win32_Handler *)l;
+
+ l = l->next;
+ if (wh->delete_me)
+ {
+ win32_handlers = (Ecore_Win32_Handler *)eina_inlist_remove(EINA_INLIST_GET(win32_handlers),
+ EINA_INLIST_GET(wh));
+ ECORE_MAGIC_SET(wh, ECORE_MAGIC_NONE);
+ free(wh);
+ }
+ }
+ win32_handlers_delete_me = 0;
+}
+#endif
+
static void
_ecore_main_fd_handlers_call(void)
{
HANDLE objects[MAXIMUM_WAIT_OBJECTS];
int sockets[MAXIMUM_WAIT_OBJECTS];
Ecore_Win32_Handler *wh;
- int objects_nbr = 0;
- int handles_nbr = 0;
- int events_nbr = 0;
+ unsigned int objects_nbr = 0;
+ unsigned int handles_nbr = 0;
+ unsigned int events_nbr = 0;
DWORD result;
DWORD timeout;
MSG msg;
else
timeout = (DWORD)(tv->tv_sec * 1000.0 + tv->tv_usec / 1000.0);
- if (timeout == 0) return;
+ if (timeout == 0) return 0;
result = MsgWaitForMultipleObjects(objects_nbr, (const HANDLE *)objects, FALSE,
timeout, QS_ALLINPUT);
msg = evil_last_error_get();
printf (" * %s\n", msg);
free(msg);
- res = 0;
+ res = -1;
}
else if (result == WAIT_TIMEOUT)
{
EINA_INLIST_FOREACH(win32_handlers, wh)
{
if (objects[result - WAIT_OBJECT_0] == wh->h)
- wh->func(wh->data, wh);
+ if (!wh->delete_me)
+ if (!wh->func(wh->data, wh))
+ {
+ wh->delete_me = 1;
+ win32_handlers_delete_me = 1;
+ }
}
res = 1;
}
else
{
fprintf(stderr, "unknown result...\n");
+ res = -1;
}
/* Remove event objects again */
for(i = 0; i < events_nbr; i++)
WSACloseEvent(objects[i]);
- /* remove HANDLEs */
- while (win32_handlers)
- {
- wh = win32_handlers;
- win32_handlers = (Ecore_Win32_Handler *)eina_inlist_remove(EINA_INLIST_GET(win32_handlers),
- EINA_INLIST_GET(wh));
- free(wh);
- }
-
return res;
}
#endif