barbieri pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=49399b385b8ebb1313a5709ae64c9bc6ebb4474e

commit 49399b385b8ebb1313a5709ae64c9bc6ebb4474e
Author: Gustavo Sverzut Barbieri <barbi...@profusion.mobi>
Date:   Thu Nov 24 01:03:45 2016 -0200

    efl_io_std{in,out,err}: do not spin on fd monitoring events.
    
    as soon as we report 'can_read' or 'can_write', stop monitoring the
    events until the user executes the operation, which will clear these
    flags and we resume monitoring.
---
 src/lib/ecore/efl_io_stderr.c  | 21 ++++++++++++++++++++-
 src/lib/ecore/efl_io_stderr.eo |  1 +
 src/lib/ecore/efl_io_stdin.c   | 21 ++++++++++++++++++++-
 src/lib/ecore/efl_io_stdin.eo  |  1 +
 src/lib/ecore/efl_io_stdout.c  | 21 ++++++++++++++++++++-
 src/lib/ecore/efl_io_stdout.eo |  1 +
 6 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/src/lib/ecore/efl_io_stderr.c b/src/lib/ecore/efl_io_stderr.c
index b609028..6992901 100644
--- a/src/lib/ecore/efl_io_stderr.c
+++ b/src/lib/ecore/efl_io_stderr.c
@@ -38,7 +38,6 @@ _efl_io_stderr_efl_object_finalize(Eo *o, void *pd 
EINA_UNUSED)
    o = efl_finalize(efl_super(o, MY_CLASS));
    if (!o) return NULL;
 
-   // TODO: only register "write" if "can_write" is being monitored?
    efl_event_callback_add(o, EFL_LOOP_FD_EVENT_WRITE, 
_efl_io_stderr_event_write, NULL);
    efl_event_callback_add(o, EFL_LOOP_FD_EVENT_ERROR, 
_efl_io_stderr_event_error, NULL);
 
@@ -57,4 +56,24 @@ _efl_io_stderr_efl_io_writer_write(Eo *o, void *pd 
EINA_UNUSED, Eina_Slice *ro_s
    return ret;
 }
 
+EOLIAN static void
+_efl_io_stderr_efl_io_writer_can_write_set(Eo *o, void *pd EINA_UNUSED, 
Eina_Bool value)
+{
+   Eina_Bool old = efl_io_writer_can_write_get(o);
+   if (old == value) return;
+
+   efl_io_writer_can_write_set(efl_super(o, MY_CLASS), value);
+
+   if (value)
+     {
+        /* stop monitoring the FD, we need to wait the user to write and clear 
the kernel flag */
+        efl_event_callback_del(o, EFL_LOOP_FD_EVENT_WRITE, 
_efl_io_stderr_event_write, NULL);
+     }
+   else
+     {
+        /* kernel flag is clear, resume monitoring the FD */
+        efl_event_callback_add(o, EFL_LOOP_FD_EVENT_WRITE, 
_efl_io_stderr_event_write, NULL);
+     }
+}
+
 #include "efl_io_stderr.eo.c"
diff --git a/src/lib/ecore/efl_io_stderr.eo b/src/lib/ecore/efl_io_stderr.eo
index 5da5641..d7ec5d5 100644
--- a/src/lib/ecore/efl_io_stderr.eo
+++ b/src/lib/ecore/efl_io_stderr.eo
@@ -10,5 +10,6 @@ class Efl.Io.Stderr (Efl.Loop.Fd, Efl.Io.Writer.Fd) {
         Efl.Object.finalize;
         Efl.Loop.Fd.fd.set;
         Efl.Io.Writer.write;
+        Efl.Io.Writer.can_write.set;
     }
 }
diff --git a/src/lib/ecore/efl_io_stdin.c b/src/lib/ecore/efl_io_stdin.c
index 679068b..6da700e 100644
--- a/src/lib/ecore/efl_io_stdin.c
+++ b/src/lib/ecore/efl_io_stdin.c
@@ -40,7 +40,6 @@ _efl_io_stdin_efl_object_finalize(Eo *o, void *pd EINA_UNUSED)
    o = efl_finalize(efl_super(o, MY_CLASS));
    if (!o) return NULL;
 
-   // TODO: only register "read" if "can_read" is being monitored?
    efl_event_callback_add(o, EFL_LOOP_FD_EVENT_READ, _efl_io_stdin_event_read, 
NULL);
    efl_event_callback_add(o, EFL_LOOP_FD_EVENT_ERROR, 
_efl_io_stdin_event_error, NULL);
    return o;
