/* Snipped from https://stackoverflow.com/a/2486353 */ #include #include #include #include #include "CO_notify_pipe.h" #include "CO_error.h" CO_NotifyPipe_t *CO_NotifyPipeCreate(void) { int pipefd[2]; CO_NotifyPipe_t *p; int ret = pipe(pipefd); if (ret < 0) { return NULL; } p = calloc(1, sizeof(CO_NotifyPipe_t)); if (p == NULL) { return NULL; } p->m_receiveFd = pipefd[0]; p->m_sendFd = pipefd[1]; fcntl(p->m_sendFd,F_SETFL,O_NONBLOCK); return p; } void CO_NotifyPipeFree(CO_NotifyPipe_t *p) { if (p == NULL) { return; } close(p->m_sendFd); close(p->m_receiveFd); free(p); } int CO_NotifyPipeGetFd(CO_NotifyPipe_t *p) { if (p == NULL) { return -1; } return p->m_receiveFd; } void CO_NotifyPipeSend(CO_NotifyPipe_t *p) { ssize_t ret; if (p == NULL) { return; } ret = write(p->m_sendFd,"1",1); if(ret < 0){ log_printf(LOG_DEBUG, DBG_ERRNO, "write()"); } }