barbieri pushed a commit to branch master. http://git.enlightenment.org/core/efl.git/commit/?id=d0b7d876a7a108dc7311e8114ae78d0b0cf79f91
commit d0b7d876a7a108dc7311e8114ae78d0b0cf79f91 Author: Gustavo Sverzut Barbieri <[email protected]> Date: Thu Nov 24 18:44:44 2016 -0200 efl_io_queue: add discard method, useful in real life. While using efl_io_queue + slice_get I found that we need to discard data and the only way was to read to an actual buffer, kinda annoying. Then introduce a discard method to do that. --- src/lib/efl/interfaces/efl_io_queue.c | 24 ++++++++++++++++++++++++ src/lib/efl/interfaces/efl_io_queue.eo | 30 +++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/lib/efl/interfaces/efl_io_queue.c b/src/lib/efl/interfaces/efl_io_queue.c index 6a7400c..277ab36 100644 --- a/src/lib/efl/interfaces/efl_io_queue.c +++ b/src/lib/efl/interfaces/efl_io_queue.c @@ -297,6 +297,30 @@ _efl_io_queue_efl_io_reader_read(Eo *o, Efl_Io_Queue_Data *pd, Eina_Rw_Slice *rw return EINVAL; } +EOLIAN static void +_efl_io_queue_discard(Eo *o, Efl_Io_Queue_Data *pd, size_t amount) +{ + size_t available; + + EINA_SAFETY_ON_TRUE_RETURN(efl_io_closer_closed_get(o)); + + available = pd->position_write - pd->position_read; + if (amount > available) + { + amount = available; + if (amount == 0) + return; + } + + pd->position_read += amount; + + efl_io_reader_can_read_set(o, pd->position_read < pd->position_write); + efl_event_callback_call(o, EFL_IO_QUEUE_EVENT_SLICE_CHANGED, NULL); + + if ((pd->pending_eos) && (efl_io_queue_usage_get(o) == 0)) + efl_io_reader_eos_set(o, EINA_TRUE); +} + EOLIAN static Eina_Bool _efl_io_queue_efl_io_reader_can_read_get(Eo *o EINA_UNUSED, Efl_Io_Queue_Data *pd) { diff --git a/src/lib/efl/interfaces/efl_io_queue.eo b/src/lib/efl/interfaces/efl_io_queue.eo index 748d580..c5d5ac4 100644 --- a/src/lib/efl/interfaces/efl_io_queue.eo +++ b/src/lib/efl/interfaces/efl_io_queue.eo @@ -58,8 +58,36 @@ class Efl.Io.Queue (Efl.Object, Efl.Io.Reader, Efl.Io.Writer, Efl.Io.Closer) { return: bool (false); [[$true on success, $false otherwise]] } + discard { + [[Discard the given number of bytes. + + This has the same effect as reading and discarding the + given amount of bytes, without executing the actual + copy. + + It's often paired with @.slice_get, if users read the + information from the slice and once they're done, that + data must be discarded. + + As an example, some protocols provide messages with a + "size" header, then @.slice_get is used to peek into the + available memory to see if there is a "size" and if the + rest of the slice is the full payload, in this case the + slice may be handled to some processing function. When + the function is done, that amount of data must be + discarded -- with this function. + ]] + params { + amount: size; [[Bytes to discard]] + } + } + clear { - [[Clear the queue. Same as reading all data]] + [[Clear the queue. Same as reading all data. + + This is equivalent as calling @.discard with @.usage + amount of bytes. + ]] } eos_mark { --
