/** * Create two file descriptors (sockets on Windows). Add * a callback that will be called when the file descriptor that * is listened receives data. An event is also put in the event * queue when data is received. * * @param handler The handler called when data is received. * @param data Data to pass to @p handler when it is called. * @return A newly created Ecore_Pipe object if successful. * @c NULL otherwise. */ EAPI Ecore_Pipe * ecore_pipe_add(Ecore_Pipe_Cb handler, const void *data) { Ecore_Pipe *p; int fds[2]; EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); if (!handler) return NULL; p = ecore_pipe_calloc(1); if (!p) return NULL; if (pipe(fds)) { ecore_pipe_mp_free(p); return NULL; } ECORE_MAGIC_SET(p, ECORE_MAGIC_PIPE); p->fd_read = fds[0]; p->fd_write = fds[1]; p->handler = handler; p->data = data; fcntl(p->fd_read, F_SETFL, O_NONBLOCK); p->fd_handler = ecore_main_fd_handler_add(p->fd_read, ECORE_FD_READ, _ecore_pipe_read, p, NULL, NULL); return p; }
void * _ecore_pipe_del(Ecore_Pipe *p) { void *data = NULL; if (!ECORE_MAGIC_CHECK(p, ECORE_MAGIC_PIPE)) { ECORE_MAGIC_FAIL(p, ECORE_MAGIC_PIPE, "ecore_pipe_del"); return NULL; } p->delete_me = EINA_TRUE; if (p->handling > 0) return (void *)p->data; if (p->fd_handler) _ecore_main_fd_handler_del(p->fd_handler); if (p->fd_read != PIPE_FD_INVALID) pipe_close(p->fd_read); if (p->fd_write != PIPE_FD_INVALID) pipe_close(p->fd_write); data = (void *)p->data; ecore_pipe_mp_free(p); return data; }