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");
}
}
int
main(void)
{
Ecore_Pipe *pipe;
pid_t child_pid;
pipe = ecore_pipe_add(handler, NULL);
child_pid = fork();
if (!child_pid)
{
do_lengthy_task(pipe);
}
else
{
}
return 0;
}