Lines Matching defs:pipe
44 /* The timeout that the pipe will wait for the remote end to write data when
51 static char pipe_prefix[] = "\\\\?\\pipe";
93 static void eof_timer_init(uv_pipe_t* pipe);
94 static void eof_timer_start(uv_pipe_t* pipe);
95 static void eof_timer_stop(uv_pipe_t* pipe);
97 static void eof_timer_destroy(uv_pipe_t* pipe);
102 snprintf(name, size, "\\\\?\\pipe\\uv\\%p-%lu", ptr, GetCurrentProcessId());
112 handle->pipe.conn.ipc_remote_pid = 0;
113 handle->pipe.conn.ipc_data_frame.payload_remaining = 0;
114 QUEUE_INIT(&handle->pipe.conn.ipc_xfer_queue);
115 handle->pipe.conn.ipc_xfer_queue_length = 0;
117 handle->pipe.conn.non_overlapped_writes_tail = NULL;
127 handle->pipe.conn.eof_timer = NULL;
135 * Assume that we have a duplex pipe first, so attempt to
151 * If the pipe is not duplex CreateFileW fails with
189 static void close_pipe(uv_pipe_t* pipe) {
190 assert(pipe->u.fd == -1 || pipe->u.fd > 2);
191 if (pipe->u.fd == -1)
192 CloseHandle(pipe->handle);
194 close(pipe->u.fd);
196 pipe->u.fd = -1;
197 pipe->handle = INVALID_HANDLE_VALUE;
277 /* Create server pipe handle. */
286 /* Create client pipe handle. */
304 /* Validate that the pipe was opened in the right mode. */
318 * both ends of the pipe created. */
402 * the state of the write buffer when we're trying to shutdown the pipe. */
486 * something that is not a pipe. */
494 /* Check if the pipe was created with FILE_FLAG_OVERLAPPED. */
506 /* Non-overlapped pipe. */
508 handle->pipe.conn.readfile_thread_handle = NULL;
509 InitializeCriticalSection(&handle->pipe.conn.readfile_thread_lock);
511 /* Overlapped pipe. Try to associate with IOCP. */
597 /* Try to avoid flushing the pipe buffer in the thread pool. */
640 while (!QUEUE_EMPTY(&handle->pipe.conn.ipc_xfer_queue)) {
644 q = QUEUE_HEAD(&handle->pipe.conn.ipc_xfer_queue);
660 handle->pipe.conn.ipc_xfer_queue_length = 0;
674 DeleteCriticalSection(&handle->pipe.conn.readfile_thread_lock);
678 assert(handle->pipe.serv.accept_reqs);
679 uv__free(handle->pipe.serv.accept_reqs);
680 handle->pipe.serv.accept_reqs = NULL;
690 handle->pipe.serv.pending_instances = count;
695 /* Creates a pipe server. */
712 handle->pipe.serv.pending_instances = default_pending_pipe_instances;
715 handle->pipe.serv.accept_reqs = (uv_pipe_accept_t*)
716 uv__malloc(sizeof(uv_pipe_accept_t) * handle->pipe.serv.pending_instances);
717 if (!handle->pipe.serv.accept_reqs) {
721 for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
722 req = &handle->pipe.serv.accept_reqs[i];
747 * Attempt to create the first pipe with FILE_FLAG_FIRST_PIPE_INSTANCE.
748 * If this fails then there's already a pipe server for the given pipe name.
752 &handle->pipe.serv.accept_reqs[0],
763 handle->pipe.serv.pending_accepts = NULL;
793 /* We're here because CreateFile on a pipe returned ERROR_PIPE_BUSY. We wait
794 * up to 30 seconds for the pipe to become available with WaitNamedPipe. */
796 /* The pipe is now available, try to connect. */
862 /* Wait for the server to make a pipe instance available. */
924 volatile HANDLE* thread_ptr = &handle->pipe.conn.readfile_thread_handle;
926 EnterCriticalSection(&handle->pipe.conn.readfile_thread_lock);
945 LeaveCriticalSection(&handle->pipe.conn.readfile_thread_lock);
988 for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
989 pipeHandle = handle->pipe.serv.accept_reqs[i].pipeHandle;
992 handle->pipe.serv.accept_reqs[i].pipeHandle = INVALID_HANDLE_VALUE;
1058 if (QUEUE_EMPTY(&server->pipe.conn.ipc_xfer_queue)) {
1063 q = QUEUE_HEAD(&server->pipe.conn.ipc_xfer_queue);
1065 server->pipe.conn.ipc_xfer_queue_length--;
1081 req = server->pipe.serv.pending_accepts;
1093 server->pipe.serv.pending_accepts = req->next_pending;
1107 /* Starts listening for connections for the given pipe. */
1136 /* First pipe handle should have already been created in uv_pipe_bind */
1137 assert(handle->pipe.serv.accept_reqs[0].pipeHandle != INVALID_HANDLE_VALUE);
1139 for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
1140 uv__pipe_queue_accept(loop, handle, &handle->pipe.serv.accept_reqs[i], i == 0);
1151 volatile HANDLE* thread_ptr = &handle->pipe.conn.readfile_thread_handle;
1152 CRITICAL_SECTION* lock = &handle->pipe.conn.readfile_thread_lock;
1189 /* Block the thread until data is available on the pipe, or the read is
1296 handle->pipe.conn.readfile_thread_handle = NULL; /* Reset cancellation. */
1379 if (handle->pipe.conn.non_overlapped_writes_tail) {
1381 handle->pipe.conn.non_overlapped_writes_tail->next_req;
1382 handle->pipe.conn.non_overlapped_writes_tail->next_req = (uv_req_t*)req;
1383 handle->pipe.conn.non_overlapped_writes_tail = req;
1386 handle->pipe.conn.non_overlapped_writes_tail = req;
1394 if (handle->pipe.conn.non_overlapped_writes_tail) {
1395 req = (uv_write_t*)handle->pipe.conn.non_overlapped_writes_tail->next_req;
1397 if (req == handle->pipe.conn.non_overlapped_writes_tail) {
1398 handle->pipe.conn.non_overlapped_writes_tail = NULL;
1400 handle->pipe.conn.non_overlapped_writes_tail->next_req =
1636 DWORD* pid = &handle->pipe.conn.ipc_remote_pid;
1638 /* If the both ends of the IPC pipe are owned by the same process,
1758 /* IPC pipe write: use framing protocol. */
1761 /* Non-IPC pipe write: put data on the wire directly. */
1815 QUEUE_INSERT_TAIL(&handle->pipe.conn.ipc_xfer_queue, &item->member);
1816 handle->pipe.conn.ipc_xfer_queue_length++;
1820 /* Read an exact number of bytes from a pipe. If an error or end-of-file is
1880 uint32_t* data_remaining = &handle->pipe.conn.ipc_data_frame.payload_remaining;
1970 * reading the pipe in the meantime, there is nothing left to do, since there
1998 /* Depending on the type of pipe, read either IPC frames or raw data. */
2067 handle->pipe.conn.non_overlapped_writes_tail) {
2095 req->next_pending = handle->pipe.serv.pending_accepts;
2096 handle->pipe.serv.pending_accepts = req;
2163 /* Initialize and optionally start the eof timer. Only do this if the pipe
2174 /* This pipe is not readable. We can just close it to let the other end
2188 static void eof_timer_init(uv_pipe_t* pipe) {
2191 assert(pipe->pipe.conn.eof_timer == NULL);
2192 assert(pipe->flags & UV_HANDLE_CONNECTION);
2194 pipe->pipe.conn.eof_timer = (uv_timer_t*) uv__malloc(sizeof *pipe->pipe.conn.eof_timer);
2196 r = uv_timer_init(pipe->loop, pipe->pipe.conn.eof_timer);
2199 pipe->pipe.conn.eof_timer->data = pipe;
2200 uv_unref((uv_handle_t*) pipe->pipe.conn.eof_timer);
2204 static void eof_timer_start(uv_pipe_t* pipe) {
2205 assert(pipe->flags & UV_HANDLE_CONNECTION);
2207 if (pipe->pipe.conn.eof_timer != NULL) {
2208 uv_timer_start(pipe->pipe.conn.eof_timer, eof_timer_cb, eof_timeout, 0);
2213 static void eof_timer_stop(uv_pipe_t* pipe) {
2214 assert(pipe->flags & UV_HANDLE_CONNECTION);
2216 if (pipe->pipe.conn.eof_timer != NULL) {
2217 uv_timer_stop(pipe->pipe.conn.eof_timer);
2223 uv_pipe_t* pipe = (uv_pipe_t*) timer->data;
2226 assert(pipe->type == UV_NAMED_PIPE);
2232 assert(pipe->flags & UV_HANDLE_READ_PENDING);
2238 if ((pipe->flags & UV_HANDLE_READ_PENDING) &&
2239 HasOverlappedIoCompleted(&pipe->read_req.u.io.overlapped)) {
2243 /* Force both ends off the pipe. */
2244 close_pipe(pipe);
2248 uv_read_stop((uv_stream_t*) pipe);
2252 uv__pipe_read_eof(loop, pipe, uv_null_buf_);
2256 static void eof_timer_destroy(uv_pipe_t* pipe) {
2257 assert(pipe->flags & UV_HANDLE_CONNECTION);
2259 if (pipe->pipe.conn.eof_timer) {
2260 uv_close((uv_handle_t*) pipe->pipe.conn.eof_timer, eof_timer_close_cb);
2261 pipe->pipe.conn.eof_timer = NULL;
2272 int uv_pipe_open(uv_pipe_t* pipe, uv_file file) {
2282 if (pipe->flags & UV_HANDLE_PIPESERVER)
2284 if (pipe->flags & UV_HANDLE_CONNECTION)
2287 uv__pipe_connection_init(pipe);
2309 * Cygwin opens the pipe in message mode, but we can support it,
2320 if (pipe->ipc) {
2332 err = uv__set_pipe_handle(pipe->loop,
2333 pipe,
2343 if (pipe->ipc) {
2344 assert(!(pipe->flags & UV_HANDLE_NON_OVERLAPPED_PIPE));
2345 pipe->pipe.conn.ipc_remote_pid = uv_os_getppid();
2346 assert(pipe->pipe.conn.ipc_remote_pid != (DWORD)(uv_pid_t) -1);
2417 * blocking operation on the queried handle. If the pipe handle is
2419 * the pipe handle, which could cause a deadlock. To avoid this, interrupt
2484 /* "\\\\.\\pipe" + name */
2522 return handle->pipe.conn.ipc_xfer_queue_length;
2560 if (handle->pipe.conn.ipc_xfer_queue_length == 0)