From 25a9e1d886054d3907fb43e3682525b1a3901209 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Mon, 19 Dec 2016 14:46:37 -0200 Subject: [PATCH] Efl.Io.{Queue,Buffer,Buffered_Stream}: slice_get is now a property. Previously we couldn't return a slice, instead required the user to pass a slice and we'd fill it since Eolian couldn't generate fallbacks for structures. Since @q66 fixed eolian, we can now return the structure itself as initially wanted, ditching some TODO from the code. --- src/bin/eeze/eeze_scanner_monitor.c | 6 +- src/bin/efl/efl_debug_common.c | 4 +- .../ecore/efl_io_buffered_stream_example.c | 4 +- src/examples/ecore/efl_io_copier_example.c | 26 ++---- src/examples/ecore/efl_io_queue_example.c | 4 +- src/examples/ecore/efl_net_dialer_simple_example.c | 15 +-- src/examples/ecore/efl_net_server_example.c | 102 +++++++++------------ src/examples/ecore/efl_net_server_simple_example.c | 15 +-- src/lib/ecore/efl_io_buffered_stream.c | 20 ++-- src/lib/ecore/efl_io_buffered_stream.eo | 20 ++-- src/lib/ecore_con/ecore_con_legacy.c | 4 +- src/lib/ecore_con/efl_net_dialer_simple.eo | 4 +- src/lib/ecore_con/efl_net_socket_simple.eo | 4 +- src/lib/efl/interfaces/efl_io_buffer.c | 16 ++-- src/lib/efl/interfaces/efl_io_buffer.eo | 12 +-- src/lib/efl/interfaces/efl_io_queue.c | 16 ++-- src/lib/efl/interfaces/efl_io_queue.eo | 14 +-- 17 files changed, 122 insertions(+), 164 deletions(-) diff --git a/src/bin/eeze/eeze_scanner_monitor.c b/src/bin/eeze/eeze_scanner_monitor.c index afed23c..fd01d2c 100644 --- a/src/bin/eeze/eeze_scanner_monitor.c +++ b/src/bin/eeze/eeze_scanner_monitor.c @@ -70,11 +70,7 @@ _on_data(void *data, const Efl_Event *event) Eo *dialer = event->object; Eina_Slice slice; - if (!efl_io_buffered_stream_slice_get(dialer, &slice)) - { - fprintf(stderr, "ERROR: could not get buffered stream slice\n"); - goto error; - } + slice = efl_io_buffered_stream_slice_get(dialer); if (slice.len == 0) return; if (eet_connection_received(ec, slice.mem, slice.len) != 0) diff --git a/src/bin/efl/efl_debug_common.c b/src/bin/efl/efl_debug_common.c index 28e44c2..f37f17f 100644 --- a/src/bin/efl/efl_debug_common.c +++ b/src/bin/efl/efl_debug_common.c @@ -24,9 +24,7 @@ received_data(Eo *sock, void (*handle)(void *data, const char op[static 4], cons Eina_Slice slice, payload; Efl_Debug_Message_Header msgheader; - if (!efl_io_buffered_stream_slice_get(sock, &slice)) - return EINA_TRUE; - + slice = efl_io_buffered_stream_slice_get(sock); if (slice.len < sizeof(msgheader)) return EINA_TRUE; diff --git a/src/examples/ecore/efl_io_buffered_stream_example.c b/src/examples/ecore/efl_io_buffered_stream_example.c index ec8ff1f..9e1a7ec 100644 --- a/src/examples/ecore/efl_io_buffered_stream_example.c +++ b/src/examples/ecore/efl_io_buffered_stream_example.c @@ -38,9 +38,7 @@ _command_next(void) static void _receiver_data(void *data EINA_UNUSED, const Efl_Event *event) { - Eina_Slice slice; - - if (!efl_io_buffered_stream_slice_get(event->object, &slice)) return; + Eina_Slice slice = efl_io_buffered_stream_slice_get(event->object); /* this will happen when we're called when we issue our own * efl_io_buffered_stream_clear() below. diff --git a/src/examples/ecore/efl_io_copier_example.c b/src/examples/ecore/efl_io_copier_example.c index 4bde9a5..50295bf 100644 --- a/src/examples/ecore/efl_io_copier_example.c +++ b/src/examples/ecore/efl_io_copier_example.c @@ -43,13 +43,7 @@ EFL_CALLBACKS_ARRAY_DEFINE(output_cbs, static void _output_buffer_reallocated(void *data EINA_UNUSED, const Efl_Event *event) { - Eina_Slice slice; - - if (!efl_io_buffer_slice_get(event->object, &slice)) - { - fprintf(stderr, "ERROR: could not get buffer slice\n"); - return; - } + Eina_Slice slice = efl_io_buffer_slice_get(event->object); fprintf(stderr, "INFO: output buffer reallocated=" EINA_SLICE_FMT "\n", EINA_SLICE_PRINT(slice)); @@ -196,17 +190,13 @@ _copier_done(void *data EINA_UNUSED, const Efl_Event *event) * an Eina_Binbuf, you own the ownership and must call * eina_binbuf_free() to release it. */ - Eina_Slice slice; - - if (!efl_io_buffer_slice_get(destination, &slice)) - fprintf(stderr, "ERROR: could not get buffer slice\n"); - else - fprintf(stderr, - "INFO: :memory: resulted in slice=" EINA_SLICE_FMT ":" - "\n--BEGIN DATA--\n" - EINA_SLICE_STR_FMT - "\n--END DATA--\n", - EINA_SLICE_PRINT(slice), EINA_SLICE_STR_PRINT(slice)); + Eina_Slice slice = efl_io_buffer_slice_get(destination); + fprintf(stderr, + "INFO: :memory: resulted in slice=" EINA_SLICE_FMT ":" + "\n--BEGIN DATA--\n" + EINA_SLICE_STR_FMT + "\n--END DATA--\n", + EINA_SLICE_PRINT(slice), EINA_SLICE_STR_PRINT(slice)); } fprintf(stderr, "INFO: done\n"); diff --git a/src/examples/ecore/efl_io_queue_example.c b/src/examples/ecore/efl_io_queue_example.c index 9b5f3a2..d1097ef 100644 --- a/src/examples/ecore/efl_io_queue_example.c +++ b/src/examples/ecore/efl_io_queue_example.c @@ -39,9 +39,7 @@ _command_next(void) static void _receiver_data(void *data EINA_UNUSED, const Efl_Event *event) { - Eina_Slice slice; - - if (!efl_io_queue_slice_get(event->object, &slice)) return; + Eina_Slice slice = efl_io_queue_slice_get(event->object); /* this will happen when we're called when we issue our own * efl_io_queue_clear() below. diff --git a/src/examples/ecore/efl_net_dialer_simple_example.c b/src/examples/ecore/efl_net_dialer_simple_example.c index 9b790c8..7411a58 100644 --- a/src/examples/ecore/efl_net_dialer_simple_example.c +++ b/src/examples/ecore/efl_net_dialer_simple_example.c @@ -28,22 +28,17 @@ _connected(void *data EINA_UNUSED, const Efl_Event *event) static void _eos(void *data EINA_UNUSED, const Efl_Event *event) { - Eina_Slice s; - fprintf(stderr, "INFO: end of stream.\n"); /* on _error() we close it, then do not read as it has nothing */ if (efl_io_closer_closed_get(event->object)) return; - if (efl_io_buffered_stream_slice_get(event->object, &s)) - { - fprintf(stderr, - "-- BEGIN RECEIVED DATA --\n" - EINA_SLICE_STR_FMT - "-- END RECEIVED DATA--\n", - EINA_SLICE_STR_PRINT(s)); - } + fprintf(stderr, + "-- BEGIN RECEIVED DATA --\n" + EINA_SLICE_STR_FMT + "-- END RECEIVED DATA--\n", + EINA_SLICE_STR_PRINT(efl_io_buffered_stream_slice_get(event->object))); } static void diff --git a/src/examples/ecore/efl_net_server_example.c b/src/examples/ecore/efl_net_server_example.c index edd5408..22efdd0 100644 --- a/src/examples/ecore/efl_net_server_example.c +++ b/src/examples/ecore/efl_net_server_example.c @@ -142,19 +142,16 @@ _send_copier_done(void *data, const Efl_Event *event) Eo *buffer = efl_io_copier_source_get(copier); Eo *client = efl_io_copier_destination_get(copier); Send_Recv_Data *d = data; - Eina_Slice slice; + Eina_Slice slice = efl_io_buffer_slice_get(buffer); /* show what we sent, just for debug */ - if (!efl_io_buffer_slice_get(buffer, &slice)) - fprintf(stderr, "ERROR: could not get buffer slice\n"); - else - fprintf(stderr, - "INFO: sent to %s %zd bytes:" - "\n--BEGIN SENT DATA--\n" - EINA_SLICE_STR_FMT - "\n--END SENT DATA--\n", - efl_net_socket_address_remote_get(client), - slice.len, EINA_SLICE_STR_PRINT(slice)); + fprintf(stderr, + "INFO: sent to %s %zd bytes:" + "\n--BEGIN SENT DATA--\n" + EINA_SLICE_STR_FMT + "\n--END SENT DATA--\n", + efl_net_socket_address_remote_get(client), + slice.len, EINA_SLICE_STR_PRINT(slice)); if (d->recv_copier) { @@ -175,7 +172,7 @@ _send_copier_error(void *data, const Efl_Event *event) const Eina_Error *perr = event->info; Send_Recv_Data *d = data; uint64_t offset; - Eina_Slice slice; + Eina_Slice slice, remaining; if (*perr == ETIMEDOUT) { @@ -188,30 +185,26 @@ _send_copier_error(void *data, const Efl_Event *event) retval = EXIT_FAILURE; offset = efl_io_buffer_position_read_get(buffer); - if (!efl_io_buffer_slice_get(buffer, &slice)) - fprintf(stderr, "ERROR: could not get buffer slice\n"); - else - { - Eina_Slice remaining = slice; - - remaining.bytes += offset; - remaining.len -= offset; - - slice.len = offset; - - fprintf(stderr, - "ERROR: sent to %s only %zd bytes:" - "\n--BEGIN SENT DATA--\n" - EINA_SLICE_STR_FMT - "\n--END SENT DATA--\n" - "Remaining %zd bytes:" - "\n--BEGIN REMAINING DATA--\n" - EINA_SLICE_STR_FMT - "\n--END REMAINING DATA--\n", - efl_net_socket_address_remote_get(client), - slice.len, EINA_SLICE_STR_PRINT(slice), - remaining.len, EINA_SLICE_STR_PRINT(remaining)); - } + slice = efl_io_buffer_slice_get(buffer); + + remaining = slice; + remaining.bytes += offset; + remaining.len -= offset; + + slice.len = offset; + + fprintf(stderr, + "ERROR: sent to %s only %zd bytes:" + "\n--BEGIN SENT DATA--\n" + EINA_SLICE_STR_FMT + "\n--END SENT DATA--\n" + "Remaining %zd bytes:" + "\n--BEGIN REMAINING DATA--\n" + EINA_SLICE_STR_FMT + "\n--END REMAINING DATA--\n", + efl_net_socket_address_remote_get(client), + slice.len, EINA_SLICE_STR_PRINT(slice), + remaining.len, EINA_SLICE_STR_PRINT(remaining)); fprintf(stderr, "ERROR: send copier %p failed %d '%s', check if should close..\n", copier, *perr, eina_error_msg_get(*perr)); @@ -229,7 +222,7 @@ _recv_copier_done(void *data, const Efl_Event *event) Eo *client = efl_io_copier_source_get(copier); Eo *buffer = efl_io_copier_destination_get(copier); Send_Recv_Data *d = data; - Eina_Slice slice; + Eina_Slice slice = efl_io_buffer_slice_get(buffer); /* show case, you could use a copier to Efl_Io_Stdout, a * file... and get progressive processing. @@ -240,16 +233,13 @@ _recv_copier_done(void *data, const Efl_Event *event) * You could also steal the binbuf with * efl_io_buffer_binbuf_steal() */ - if (!efl_io_buffer_slice_get(buffer, &slice)) - fprintf(stderr, "ERROR: could not get buffer slice\n"); - else - fprintf(stderr, - "INFO: recv from %s %zd bytes:" - "\n--BEGIN RECV DATA--\n" - EINA_SLICE_STR_FMT "\n" - "\n--END RECV DATA--\n", - efl_net_socket_address_remote_get(client), - slice.len, EINA_SLICE_STR_PRINT(slice)); + fprintf(stderr, + "INFO: recv from %s %zd bytes:" + "\n--BEGIN RECV DATA--\n" + EINA_SLICE_STR_FMT "\n" + "\n--END RECV DATA--\n", + efl_net_socket_address_remote_get(client), + slice.len, EINA_SLICE_STR_PRINT(slice)); fprintf(stderr, "INFO: receive copier done, check if should close %p\n", copier); _send_recv_done(d, copier); @@ -275,16 +265,14 @@ _recv_copier_error(void *data, const Efl_Event *event) retval = EXIT_FAILURE; - if (!efl_io_buffer_slice_get(buffer, &slice)) - fprintf(stderr, "ERROR: could not get buffer slice\n"); - else - fprintf(stderr, - "ERROR: recv to %s only %zd bytes:" - "\n--BEGIN RECV DATA--\n" - EINA_SLICE_STR_FMT "\n" - "\n--END RECV DATA--\n", - efl_net_socket_address_remote_get(client), - slice.len, EINA_SLICE_STR_PRINT(slice)); + slice = efl_io_buffer_slice_get(buffer); + fprintf(stderr, + "ERROR: recv to %s only %zd bytes:" + "\n--BEGIN RECV DATA--\n" + EINA_SLICE_STR_FMT "\n" + "\n--END RECV DATA--\n", + efl_net_socket_address_remote_get(client), + slice.len, EINA_SLICE_STR_PRINT(slice)); fprintf(stderr, "ERROR: receive copier %p failed %d '%s', check if should close..\n", copier, *perr, eina_error_msg_get(*perr)); diff --git a/src/examples/ecore/efl_net_server_simple_example.c b/src/examples/ecore/efl_net_server_simple_example.c index cef0a3a..548dd92 100644 --- a/src/examples/ecore/efl_net_server_simple_example.c +++ b/src/examples/ecore/efl_net_server_simple_example.c @@ -37,22 +37,17 @@ _client_eos(void *data EINA_UNUSED, const Efl_Event *event) static void _client_read_finished(void *data EINA_UNUSED, const Efl_Event *event) { - Eina_Slice s; - /* on _error() we close it, then do not read as it has nothing */ if (efl_io_closer_closed_get(event->object)) return; if (echo) return; - if (efl_io_buffered_stream_slice_get(event->object, &s)) - { - fprintf(stderr, - "-- BEGIN RECEIVED DATA --\n" - EINA_SLICE_STR_FMT - "-- END RECEIVED DATA--\n", - EINA_SLICE_STR_PRINT(s)); - } + fprintf(stderr, + "-- BEGIN RECEIVED DATA --\n" + EINA_SLICE_STR_FMT + "-- END RECEIVED DATA--\n", + EINA_SLICE_STR_PRINT(efl_io_buffered_stream_slice_get(event->object))); } static void diff --git a/src/lib/ecore/efl_io_buffered_stream.c b/src/lib/ecore/efl_io_buffered_stream.c index 82de769..a54d125 100644 --- a/src/lib/ecore/efl_io_buffered_stream.c +++ b/src/lib/ecore/efl_io_buffered_stream.c @@ -533,19 +533,15 @@ _efl_io_buffered_stream_progress_get(Eo *o EINA_UNUSED, Efl_Io_Buffered_Stream_D if (pw) *pw = w; } -EOLIAN static Eina_Bool -_efl_io_buffered_stream_slice_get(Eo *o EINA_UNUSED, Efl_Io_Buffered_Stream_Data *pd, Eina_Slice *slice) +EOLIAN static Eina_Slice +_efl_io_buffered_stream_slice_get(Eo *o EINA_UNUSED, Efl_Io_Buffered_Stream_Data *pd) { - if (!pd->incoming) - { - if (slice) - { - slice->mem = NULL; - slice->len = 0; - } - return EINA_FALSE; - } - return efl_io_queue_slice_get(pd->incoming, slice); + Eina_Slice slice = { }; + + if (pd->incoming) + slice = efl_io_queue_slice_get(pd->incoming); + + return slice; } EOLIAN static void diff --git a/src/lib/ecore/efl_io_buffered_stream.eo b/src/lib/ecore/efl_io_buffered_stream.eo index fd8f1a9..e7ebcfa 100644 --- a/src/lib/ecore/efl_io_buffered_stream.eo +++ b/src/lib/ecore/efl_io_buffered_stream.eo @@ -19,13 +19,13 @@ class Efl.Io.Buffered_Stream (Efl.Loop_User, Efl.Io.Reader, Efl.Io.Writer, Efl.I Reading is also much simpler since incoming data is kept in an @Efl.Io.Queue, thus its size can be queried with @.pending_read - and read with @Efl.Io.Reader.read or peeked with @.slice_get, + and read with @Efl.Io.Reader.read or peeked with @.slice, then discarded with @.discard or @.clear. Then when waiting for a complete message, just peek at its contents, if not complete do nothing and wait, if complete then either @Efl.Io.Reader.read to get a copy or manipulate a - read-only reference from @.slice_get and then @.discard + read-only reference from @.slice and then @.discard The actual I/O is set with the constructor method @.inner_io.set and can be retrieved with @.inner_io.get, which should be used @@ -155,17 +155,17 @@ class Efl.Io.Buffered_Stream (Efl.Loop_User, Efl.Io.Reader, Efl.Io.Writer, Efl.I } } - slice_get { // TODO: property and return of Eina.Slice (not pointer) + @property slice { [[Get a temporary access to input queue's internal read memory. The memory pointed by slice may be changed by other methods of this class. The event "slice,changed" will be called in those situations. ]] - params { - @out slice: Eina.Slice; [[Slice of the current buffer, may be invalidated if @Efl.Io.Writer.write, @Efl.Io.Closer.close or @Efl.Io.Reader.read are called. It is the full slice available for reading.]] + get { } + values { + slice: Eina.Slice; [[Slice of the current buffer, may be invalidated if @Efl.Io.Writer.write, @Efl.Io.Closer.close or @Efl.Io.Reader.read are called. It is the full slice available for reading.]] } - return: bool (false); [[$true on success, $false otherwise]] } discard { @@ -175,12 +175,12 @@ class Efl.Io.Buffered_Stream (Efl.Loop_User, Efl.Io.Reader, Efl.Io.Writer, Efl.I given amount of bytes, without executing the actual copy. - It's often paired with @.slice_get, if users read the + It's often paired with @.slice, 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 + "size" header, then @.slice 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 @@ -241,8 +241,8 @@ class Efl.Io.Buffered_Stream (Efl.Loop_User, Efl.Io.Reader, Efl.Io.Writer, Efl.I finished; [[Both read and write are finished.]] error: Eina.Error; [[An error happened and the I/O stopped]] progress; [[Property @.progress changed]] - slice,changed; [[The read-slice returned by @.slice_get may have changed.]] - line: ptr(const(Eina.Slice)); [[If @.line_delimiter is set, will be emitted with current line. The memory is only valid during event callback dispatched and should not be modified. Note that the line slice may not be inside @.slice_get, don't assume that!]] + slice,changed; [[The read-slice returned by @.slice may have changed.]] + line: ptr(const(Eina.Slice)); [[If @.line_delimiter is set, will be emitted with current line. The memory is only valid during event callback dispatched and should not be modified. Note that the line slice may not be inside @.slice, don't assume that!]] } implements { diff --git a/src/lib/ecore_con/ecore_con_legacy.c b/src/lib/ecore_con/ecore_con_legacy.c index 684c25d..54b929d 100644 --- a/src/lib/ecore_con/ecore_con_legacy.c +++ b/src/lib/ecore_con/ecore_con_legacy.c @@ -530,7 +530,7 @@ _ecore_con_client_socket_slice_changed(void *data, const Efl_Event *event EINA_U if (cl->delete_me) return; if (cl->ssl.upgrading) return; - if (!efl_io_buffered_stream_slice_get(cl->socket, &ro_slice)) return; + ro_slice = efl_io_buffered_stream_slice_get(cl->socket); if (ro_slice.len == 0) return; rw_slice = eina_slice_dup(ro_slice); @@ -1211,7 +1211,7 @@ _ecore_con_server_dialer_slice_changed(void *data, const Efl_Event *event EINA_U if (svr->delete_me) return; if (svr->ssl.upgrading) return; - if (!efl_io_buffered_stream_slice_get(svr->dialer, &ro_slice)) return; + ro_slice = efl_io_buffered_stream_slice_get(svr->dialer); if (ro_slice.len == 0) return; rw_slice = eina_slice_dup(ro_slice); diff --git a/src/lib/ecore_con/efl_net_dialer_simple.eo b/src/lib/ecore_con/efl_net_dialer_simple.eo index 2d51234..22e40b0 100644 --- a/src/lib/ecore_con/efl_net_dialer_simple.eo +++ b/src/lib/ecore_con/efl_net_dialer_simple.eo @@ -20,14 +20,14 @@ class Efl.Net.Dialer.Simple (Efl.Net.Socket.Simple, Efl.Net.Dialer) { @Efl.Io.Queue, thus its size can be queried with @Efl.Io.Buffered_Stream.pending_read and read with @Efl.Io.Reader.read or peeked with - @Efl.Io.Buffered_Stream.slice_get, then discarded with + @Efl.Io.Buffered_Stream.slice, then discarded with @Efl.Io.Buffered_Stream.discard or @Efl.Io.Buffered_Stream.clear. Then when waiting for a complete message, just peek at its contents, if not complete do nothing, if complete then either @Efl.Io.Reader.read to get a copy or manipulate a read-only - reference from @Efl.Io.Buffered_Stream.slice_get and then + reference from @Efl.Io.Buffered_Stream.slice and then @Efl.Io.Buffered_Stream.discard The actual dialer is created using the class given as the diff --git a/src/lib/ecore_con/efl_net_socket_simple.eo b/src/lib/ecore_con/efl_net_socket_simple.eo index b6339ac..bfdd24f 100644 --- a/src/lib/ecore_con/efl_net_socket_simple.eo +++ b/src/lib/ecore_con/efl_net_socket_simple.eo @@ -19,14 +19,14 @@ class Efl.Net.Socket.Simple (Efl.Io.Buffered_Stream, Efl.Net.Socket) { @Efl.Io.Queue, thus its size can be queried with @Efl.Io.Buffered_Stream.pending_read and read with @Efl.Io.Reader.read or peeked with - @Efl.Io.Buffered_Stream.slice_get, then discarded with + @Efl.Io.Buffered_Stream.slice, then discarded with @Efl.Io.Buffered_Stream.discard or @Efl.Io.Buffered_Stream.clear. Then when waiting for a complete message, just peek at its contents, if not complete do nothing, if complete then either @Efl.Io.Reader.read to get a copy or manipulate a read-only - reference from @Efl.Io.Buffered_Stream.slice_get and then + reference from @Efl.Io.Buffered_Stream.slice and then @Efl.Io.Buffered_Stream.discard The actual socket is set with the constructor method diff --git a/src/lib/efl/interfaces/efl_io_buffer.c b/src/lib/efl/interfaces/efl_io_buffer.c index f60fe65..66b5338 100644 --- a/src/lib/efl/interfaces/efl_io_buffer.c +++ b/src/lib/efl/interfaces/efl_io_buffer.c @@ -107,16 +107,18 @@ _efl_io_buffer_limit_get(Eo *o EINA_UNUSED, Efl_Io_Buffer_Data *pd) return pd->limit; } -EOLIAN static Eina_Bool -_efl_io_buffer_slice_get(Eo *o, Efl_Io_Buffer_Data *pd, Eina_Slice *slice) +EOLIAN static Eina_Slice +_efl_io_buffer_slice_get(Eo *o, Efl_Io_Buffer_Data *pd) { - if (slice) + Eina_Slice slice = { }; + + if (!efl_io_closer_closed_get(o)) { - slice->mem = pd->bytes; - slice->len = efl_io_sizer_size_get(o); + slice.mem = pd->bytes; + slice.len = efl_io_sizer_size_get(o); } - EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_io_closer_closed_get(o), EINA_FALSE); - return EINA_TRUE; + + return slice; } EOLIAN static Eina_Binbuf * diff --git a/src/lib/efl/interfaces/efl_io_buffer.eo b/src/lib/efl/interfaces/efl_io_buffer.eo index 5912858..30b75d2 100644 --- a/src/lib/efl/interfaces/efl_io_buffer.eo +++ b/src/lib/efl/interfaces/efl_io_buffer.eo @@ -6,7 +6,7 @@ class Efl.Io.Buffer (Efl.Object, Efl.Io.Reader, Efl.Io.Writer, Efl.Io.Closer, Ef use different offsets/position internally. One can get temporary direct access to internal buffer with - @.slice_get or steal the buffer with @.binbuf_steal. + @.slice or steal the buffer with @.binbuf_steal. A fixed sized buffer can be implemented by setting @.limit followed by @.preallocate @@ -78,17 +78,17 @@ class Efl.Io.Buffer (Efl.Object, Efl.Io.Reader, Efl.Io.Writer, Efl.Io.Closer, Ef } } - slice_get { // TODO: property and return of Eina.Slice (not pointer) + @property slice { [[Get a temporary access to buffer's internal memory. The memory pointed by slice may be changed by other methods of this class. The event "reallocated" will be called in those situations. ]] - params { - @out slice: Eina.Slice; [[Slice of the current buffer, may be invalidated if @Efl.Io.Writer.write, @Efl.Io.Closer.close or @Efl.Io.Sizer.resize are called. It is the full slice, not a partial one starting at current position.]] + get { } + values { + slice: Eina.Slice; [[Slice of the current buffer, may be invalidated if @Efl.Io.Writer.write, @Efl.Io.Closer.close or @Efl.Io.Sizer.resize are called. It is the full slice, not a partial one starting at current position.]] } - return: bool (false); [[$true on success, $false otherwise]] } binbuf_steal { @@ -103,7 +103,7 @@ class Efl.Io.Buffer (Efl.Object, Efl.Io.Reader, Efl.Io.Writer, Efl.Io.Closer, Ef events { position_read,changed; [[Notifies @.position_read changed]] position_write,changed; [[Notifies @.position_write changed]] - reallocated; [[Notifies the internal buffer was reallocated, thus whatever was returned by @.slice_get becomes invalid]] + reallocated; [[Notifies the internal buffer was reallocated, thus whatever was returned by @.slice becomes invalid]] } implements { diff --git a/src/lib/efl/interfaces/efl_io_queue.c b/src/lib/efl/interfaces/efl_io_queue.c index 503adc6..deda2d6 100644 --- a/src/lib/efl/interfaces/efl_io_queue.c +++ b/src/lib/efl/interfaces/efl_io_queue.c @@ -200,16 +200,18 @@ _efl_io_queue_usage_get(Eo *o EINA_UNUSED, Efl_Io_Queue_Data *pd) return pd->position_write - pd->position_read; } -EOLIAN static Eina_Bool -_efl_io_queue_slice_get(Eo *o, Efl_Io_Queue_Data *pd, Eina_Slice *slice) +EOLIAN static Eina_Slice +_efl_io_queue_slice_get(Eo *o, Efl_Io_Queue_Data *pd) { - if (slice) + Eina_Slice slice = { }; + + if (!efl_io_closer_closed_get(o)) { - slice->mem = pd->bytes + pd->position_read; - slice->len = efl_io_queue_usage_get(o); + slice.mem = pd->bytes + pd->position_read; + slice.len = efl_io_queue_usage_get(o); } - EINA_SAFETY_ON_TRUE_RETURN_VAL(efl_io_closer_closed_get(o), EINA_FALSE); - return EINA_TRUE; + + return slice; } EOLIAN static void diff --git a/src/lib/efl/interfaces/efl_io_queue.eo b/src/lib/efl/interfaces/efl_io_queue.eo index c5d5ac4..e3457ed 100644 --- a/src/lib/efl/interfaces/efl_io_queue.eo +++ b/src/lib/efl/interfaces/efl_io_queue.eo @@ -45,17 +45,17 @@ class Efl.Io.Queue (Efl.Object, Efl.Io.Reader, Efl.Io.Writer, Efl.Io.Closer) { } } - slice_get { // TODO: property and return of Eina.Slice (not pointer) + @property slice { [[Get a temporary access to queue's internal read memory. The memory pointed by slice may be changed by other methods of this class. The event "slice,changed" will be called in those situations. ]] - params { - @out slice: Eina.Slice; [[Slice of the current buffer, may be invalidated if @Efl.Io.Writer.write, @Efl.Io.Closer.close or @Efl.Io.Reader.read are called. It is the full slice available for reading.]] + get { } + values { + slice: Eina.Slice; [[Slice of the current buffer, may be invalidated if @Efl.Io.Writer.write, @Efl.Io.Closer.close or @Efl.Io.Reader.read are called. It is the full slice available for reading.]] } - return: bool (false); [[$true on success, $false otherwise]] } discard { @@ -65,12 +65,12 @@ class Efl.Io.Queue (Efl.Object, Efl.Io.Reader, Efl.Io.Writer, Efl.Io.Closer) { given amount of bytes, without executing the actual copy. - It's often paired with @.slice_get, if users read the + It's often paired with @.slice, 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 + "size" header, then @.slice 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 @@ -102,7 +102,7 @@ class Efl.Io.Queue (Efl.Object, Efl.Io.Reader, Efl.Io.Writer, Efl.Io.Closer) { } events { - slice,changed; [[The read-slice returned by @.slice_get may have changed.]] + slice,changed; [[The read-slice returned by @.slice may have changed.]] } implements { -- 2.7.4