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.
This commit is contained in:
Gustavo Sverzut Barbieri 2016-12-19 14:46:37 -02:00
parent 6979be8215
commit 8c2013d090
6 changed files with 62 additions and 98 deletions

View File

@ -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.

View File

@ -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");

View File

@ -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.

View File

@ -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

View File

@ -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;
slice = efl_io_buffer_slice_get(buffer);
remaining.bytes += offset;
remaining.len -= offset;
remaining = slice;
remaining.bytes += offset;
remaining.len -= offset;
slice.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: 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));

View File

@ -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