From 06608f632e9fad1d500dd9ef8bc5f838ebabd037 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Wed, 26 Oct 2016 12:46:09 -0200 Subject: [PATCH] efl_io_copier_example: allow udp as input/source. now that we have a 'bind', let's use the given address as bind and dial to `0.0.0.0` or `::`. This allows the dialer to receive data at the given address and make the example useful. --- src/examples/ecore/efl_io_copier_example.c | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/examples/ecore/efl_io_copier_example.c b/src/examples/ecore/efl_io_copier_example.c index cedd41b09e..222cec594c 100644 --- a/src/examples/ecore/efl_io_copier_example.c +++ b/src/examples/ecore/efl_io_copier_example.c @@ -335,6 +335,7 @@ static const Ecore_Getopt options = { "tcp://IP:PORT to connect using TCP and an IPv4 (A.B.C.D:PORT) or IPv6 ([A:B:C:D::E]:PORT).\n" "http://address to do a GET request\n" "ws://address or wss:// to do WebSocket request (must send some data once connected)\n" + "udp://IP:PORT to bind using UDP and an IPv4 (A.B.C.D:PORT) or IPv6 ([A:B:C:D::E]:PORT).\n" "", "input-file"), ECORE_GETOPT_STORE_METAVAR_STR(0, NULL, @@ -504,6 +505,38 @@ main(int argc, char **argv) goto end_input; } } + else if (strncmp(input_fname, "udp://", strlen("udp://")) == 0) + { + /* + * Since Efl.Net.Socket implements the required interfaces, + * they can be used here as well. + */ + const char *bind_address = input_fname + strlen("udp://"); + const char *address; + Eina_Error err; + input = efl_add(EFL_NET_DIALER_UDP_CLASS, ecore_main_loop_get(), + efl_net_socket_udp_bind_set(efl_added, bind_address), /* use the address as the bind, so we can get data at it */ + efl_event_callback_array_add(efl_added, input_cbs(), NULL), /* optional */ + efl_event_callback_array_add(efl_added, dialer_cbs(), NULL) /* optional */ + ); + if (!input) + { + fprintf(stderr, "ERROR: could not create UDP Dialer.\n"); + retval = EXIT_FAILURE; + goto end; + } + + if (bind_address[0] == '[') address = "[::]"; + else address = "0.0.0.0"; + + err = efl_net_dialer_dial(input, address); + if (err) + { + fprintf(stderr, "ERROR: could not UDP dial %s: %s\n", + address, eina_error_msg_get(err)); + goto end_input; + } + } else { /* regular file, open with flags: read-only and close-on-exec */