ecore_pipe_simple_example.c
//Compile with:
//gcc -g -Wall -o ecore_pipe_simple_example ecore_pipe_simple_example.c `pkg-config --cflags --libs ecore`
#include <unistd.h>
#include <Ecore.h>
static void
do_lengthy_task(Ecore_Pipe *pipe)
{
int i, j;
char *buffer;
for (i = 0; i < 20; i++)
{
sleep(1);
buffer = malloc(sizeof(char) * i);
for (j = 0; j < i; j++)
buffer[j] = 'a' + j;
ecore_pipe_write(pipe, buffer, i);
free(buffer);
}
ecore_pipe_write(pipe, "close", 5);
}
static void
handler(void *data EINA_UNUSED, void *buf, unsigned int len)
{
char *str = malloc(sizeof(char) * len + 1);
memcpy(str, buf, len);
str[len] = '\0';
printf("received %u bytes\n", len);
printf("content: %s\n", (const char *)str);
free(str);
if (len && !strncmp(buf, "close", len < 5 ? len : 5))
{
printf("close requested\n");
ecore_main_loop_quit();
}
}
int
main(void)
{
Ecore_Pipe *pipe;
pid_t child_pid;
ecore_init();
pipe = ecore_pipe_add(handler, NULL);
child_pid = fork();
if (!child_pid)
{
ecore_pipe_read_close(pipe);
do_lengthy_task(pipe);
}
else
{
ecore_pipe_write_close(pipe);
ecore_main_loop_begin();
}
ecore_pipe_del(pipe);
ecore_shutdown();
return 0;
}
ecore_shutdown
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition ecore.c:371
ecore_init
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition ecore.c:230
ecore_main_loop_quit
void ecore_main_loop_quit(void)
Quits the main loop once all the events currently on the queue have been processed.
Definition ecore_main.c:1321
ecore_main_loop_begin
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition ecore_main.c:1311
Ecore_Pipe
struct _Ecore_Pipe Ecore_Pipe
A handle for pipes.
Definition Ecore_Common.h:2422
ecore_pipe_write
Eina_Bool ecore_pipe_write(Ecore_Pipe *p, const void *buffer, unsigned int nbytes)
Writes on the file descriptor the data passed as parameter.
Definition ecore_pipe.c:199
ecore_pipe_write_close
void ecore_pipe_write_close(Ecore_Pipe *p)
Closes the write end of an Ecore_Pipe object created with ecore_pipe_add().
Definition ecore_pipe.c:176
ecore_pipe_add
Ecore_Pipe * ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data)
Creates two file descriptors (sockets on Windows).
Definition ecore_pipe.c:93
ecore_pipe_del
void * ecore_pipe_del(Ecore_Pipe *p)
Frees an Ecore_Pipe object created with ecore_pipe_add().
Definition ecore_pipe.c:100
ecore_pipe_read_close
void ecore_pipe_read_close(Ecore_Pipe *p)
Closes the read end of an Ecore_Pipe object created with ecore_pipe_add().
Definition ecore_pipe.c:108
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition eina_types.h:339