static int makeChannel(MprCmd *cmd, int index) { MprCmdFile *file; int nonBlock; static int tempSeed = 0; file = &cmd->files[index]; file->name = sfmt("/pipe/%s_%d_%d", ME_NAME, taskIdSelf(), tempSeed++); if (pipeDevCreate(file->name, 6, ME_BUFSIZE) < 0) { mprLog("error mpr cmd", 0, "Cannot create pipes to run %s", cmd->program); return MPR_ERR_CANT_OPEN; } /* Open the server end of the pipe. MPR_CMD_STDIN is from the client's perspective. */ if (index == MPR_CMD_STDIN) { file->fd = open(file->name, O_WRONLY, 0644); } else { file->fd = open(file->name, O_RDONLY, 0644); } if (file->fd < 0) { mprLog("error mpr cmd", 0, "Cannot create stdio pipes. Err %d", mprGetOsError()); return MPR_ERR_CANT_CREATE; } nonBlock = 1; ioctl(file->fd, FIONBIO, (int) &nonBlock); return 0; }
static int makeChannel(MprCmd *cmd, int index) { MprCmdFile *file; static int tempSeed = 0; file = &cmd->files[index]; file->name = mprAsprintf(cmd, -1, "/pipe/%s_%d_%d", BLD_PRODUCT, taskIdSelf(), tempSeed++); if (pipeDevCreate(file->name, 5, MPR_BUFSIZE) < 0) { mprError(cmd, "Can't create pipes to run %s", cmd->program); return MPR_ERR_CANT_OPEN; } /* * Open the server end of the pipe. MPR_CMD_STDIN is from the client's perspective. */ if (index == MPR_CMD_STDIN) { file->fd = open(file->name, O_WRONLY, 0644); } else { file->fd = open(file->name, O_RDONLY, 0644); } if (file->fd < 0) { mprError(cmd, "Can't create stdio pipes. Err %d", mprGetOsError()); return MPR_ERR_CANT_CREATE; } return 0; }
int initSelectPipe() { int rc = pipeDevCreate (SELECT_PIPE_NAME, 100, 10); sysAssume(rc == OK); selectPipeFD = open(SELECT_PIPE_NAME, O_RDWR | O_NONBLOCK); //fprintf(stderr, "initSelectPipe: fd = %d\n", selectPipeFD); return (selectPipeFD == -1) ? -1 : 0; }
QEventDispatcherUNIXPrivate::QEventDispatcherUNIXPrivate() { extern Qt::HANDLE qt_application_thread_id; mainThread = (QThread::currentThreadId() == qt_application_thread_id); bool pipefail = false; // initialize the common parts of the event loop #if defined(Q_OS_NACL) || defined (Q_OS_BLACKBERRY) // do nothing. #elif defined(Q_OS_INTEGRITY) // INTEGRITY doesn't like a "select" on pipes, so use socketpair instead if (socketpair(AF_INET, SOCK_STREAM, 0, thread_pipe) == -1) { perror("QEventDispatcherUNIXPrivate(): Unable to create socket pair"); pipefail = true; } else { initThreadPipeFD(thread_pipe[0]); initThreadPipeFD(thread_pipe[1]); } #elif defined(Q_OS_VXWORKS) char name[20]; qsnprintf(name, sizeof(name), "/pipe/qt_%08x", int(taskIdSelf())); // make sure there is no pipe with this name pipeDevDelete(name, true); // create the pipe if (pipeDevCreate(name, 128 /*maxMsg*/, 1 /*maxLength*/) != OK) { perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe device"); pipefail = true; } else { if ((thread_pipe[0] = open(name, O_RDWR, 0)) < 0) { perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe"); pipefail = true; } else { initThreadPipeFD(thread_pipe[0]); thread_pipe[1] = thread_pipe[0]; } } #else # ifndef QT_NO_EVENTFD thread_pipe[0] = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (thread_pipe[0] != -1) thread_pipe[1] = -1; else // fall through the next "if" # endif if (qt_safe_pipe(thread_pipe, O_NONBLOCK) == -1) { perror("QEventDispatcherUNIXPrivate(): Unable to create thread pipe"); pipefail = true; } #endif if (pipefail) qFatal("QEventDispatcherUNIXPrivate(): Can not continue without a thread pipe"); sn_highest = -1; }
struct graphhost_t * GraphHost_create(int port) { /* int i; */ struct graphhost_t *inst; int pipefd[2]; #ifndef __VXWORKS__ int error; #endif /* Allocate memory for the graphhost_t structure */ inst = malloc(sizeof(struct graphhost_t)); /* Mark the thread as not running, this will be set to 1 by the thread */ inst->running = 0; /* Store the port to listen on */ inst->port = port; /* Create a pipe for IPC with the thread */ #ifdef __VXWORKS__ pipeDevCreate("/pipe/graphhost", 10, 100); pipefd[0] = open("/pipe/graphhost", O_RDONLY, 0644); pipefd[1] = open("/pipe/graphhost", O_WRONLY, 0644); if(pipefd[0] == -1 || pipefd[1] == -1) { perror(""); free(inst); return NULL; } #else error = pipe(pipefd); if(error == -1) { perror(""); free(inst); return NULL; } #endif inst->ipcfd_r = pipefd[0]; inst->ipcfd_w = pipefd[1]; /* Launch the thread */ if(pthread_create(&inst->thread, NULL, sockets_threadmain, (void *)inst) != 0) { fprintf(stderr, "pthread_create(3) failed\n"); free(inst); return NULL; } return inst; }
ClInt32T clCreatePipe(ClInt32T fds[2], ClUint32T numMsgs, ClUint32T msgSize) { static ClInt32T numPipes; char pipeName[CL_MAX_NAME_LENGTH]; static char compName[CL_MAX_NAME_LENGTH]; int fd; if(!numMsgs) numMsgs = CL_VXWORKS_PIPE_MSGS; if(!msgSize) msgSize = CL_VXWORKS_PIPE_MSGSIZE; if(!compName[0]) { char *str = getenv("ASP_COMPNAME"); if(!str) { str = "nodeRep"; } strncpy(compName, str, sizeof(compName)-1); } pthread_mutex_lock(&pipeLock); snprintf(pipeName, sizeof(pipeName)-1, "/%s%d", compName, numPipes); fd = pipeDevCreate(pipeName, numMsgs, msgSize); if(fd < 0) { pthread_mutex_unlock(&pipeLock); printf("pipe dev create for device [%s] returned [%s]\n", pipeName, strerror(errno)); return fd; } fd = open(pipeName, O_RDWR, 0666); if(fd < 0 ) { pthread_mutex_unlock(&pipeLock); printf("pipe dev open [%s] returned [%s]\n", pipeName, strerror(errno)); return fd; } ++numPipes; pthread_mutex_unlock(&pipeLock); fds[0] = fd; fds[1] = fd; return 0; }