@@ -58,4 +57,24 @@ _efl_io_stdin_efl_io_reader_read(Eo *o, void *pd 
EINA_UNUSED, Eina_Rw_Slice *rw_
    return ret;
 }
 
+EOLIAN static void
+_efl_io_stdin_efl_io_reader_can_read_set(Eo *o, void *pd EINA_UNUSED, 
Eina_Bool value)
+{
+   Eina_Bool old = efl_io_reader_can_read_get(o);
+   if (old == value) return;
+
+   efl_io_reader_can_read_set(efl_super(o, MY_CLASS), value);
+
+   if (value)
+     {
+        /* stop monitoring the FD, we need to wait the user to read and clear 
the kernel flag */
+        efl_event_callback_del(o, EFL_LOOP_FD_EVENT_READ, 
_efl_io_stdin_event_read, NULL);
+     }
+   else
+     {
+        /* kernel flag is clear, resume monitoring the FD */
+        efl_event_callback_add(o, EFL_LOOP_FD_EVENT_READ, 
_efl_io_stdin_event_read, NULL);
+     }
+}
+
 #include "efl_io_stdin.eo.c"
diff --git a/src/lib/ecore/efl_io_stdin.eo b/src/lib/ecore/efl_io_stdin.eo
index 4a86558..421341a 100644
--- a/src/lib/ecore/efl_io_stdin.eo
+++ b/src/lib/ecore/efl_io_stdin.eo
@@ -10,5 +10,6 @@ class Efl.Io.Stdin (Efl.Loop.Fd, Efl.Io.Reader.Fd) {
         Efl.Object.finalize;
         Efl.Loop.Fd.fd.set;
         Efl.Io.Reader.read;
+        Efl.Io.Reader.can_read.set;
     }
 }
diff --git a/src/lib/ecore/efl_io_stdout.c b/src/lib/ecore/efl_io_stdout.c
index df20c9fb..026d79b 100644
--- a/src/lib/ecore/efl_io_stdout.c
+++ b/src/lib/ecore/efl_io_stdout.c
@@ -38,7 +38,6 @@ _efl_io_stdout_efl_object_finalize(Eo *o, void *pd 
EINA_UNUSED)
    o = efl_finalize(efl_super(o, MY_CLASS));
    if (!o) return NULL;
 
-   // TODO: only register "write" if "can_write" is being monitored?
    efl_event_callback_add(o, EFL_LOOP_FD_EVENT_WRITE, 
_efl_io_stdout_event_write, NULL);
    efl_event_callback_add(o, EFL_LOOP_FD_EVENT_ERROR, 
_efl_io_stdout_event_error, NULL);
    return o;
@@ -56,4 +55,24 @@ _efl_io_stdout_efl_io_writer_write(Eo *o, void *pd 
EINA_UNUSED, Eina_Slice *ro_s
    return ret;
 }
 
+EOLIAN static void
+_efl_io_stdout_efl_io_writer_can_write_set(Eo *o, void *pd EINA_UNUSED, 
Eina_Bool value)
+{
+   Eina_Bool old = efl_io_writer_can_write_get(o);
+   if (old == value) return;
+
+   efl_io_writer_can_write_set(efl_super(o, MY_CLASS), value);
+
+   if (value)
+     {
+        /* stop monitoring the FD, we need to wait the user to write and clear 
the kernel flag */
+        efl_event_callback_del(o, EFL_LOOP_FD_EVENT_WRITE, 
_efl_io_stdout_event_write, NULL);
+     }
+   else
+     {
+        /* kernel flag is clear, resume monitoring the FD */
+        efl_event_callback_add(o, EFL_LOOP_FD_EVENT_WRITE, 
_efl_io_stdout_event_write, NULL);
+     }
+}
+
 #include "efl_io_stdout.eo.c"
diff --git a/src/lib/ecore/efl_io_stdout.eo b/src/lib/ecore/efl_io_stdout.eo
index 0dcc6eb..b05fcdc 100644
--- a/src/lib/ecore/efl_io_stdout.eo
+++ b/src/lib/ecore/efl_io_stdout.eo
@@ -10,5 +10,6 @@ class Efl.Io.Stdout (Efl.Loop.Fd, Efl.Io.Writer.Fd) {
         Efl.Object.finalize;
         Efl.Loop.Fd.fd.set;
         Efl.Io.Writer.write;
+        Efl.Io.Writer.can_write.set;
     }
 }

-- 


Reply via email to