net: simplify io example - no need for full lifecycle
This commit is contained in:
parent
42de664854
commit
d226ee2c98
|
@ -18,6 +18,39 @@ static Eina_List *_commands = NULL;
|
|||
static Eina_Slice _delimiter;
|
||||
static Eo *_dialer = NULL, *_sender = NULL, *_receiver = NULL;
|
||||
|
||||
// call this method to cleanly shut down our example
|
||||
static void
|
||||
_quit(int retval)
|
||||
{
|
||||
if (_waiting)
|
||||
{
|
||||
fprintf(stderr, "ERROR: %d operations were waiting!\n",
|
||||
eina_list_count(_waiting));
|
||||
eina_list_free(_waiting);
|
||||
_waiting = NULL;
|
||||
}
|
||||
|
||||
if (_receiver)
|
||||
{
|
||||
efl_io_closer_close(_receiver);
|
||||
efl_del(efl_io_copier_destination_get(_receiver));
|
||||
efl_del(_receiver);
|
||||
}
|
||||
|
||||
if (_sender)
|
||||
{
|
||||
efl_io_closer_close(_sender);
|
||||
efl_del(efl_io_copier_source_get(_sender));
|
||||
efl_del(_sender);
|
||||
}
|
||||
|
||||
if (_dialer)
|
||||
efl_del(_dialer);
|
||||
|
||||
efl_exit(retval);
|
||||
}
|
||||
|
||||
// iterate through the commands to send through the dialler
|
||||
static void
|
||||
_command_next(void)
|
||||
{
|
||||
|
@ -85,7 +118,7 @@ _copier_done(void *data EINA_UNUSED, const Efl_Event *event)
|
|||
|
||||
_waiting = eina_list_remove(_waiting, event->object);
|
||||
if (!_waiting)
|
||||
efl_exit(EXIT_SUCCESS);
|
||||
_quit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -96,52 +129,13 @@ _copier_error(void *data EINA_UNUSED, const Efl_Event *event)
|
|||
fprintf(stderr, "INFO: %s error: #%d '%s'\n",
|
||||
efl_name_get(event->object), *perr, eina_error_msg_get(*perr));
|
||||
|
||||
efl_exit(EXIT_FAILURE);
|
||||
_quit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
EFL_CALLBACKS_ARRAY_DEFINE(copier_cbs,
|
||||
{ EFL_IO_COPIER_EVENT_DONE, _copier_done },
|
||||
{ EFL_IO_COPIER_EVENT_ERROR, _copier_error });
|
||||
|
||||
EAPI void
|
||||
efl_pause(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
EAPI void
|
||||
efl_resume(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
||||
{
|
||||
}
|
||||
|
||||
EAPI void
|
||||
efl_terminate(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
||||
{
|
||||
if (_waiting)
|
||||
{
|
||||
fprintf(stderr, "ERROR: %d operations were waiting!\n",
|
||||
eina_list_count(_waiting));
|
||||
eina_list_free(_waiting);
|
||||
_waiting = NULL;
|
||||
}
|
||||
|
||||
if (_receiver)
|
||||
{
|
||||
efl_io_closer_close(_receiver);
|
||||
efl_del(efl_io_copier_destination_get(_receiver));
|
||||
efl_del(_receiver);
|
||||
}
|
||||
|
||||
if (_sender)
|
||||
{
|
||||
efl_io_closer_close(_sender);
|
||||
efl_del(efl_io_copier_source_get(_sender));
|
||||
efl_del(_sender);
|
||||
}
|
||||
|
||||
if (_dialer)
|
||||
efl_del(_dialer);
|
||||
}
|
||||
|
||||
EAPI_MAIN void
|
||||
efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
||||
{
|
||||
|
@ -170,7 +164,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
if (!send_queue)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create Efl_Io_Queue (send)\n");
|
||||
efl_exit(EXIT_FAILURE);
|
||||
_quit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -192,7 +186,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
if (!receive_queue)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create Efl_Io_Queue (receive)\n");
|
||||
efl_exit(EXIT_FAILURE);
|
||||
_quit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -209,7 +203,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
if (!_dialer)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create Efl_Net_Dialer_Tcp\n");
|
||||
efl_exit(EXIT_FAILURE);
|
||||
_quit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* sender: send_queue->network */
|
||||
|
@ -222,7 +216,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
if (!_sender)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create Efl_Io_Copier (sender)\n");
|
||||
efl_exit(EXIT_FAILURE);
|
||||
_quit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* receiver: network->receive_queue */
|
||||
|
@ -235,7 +229,7 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
if (!_receiver)
|
||||
{
|
||||
fprintf(stderr, "ERROR: could not create Efl_Io_Copier (receiver)\n");
|
||||
efl_exit(EXIT_FAILURE);
|
||||
_quit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
err = efl_net_dialer_dial(_dialer, address);
|
||||
|
@ -243,11 +237,11 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
|
|||
{
|
||||
fprintf(stderr, "ERROR: could not dial %s: %s\n",
|
||||
address, eina_error_msg_get(err));
|
||||
efl_exit(EXIT_FAILURE);
|
||||
_quit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
_waiting = eina_list_append(_waiting, _sender);
|
||||
_waiting = eina_list_append(_waiting, _receiver);
|
||||
}
|
||||
EFL_MAIN_EX()
|
||||
EFL_MAIN()
|
||||
|
||||
|
|
Loading…
Reference in New Issue