Proper renaming of vars and methods
To reflect what they really are. I was confused for a while about loops and FDs.
This commit is contained in:
parent
f16cef85db
commit
c106ec6d44
|
@ -18,7 +18,7 @@
|
|||
* read or write to an FD without blocking.
|
||||
*/
|
||||
|
||||
static void _read_loop_create();
|
||||
static void _read_fd_create();
|
||||
|
||||
static void
|
||||
_print_loop(Efl_Loop *loop, const char *label)
|
||||
|
@ -27,20 +27,20 @@ _print_loop(Efl_Loop *loop, const char *label)
|
|||
}
|
||||
|
||||
static void
|
||||
_loop_fd_read_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
_read_fd_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
{
|
||||
Efl_Loop_Fd *loop_fd;
|
||||
Efl_Loop_Fd *efl_fd;
|
||||
char buf[7];
|
||||
int len;
|
||||
|
||||
loop_fd = event->object;
|
||||
efl_fd = event->object;
|
||||
|
||||
len = read(efl_loop_fd_file_get(loop_fd), &buf, sizeof(buf));
|
||||
len = read(efl_loop_fd_file_get(efl_fd), &buf, sizeof(buf));
|
||||
|
||||
// here we are exiting
|
||||
if (len <= 0)
|
||||
{
|
||||
efl_del(loop_fd);
|
||||
efl_del(efl_fd);
|
||||
unlink(FILENAME);
|
||||
|
||||
efl_exit(0);
|
||||
|
@ -48,68 +48,68 @@ _loop_fd_read_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
|||
}
|
||||
|
||||
buf[len] = 0;
|
||||
_print_loop(loop_fd, "Reading from");
|
||||
printf("Reading from: %s\n", efl_name_get(efl_fd));
|
||||
}
|
||||
|
||||
static void
|
||||
_loop_fd_write_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
_write_fd_cb(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
{
|
||||
Efl_Loop_Fd *loop_fd;
|
||||
Efl_Loop_Fd *efl_fd;
|
||||
static int _count = 0;
|
||||
|
||||
loop_fd = event->object;
|
||||
efl_fd = event->object;
|
||||
|
||||
// we have outputted all we want to, remove the write handler
|
||||
// start checking for read availability instead
|
||||
// we have output all we wanted, remove the write handler
|
||||
// and start checking for read availability instead
|
||||
if (_count >= 5)
|
||||
{
|
||||
efl_del(loop_fd);
|
||||
efl_del(efl_fd);
|
||||
|
||||
_read_loop_create();
|
||||
_read_fd_create();
|
||||
return;
|
||||
}
|
||||
|
||||
_count++;
|
||||
_print_loop(loop_fd, "Writing from");
|
||||
write(efl_loop_fd_file_get(loop_fd), eina_slstr_printf("TEST %d\n", _count), 7);
|
||||
printf("Writing to: %s\n", efl_name_get(efl_fd));
|
||||
write(efl_loop_fd_file_get(efl_fd), eina_slstr_printf("TEST %d\n", _count), 7);
|
||||
}
|
||||
|
||||
static void
|
||||
_write_loop_create()
|
||||
_write_fd_create()
|
||||
{
|
||||
Efl_Loop_Fd *loop_fd;
|
||||
Efl_Loop_Fd *efl_fd;
|
||||
FILE *file;
|
||||
int fd;
|
||||
|
||||
loop_fd = efl_add(EFL_LOOP_FD_CLASS, NULL,
|
||||
efl_name_set(efl_added, "Write Loop"));
|
||||
efl_fd = efl_add(EFL_LOOP_FD_CLASS, NULL,
|
||||
efl_name_set(efl_added, "Write FD"));
|
||||
|
||||
efl_event_callback_add(loop_fd, EFL_LOOP_FD_EVENT_WRITE, _loop_fd_write_cb, NULL);
|
||||
efl_event_callback_add(efl_fd, EFL_LOOP_FD_EVENT_WRITE, _write_fd_cb, NULL);
|
||||
|
||||
file = fopen(FILENAME, "w+");
|
||||
fd = fileno(file);
|
||||
|
||||
printf("Opened file %s with fd %d\n", FILENAME, fd);
|
||||
efl_loop_fd_file_set(loop_fd, fd);
|
||||
efl_loop_fd_file_set(efl_fd, fd);
|
||||
}
|
||||
|
||||
static void
|
||||
_read_loop_create()
|
||||
_read_fd_create()
|
||||
{
|
||||
Efl_Loop_Fd *loop_fd;
|
||||
Efl_Loop_Fd *efl_fd;
|
||||
FILE *file;
|
||||
int fd;
|
||||
|
||||
loop_fd = efl_add(EFL_LOOP_FD_CLASS, NULL,
|
||||
efl_name_set(efl_added, "Read Loop"));
|
||||
efl_fd = efl_add(EFL_LOOP_FD_CLASS, NULL,
|
||||
efl_name_set(efl_added, "Read FD"));
|
||||
|
||||
efl_event_callback_add(loop_fd, EFL_LOOP_FD_EVENT_READ, _loop_fd_read_cb, NULL);
|
||||
efl_event_callback_add(efl_fd, EFL_LOOP_FD_EVENT_READ, _read_fd_cb, NULL);
|
||||
|
||||
file = fopen(FILENAME, "r");
|
||||
fd = fileno(file);
|
||||
|
||||
printf("Opened file %s with fd %d\n", FILENAME, fd);
|
||||
efl_loop_fd_file_set(loop_fd, fd);
|
||||
efl_loop_fd_file_set(efl_fd, fd);
|
||||
}
|
||||
|
||||
EAPI_MAIN void
|
||||
|
@ -118,11 +118,10 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
|
|||
const Efl_Version *version;
|
||||
Efl_Loop *loop;
|
||||
|
||||
version = efl_loop_efl_version_get(ev->object);
|
||||
loop = ev->object;
|
||||
version = efl_loop_efl_version_get(loop);
|
||||
printf("Running on EFL version %d.%d.%d [%s]\n\n", version->major, version->minor,
|
||||
version->micro, version->build_id);
|
||||
|
||||
loop = ev->object;
|
||||
_print_loop(loop, "Current");
|
||||
|
||||
loop = efl_loop_main_get(loop);
|
||||
|
@ -134,8 +133,8 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
|
|||
efl_del(loop);
|
||||
printf("\n");
|
||||
|
||||
_write_loop_create();
|
||||
// we will call _read_loop_create() once write is complete!
|
||||
_write_fd_create();
|
||||
// we will call _read_fd_create() once write is complete!
|
||||
|
||||
// we will exit from the end of the read loop
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue