summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore/ecore_main.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2012-08-01 14:37:24 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2012-08-01 14:37:24 +0000
commit3fc5ceadd728ba87a663050348231af519caa7d6 (patch)
tree1444a536370a4c97b4ea240a2686d54e06fb146b /legacy/ecore/src/lib/ecore/ecore_main.c
parent15a9aa0950f9127fcb4ba130c5de24e0ac2474f8 (diff)
add ecore_main_fd_handler_file_add() for use with regular files.
epoll does not handle reading from files since it is only a mechanism for determining whether a fd is ready for read/write/error, and regular files are always ready. as a result, we must select on them explicitly without adding to the epoll fd I realize that this is a feature freeze, but it's rather non-invasive and this is an absolute must-have to fix mounting for e17 so...sorry! SVN revision: 74741
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_main.c101
1 files changed, 93 insertions, 8 deletions
diff --git a/legacy/ecore/src/lib/ecore/ecore_main.c b/legacy/ecore/src/lib/ecore/ecore_main.c
index a936a2b41c..fdab2618d5 100644
--- a/legacy/ecore/src/lib/ecore/ecore_main.c
+++ b/legacy/ecore/src/lib/ecore/ecore_main.c
@@ -163,6 +163,7 @@ struct _Ecore_Fd_Handler
163 Eina_Bool write_active : 1; 163 Eina_Bool write_active : 1;
164 Eina_Bool error_active : 1; 164 Eina_Bool error_active : 1;
165 Eina_Bool delete_me : 1; 165 Eina_Bool delete_me : 1;
166 Eina_Bool file : 1;
166#if defined(USE_G_MAIN_LOOP) 167#if defined(USE_G_MAIN_LOOP)
167 GPollFD gfd; 168 GPollFD gfd;
168#endif 169#endif
@@ -213,6 +214,7 @@ static int do_quit = 0;
213static Ecore_Fd_Handler *fd_handlers = NULL; 214static Ecore_Fd_Handler *fd_handlers = NULL;
214static Ecore_Fd_Handler *fd_handler_current = NULL; 215static Ecore_Fd_Handler *fd_handler_current = NULL;
215static Eina_List *fd_handlers_with_prep = NULL; 216static Eina_List *fd_handlers_with_prep = NULL;
217static Eina_List *file_fd_handlers = NULL;
216static Eina_List *fd_handlers_with_buffer = NULL; 218static Eina_List *fd_handlers_with_buffer = NULL;
217static Eina_List *fd_handlers_to_delete = NULL; 219static Eina_List *fd_handlers_to_delete = NULL;
218 220
@@ -326,7 +328,7 @@ _ecore_poll_events_from_fdh(Ecore_Fd_Handler *fdh)
326 int events = 0; 328 int events = 0;
327 if (fdh->flags & ECORE_FD_READ) events |= EPOLLIN; 329 if (fdh->flags & ECORE_FD_READ) events |= EPOLLIN;
328 if (fdh->flags & ECORE_FD_WRITE) events |= EPOLLOUT; 330 if (fdh->flags & ECORE_FD_WRITE) events |= EPOLLOUT;
329 if (fdh->flags & ECORE_FD_ERROR) events |= EPOLLERR; 331 if (fdh->flags & ECORE_FD_ERROR) events |= EPOLLERR | EPOLLPRI;
330 return events; 332 return events;
331} 333}
332 334
@@ -348,7 +350,7 @@ _ecore_main_fdh_poll_add(Ecore_Fd_Handler *fdh)
348{ 350{
349 int r = 0; 351 int r = 0;
350 352
351 if (HAVE_EPOLL && epoll_fd >= 0) 353 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0)
352 { 354 {
353 r = _ecore_epoll_add(_ecore_get_epoll_fd(), fdh->fd, 355 r = _ecore_epoll_add(_ecore_get_epoll_fd(), fdh->fd,
354 _ecore_poll_events_from_fdh(fdh), fdh); 356 _ecore_poll_events_from_fdh(fdh), fdh);
@@ -369,7 +371,7 @@ _ecore_main_fdh_poll_add(Ecore_Fd_Handler *fdh)
369static inline void 371static inline void
370_ecore_main_fdh_poll_del(Ecore_Fd_Handler *fdh) 372_ecore_main_fdh_poll_del(Ecore_Fd_Handler *fdh)
371{ 373{
372 if (HAVE_EPOLL && epoll_fd >= 0) 374 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0)
373 { 375 {
374 struct epoll_event ev; 376 struct epoll_event ev;
375 int efd = _ecore_get_epoll_fd(); 377 int efd = _ecore_get_epoll_fd();
@@ -408,7 +410,7 @@ static inline int
408_ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh) 410_ecore_main_fdh_poll_modify(Ecore_Fd_Handler *fdh)
409{ 411{
410 int r = 0; 412 int r = 0;
411 if (HAVE_EPOLL && epoll_fd >= 0) 413 if ((!fdh->file) && HAVE_EPOLL && epoll_fd >= 0)
412 { 414 {
413 struct epoll_event ev; 415 struct epoll_event ev;
414 int efd = _ecore_get_epoll_fd(); 416 int efd = _ecore_get_epoll_fd();
@@ -1041,6 +1043,56 @@ unlock:
1041 return fdh; 1043 return fdh;
1042} 1044}
1043 1045
1046EAPI Ecore_Fd_Handler *
1047ecore_main_fd_handler_file_add(int fd,
1048 Ecore_Fd_Handler_Flags flags,
1049 Ecore_Fd_Cb func,
1050 const void *data,
1051 Ecore_Fd_Cb buf_func,
1052 const void *buf_data)
1053{
1054 Ecore_Fd_Handler *fdh = NULL;
1055
1056 EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
1057 _ecore_lock();
1058
1059 if ((fd < 0) || (flags == 0) || (!func)) goto unlock;
1060
1061 fdh = ecore_fd_handler_calloc(1);
1062 if (!fdh) goto unlock;
1063 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_FD_HANDLER);
1064 fdh->next_ready = NULL;
1065 fdh->fd = fd;
1066 fdh->flags = flags;
1067 fdh->file = EINA_TRUE;
1068 if (_ecore_main_fdh_poll_add(fdh) < 0)
1069 {
1070 int err = errno;
1071 ERR("Failed to add poll on fd %d (errno = %d: %s)!", fd, err, strerror(err));
1072 ecore_fd_handler_mp_free(fdh);
1073 fdh = NULL;
1074 goto unlock;
1075 }
1076 fdh->read_active = EINA_FALSE;
1077 fdh->write_active = EINA_FALSE;
1078 fdh->error_active = EINA_FALSE;
1079 fdh->delete_me = EINA_FALSE;
1080 fdh->func = func;
1081 fdh->data = (void *)data;
1082 fdh->buf_func = buf_func;
1083 if (buf_func)
1084 fd_handlers_with_buffer = eina_list_append(fd_handlers_with_buffer, fdh);
1085 fdh->buf_data = (void *)buf_data;
1086 fd_handlers = (Ecore_Fd_Handler *)
1087 eina_inlist_append(EINA_INLIST_GET(fd_handlers),
1088 EINA_INLIST_GET(fdh));
1089 file_fd_handlers = eina_list_append(file_fd_handlers, fdh);
1090unlock:
1091 _ecore_unlock();
1092
1093 return fdh;
1094}
1095
1044#ifdef _WIN32 1096#ifdef _WIN32
1045EAPI Ecore_Win32_Handler * 1097EAPI Ecore_Win32_Handler *
1046ecore_main_win32_handler_add(void *h, 1098ecore_main_win32_handler_add(void *h,
@@ -1243,6 +1295,8 @@ _ecore_main_shutdown(void)
1243 fd_handlers_with_prep = eina_list_free(fd_handlers_with_prep); 1295 fd_handlers_with_prep = eina_list_free(fd_handlers_with_prep);
1244 if (fd_handlers_to_delete) 1296 if (fd_handlers_to_delete)
1245 fd_handlers_to_delete = eina_list_free(fd_handlers_to_delete); 1297 fd_handlers_to_delete = eina_list_free(fd_handlers_to_delete);
1298 if (file_fd_handlers)
1299 file_fd_handlers = eina_list_free(file_fd_handlers);
1246 1300
1247 fd_handlers_to_call = NULL; 1301 fd_handlers_to_call = NULL;
1248 fd_handlers_to_call_current = NULL; 1302 fd_handlers_to_call_current = NULL;
@@ -1296,6 +1350,8 @@ _ecore_main_select(double timeout)
1296{ 1350{
1297 struct timeval tv, *t; 1351 struct timeval tv, *t;
1298 fd_set rfds, wfds, exfds; 1352 fd_set rfds, wfds, exfds;
1353 Ecore_Fd_Handler *fdh;
1354 Eina_List *l;
1299 int max_fd; 1355 int max_fd;
1300 int ret; 1356 int ret;
1301 1357
@@ -1333,8 +1389,6 @@ _ecore_main_select(double timeout)
1333 1389
1334 if (!HAVE_EPOLL || epoll_fd < 0) 1390 if (!HAVE_EPOLL || epoll_fd < 0)
1335 { 1391 {
1336 Ecore_Fd_Handler *fdh;
1337
1338 EINA_INLIST_FOREACH(fd_handlers, fdh) 1392 EINA_INLIST_FOREACH(fd_handlers, fdh)
1339 { 1393 {
1340 if (!fdh->delete_me) 1394 if (!fdh->delete_me)
@@ -1363,7 +1417,26 @@ _ecore_main_select(double timeout)
1363 max_fd = _ecore_get_epoll_fd(); 1417 max_fd = _ecore_get_epoll_fd();
1364 FD_SET(max_fd, &rfds); 1418 FD_SET(max_fd, &rfds);
1365 } 1419 }
1366 1420 EINA_LIST_FOREACH(file_fd_handlers, l, fdh)
1421 if (!fdh->delete_me)
1422 {
1423 if (fdh->flags & ECORE_FD_READ)
1424 {
1425 FD_SET(fdh->fd, &rfds);
1426 if (fdh->fd > max_fd) max_fd = fdh->fd;
1427 }
1428 if (fdh->flags & ECORE_FD_WRITE)
1429 {
1430 FD_SET(fdh->fd, &wfds);
1431 if (fdh->fd > max_fd) max_fd = fdh->fd;
1432 }
1433 if (fdh->flags & ECORE_FD_ERROR)
1434 {
1435 FD_SET(fdh->fd, &exfds);
1436 if (fdh->fd > max_fd) max_fd = fdh->fd;
1437 }
1438 if (fdh->fd > max_fd) max_fd = fdh->fd;
1439 }
1367 if (_ecore_signal_count_get()) return -1; 1440 if (_ecore_signal_count_get()) return -1;
1368 1441
1369 _ecore_unlock(); 1442 _ecore_unlock();
@@ -1401,7 +1474,17 @@ _ecore_main_select(double timeout)
1401 } 1474 }
1402 } 1475 }
1403 } 1476 }
1404 1477 EINA_LIST_FOREACH(file_fd_handlers, l, fdh)
1478 if (!fdh->delete_me)
1479 {
1480 if (FD_ISSET(fdh->fd, &rfds))
1481 fdh->read_active = EINA_TRUE;
1482 if (FD_ISSET(fdh->fd, &wfds))
1483 fdh->write_active = EINA_TRUE;
1484 if (FD_ISSET(fdh->fd, &exfds))
1485 fdh->error_active = EINA_TRUE;
1486 _ecore_try_add_to_call_list(fdh);
1487 }
1405 _ecore_main_fd_handlers_cleanup(); 1488 _ecore_main_fd_handlers_cleanup();
1406#ifdef _WIN32 1489#ifdef _WIN32
1407 _ecore_main_win32_handlers_cleanup(); 1490 _ecore_main_win32_handlers_cleanup();
@@ -1498,6 +1581,8 @@ _ecore_main_fd_handlers_cleanup(void)
1498 fd_handlers_with_prep = eina_list_remove(fd_handlers_with_prep, fdh); 1581 fd_handlers_with_prep = eina_list_remove(fd_handlers_with_prep, fdh);
1499 fd_handlers = (Ecore_Fd_Handler *) 1582 fd_handlers = (Ecore_Fd_Handler *)
1500 eina_inlist_remove(EINA_INLIST_GET(fd_handlers), EINA_INLIST_GET(fdh)); 1583 eina_inlist_remove(EINA_INLIST_GET(fd_handlers), EINA_INLIST_GET(fdh));
1584 if (fdh->file)
1585 file_fd_handlers = eina_list_remove(file_fd_handlers, fdh);
1501 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE); 1586 ECORE_MAGIC_SET(fdh, ECORE_MAGIC_NONE);
1502 ecore_fd_handler_mp_free(fdh); 1587 ecore_fd_handler_mp_free(fdh);
1503 fd_handlers_to_delete = eina_list_remove_list(fd_handlers_to_delete, l); 1588 fd_handlers_to_delete = eina_list_remove_list(fd_handlers_to_delete, l);