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;
}
EAPI int ecore_shutdown(void)
Shuts down connections, signal handlers sockets etc.
Definition: ecore.c:371
EAPI int ecore_init(void)
Sets up connections, signal handlers, sockets etc.
Definition: ecore.c:230
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
void ecore_main_loop_begin(void)
Runs the application main loop.
Definition: ecore_main.c:1311
struct _Ecore_Pipe Ecore_Pipe
A handle for pipes.
Definition: Ecore_Common.h:2416
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
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 * ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data)
Creates two file descriptors (sockets on Windows).
Definition: ecore_pipe.c:93
void * ecore_pipe_del(Ecore_Pipe *p)
Frees an Ecore_Pipe object created with ecore_pipe_add().
Definition: ecore_pipe.c:100
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
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339