Lines Matching refs:handle

98 static void eof_timer_close_cb(uv_handle_t* handle);
114 int uv_pipe_init(uv_loop_t* loop, uv_pipe_t* handle, int ipc) { in uv_pipe_init() argument
115 uv__stream_init(loop, (uv_stream_t*)handle, UV_NAMED_PIPE); in uv_pipe_init()
117 handle->reqs_pending = 0; in uv_pipe_init()
118 handle->handle = INVALID_HANDLE_VALUE; in uv_pipe_init()
119 handle->name = NULL; in uv_pipe_init()
120 handle->pipe.conn.ipc_remote_pid = 0; in uv_pipe_init()
121 handle->pipe.conn.ipc_data_frame.payload_remaining = 0; in uv_pipe_init()
122 uv__queue_init(&handle->pipe.conn.ipc_xfer_queue); in uv_pipe_init()
123 handle->pipe.conn.ipc_xfer_queue_length = 0; in uv_pipe_init()
124 handle->ipc = ipc; in uv_pipe_init()
125 handle->pipe.conn.non_overlapped_writes_tail = NULL; in uv_pipe_init()
131 static void uv__pipe_connection_init(uv_pipe_t* handle) { in uv__pipe_connection_init() argument
132 assert(!(handle->flags & UV_HANDLE_PIPESERVER)); in uv__pipe_connection_init()
133 uv__connection_init((uv_stream_t*) handle); in uv__pipe_connection_init()
134 handle->read_req.data = handle; in uv__pipe_connection_init()
135 handle->pipe.conn.eof_timer = NULL; in uv__pipe_connection_init()
200 CloseHandle(pipe->handle); in close_pipe()
205 pipe->handle = INVALID_HANDLE_VALUE; in close_pipe()
441 parent_pipe->handle = server_pipe; in uv__create_stdio_pipe_pair()
464 uv_pipe_t* handle, in uv__set_pipe_handle() argument
475 assert(handle->flags & UV_HANDLE_CONNECTION); in uv__set_pipe_handle()
476 assert(!(handle->flags & UV_HANDLE_PIPESERVER)); in uv__set_pipe_handle()
477 if (handle->flags & UV_HANDLE_CLOSING) in uv__set_pipe_handle()
479 if (handle->handle != INVALID_HANDLE_VALUE) in uv__set_pipe_handle()
520 handle->flags |= UV_HANDLE_NON_OVERLAPPED_PIPE; in uv__set_pipe_handle()
521 handle->pipe.conn.readfile_thread_handle = NULL; in uv__set_pipe_handle()
522 InitializeCriticalSection(&handle->pipe.conn.readfile_thread_lock); in uv__set_pipe_handle()
527 (ULONG_PTR) handle, in uv__set_pipe_handle()
529 handle->flags |= UV_HANDLE_EMULATE_IOCP; in uv__set_pipe_handle()
533 handle->handle = pipeHandle; in uv__set_pipe_handle()
534 handle->u.fd = fd; in uv__set_pipe_handle()
535 handle->flags |= duplex_flags; in uv__set_pipe_handle()
541 static int pipe_alloc_accept(uv_loop_t* loop, uv_pipe_t* handle, in pipe_alloc_accept() argument
546 CreateNamedPipeW(handle->name, in pipe_alloc_accept()
559 (ULONG_PTR) handle, in pipe_alloc_accept()
567 handle->handle = req->pipeHandle; in pipe_alloc_accept()
575 uv_pipe_t* handle; in pipe_shutdown_thread_proc() local
580 handle = (uv_pipe_t*) req->handle; in pipe_shutdown_thread_proc()
581 assert(handle); in pipe_shutdown_thread_proc()
582 loop = handle->loop; in pipe_shutdown_thread_proc()
585 FlushFileBuffers(handle->handle); in pipe_shutdown_thread_proc()
594 void uv__pipe_shutdown(uv_loop_t* loop, uv_pipe_t* handle, uv_shutdown_t *req) { in uv__pipe_shutdown() argument
600 assert(handle->flags & UV_HANDLE_CONNECTION); in uv__pipe_shutdown()
602 assert(handle->stream.conn.write_reqs_pending == 0); in uv__pipe_shutdown()
605 if (handle->flags & UV_HANDLE_CLOSING) { in uv__pipe_shutdown()
611 nt_status = pNtQueryInformationFile(handle->handle, in uv__pipe_shutdown()
619 handle->flags |= UV_HANDLE_WRITABLE; /* Questionable. */ in uv__pipe_shutdown()
637 handle->flags |= UV_HANDLE_WRITABLE; /* Questionable. */ in uv__pipe_shutdown()
644 void uv__pipe_endgame(uv_loop_t* loop, uv_pipe_t* handle) { in uv__pipe_endgame() argument
647 assert(handle->reqs_pending == 0); in uv__pipe_endgame()
648 assert(handle->flags & UV_HANDLE_CLOSING); in uv__pipe_endgame()
649 assert(!(handle->flags & UV_HANDLE_CLOSED)); in uv__pipe_endgame()
651 if (handle->flags & UV_HANDLE_CONNECTION) { in uv__pipe_endgame()
653 while (!uv__queue_empty(&handle->pipe.conn.ipc_xfer_queue)) { in uv__pipe_endgame()
657 q = uv__queue_head(&handle->pipe.conn.ipc_xfer_queue); in uv__pipe_endgame()
673 handle->pipe.conn.ipc_xfer_queue_length = 0; in uv__pipe_endgame()
675 assert(handle->read_req.wait_handle == INVALID_HANDLE_VALUE); in uv__pipe_endgame()
676 if (handle->read_req.event_handle != NULL) { in uv__pipe_endgame()
677 CloseHandle(handle->read_req.event_handle); in uv__pipe_endgame()
678 handle->read_req.event_handle = NULL; in uv__pipe_endgame()
681 if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) in uv__pipe_endgame()
682 DeleteCriticalSection(&handle->pipe.conn.readfile_thread_lock); in uv__pipe_endgame()
685 if (handle->flags & UV_HANDLE_PIPESERVER) { in uv__pipe_endgame()
686 assert(handle->pipe.serv.accept_reqs); in uv__pipe_endgame()
687 uv__free(handle->pipe.serv.accept_reqs); in uv__pipe_endgame()
688 handle->pipe.serv.accept_reqs = NULL; in uv__pipe_endgame()
691 uv__handle_close(handle); in uv__pipe_endgame()
695 void uv_pipe_pending_instances(uv_pipe_t* handle, int count) { in uv_pipe_pending_instances() argument
696 if (handle->flags & UV_HANDLE_BOUND) in uv_pipe_pending_instances()
698 handle->pipe.serv.pending_instances = count; in uv_pipe_pending_instances()
699 handle->flags |= UV_HANDLE_PIPESERVER; in uv_pipe_pending_instances()
704 int uv_pipe_bind(uv_pipe_t* handle, const char* name) { in uv_pipe_bind() argument
705 return uv_pipe_bind2(handle, name, strlen(name), 0); in uv_pipe_bind()
709 int uv_pipe_bind2(uv_pipe_t* handle, in uv_pipe_bind2() argument
713 uv_loop_t* loop = handle->loop; in uv_pipe_bind2()
734 if (handle->flags & UV_HANDLE_BOUND) { in uv_pipe_bind2()
738 if (uv__is_closing(handle)) { in uv_pipe_bind2()
750 if (!(handle->flags & UV_HANDLE_PIPESERVER)) { in uv_pipe_bind2()
751 handle->pipe.serv.pending_instances = default_pending_pipe_instances; in uv_pipe_bind2()
755 handle->pipe.serv.accept_reqs = (uv_pipe_accept_t*) in uv_pipe_bind2()
756 uv__malloc(sizeof(uv_pipe_accept_t) * handle->pipe.serv.pending_instances); in uv_pipe_bind2()
757 if (handle->pipe.serv.accept_reqs == NULL) { in uv_pipe_bind2()
761 for (i = 0; i < handle->pipe.serv.pending_instances; i++) { in uv_pipe_bind2()
762 req = &handle->pipe.serv.accept_reqs[i]; in uv_pipe_bind2()
764 req->data = handle; in uv_pipe_bind2()
770 err = uv__convert_utf8_to_utf16(name_copy, &handle->name); in uv_pipe_bind2()
783 handle, in uv_pipe_bind2()
784 &handle->pipe.serv.accept_reqs[0], in uv_pipe_bind2()
797 handle->pipe.serv.pending_accepts = NULL; in uv_pipe_bind2()
798 handle->flags |= UV_HANDLE_PIPESERVER; in uv_pipe_bind2()
799 handle->flags |= UV_HANDLE_BOUND; in uv_pipe_bind2()
804 uv__free(handle->pipe.serv.accept_reqs); in uv_pipe_bind2()
805 uv__free(handle->name); in uv_pipe_bind2()
807 handle->pipe.serv.accept_reqs = NULL; in uv_pipe_bind2()
808 handle->name = NULL; in uv_pipe_bind2()
816 uv_pipe_t* handle; in pipe_connect_thread_proc() local
823 handle = (uv_pipe_t*) req->handle; in pipe_connect_thread_proc()
824 assert(handle); in pipe_connect_thread_proc()
825 loop = handle->loop; in pipe_connect_thread_proc()
857 uv_pipe_t* handle, in uv_pipe_connect() argument
863 err = uv_pipe_connect2(req, handle, name, strlen(name), 0, cb); in uv_pipe_connect()
866 loop = handle->loop; in uv_pipe_connect()
870 handle->reqs_pending++; in uv_pipe_connect()
871 REGISTER_HANDLE_REQ(loop, handle); in uv_pipe_connect()
877 uv_pipe_t* handle, in uv_pipe_connect2() argument
889 loop = handle->loop; in uv_pipe_connect2()
891 req->handle = (uv_stream_t*) handle; in uv_pipe_connect2()
921 if (handle->flags & UV_HANDLE_PIPESERVER) { in uv_pipe_connect2()
925 if (handle->flags & UV_HANDLE_CONNECTION) { in uv_pipe_connect2()
929 uv__pipe_connection_init(handle); in uv_pipe_connect2()
932 err = uv__convert_utf8_to_utf16(name_copy, &handle->name); in uv_pipe_connect2()
941 pipeHandle = open_named_pipe(handle->name, &duplex_flags); in uv_pipe_connect2()
944 nameSize = (wcslen(handle->name) + 1) * sizeof(WCHAR); in uv_pipe_connect2()
950 memcpy(req->u.connect.name, handle->name, nameSize); in uv_pipe_connect2()
962 REGISTER_HANDLE_REQ(loop, handle); in uv_pipe_connect2()
963 handle->reqs_pending++; in uv_pipe_connect2()
976 handle->reqs_pending++; in uv_pipe_connect2()
977 REGISTER_HANDLE_REQ(loop, handle); in uv_pipe_connect2()
983 if (handle->name) { in uv_pipe_connect2()
984 uv__free(handle->name); in uv_pipe_connect2()
985 handle->name = NULL; in uv_pipe_connect2()
994 handle->reqs_pending++; in uv_pipe_connect2()
995 REGISTER_HANDLE_REQ(loop, handle); in uv_pipe_connect2()
1000 void uv__pipe_interrupt_read(uv_pipe_t* handle) { in uv__pipe_interrupt_read() argument
1003 if (!(handle->flags & UV_HANDLE_READ_PENDING)) in uv__pipe_interrupt_read()
1005 if (handle->flags & UV_HANDLE_CANCELLATION_PENDING) in uv__pipe_interrupt_read()
1007 if (handle->handle == INVALID_HANDLE_VALUE) in uv__pipe_interrupt_read()
1010 if (!(handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE)) { in uv__pipe_interrupt_read()
1012 r = CancelIoEx(handle->handle, &handle->read_req.u.io.overlapped); in uv__pipe_interrupt_read()
1018 volatile HANDLE* thread_ptr = &handle->pipe.conn.readfile_thread_handle; in uv__pipe_interrupt_read()
1020 EnterCriticalSection(&handle->pipe.conn.readfile_thread_lock); in uv__pipe_interrupt_read()
1039 LeaveCriticalSection(&handle->pipe.conn.readfile_thread_lock); in uv__pipe_interrupt_read()
1043 handle->flags |= UV_HANDLE_CANCELLATION_PENDING; in uv__pipe_interrupt_read()
1047 void uv__pipe_read_stop(uv_pipe_t* handle) { in uv__pipe_read_stop() argument
1048 handle->flags &= ~UV_HANDLE_READING; in uv__pipe_read_stop()
1049 DECREASE_ACTIVE_COUNT(handle->loop, handle); in uv__pipe_read_stop()
1050 uv__pipe_interrupt_read(handle); in uv__pipe_read_stop()
1056 void uv__pipe_close(uv_loop_t* loop, uv_pipe_t* handle) { in uv__pipe_close() argument
1060 if (handle->flags & UV_HANDLE_READING) { in uv__pipe_close()
1061 handle->flags &= ~UV_HANDLE_READING; in uv__pipe_close()
1062 DECREASE_ACTIVE_COUNT(loop, handle); in uv__pipe_close()
1065 if (handle->flags & UV_HANDLE_LISTENING) { in uv__pipe_close()
1066 handle->flags &= ~UV_HANDLE_LISTENING; in uv__pipe_close()
1067 DECREASE_ACTIVE_COUNT(loop, handle); in uv__pipe_close()
1070 handle->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE); in uv__pipe_close()
1072 uv__handle_closing(handle); in uv__pipe_close()
1074 uv__pipe_interrupt_read(handle); in uv__pipe_close()
1076 if (handle->name) { in uv__pipe_close()
1077 uv__free(handle->name); in uv__pipe_close()
1078 handle->name = NULL; in uv__pipe_close()
1081 if (handle->flags & UV_HANDLE_PIPESERVER) { in uv__pipe_close()
1082 for (i = 0; i < handle->pipe.serv.pending_instances; i++) { in uv__pipe_close()
1083 pipeHandle = handle->pipe.serv.accept_reqs[i].pipeHandle; in uv__pipe_close()
1086 handle->pipe.serv.accept_reqs[i].pipeHandle = INVALID_HANDLE_VALUE; in uv__pipe_close()
1089 handle->handle = INVALID_HANDLE_VALUE; in uv__pipe_close()
1092 if (handle->flags & UV_HANDLE_CONNECTION) { in uv__pipe_close()
1093 eof_timer_destroy(handle); in uv__pipe_close()
1096 if ((handle->flags & UV_HANDLE_CONNECTION) in uv__pipe_close()
1097 && handle->handle != INVALID_HANDLE_VALUE) { in uv__pipe_close()
1099 close_pipe(handle); in uv__pipe_close()
1102 if (handle->reqs_pending == 0) in uv__pipe_close()
1103 uv__want_endgame(loop, (uv_handle_t*) handle); in uv__pipe_close()
1107 static void uv__pipe_queue_accept(uv_loop_t* loop, uv_pipe_t* handle, in uv__pipe_queue_accept() argument
1109 assert(handle->flags & UV_HANDLE_LISTENING); in uv__pipe_queue_accept()
1111 if (!firstInstance && !pipe_alloc_accept(loop, handle, req, FALSE)) { in uv__pipe_queue_accept()
1114 handle->reqs_pending++; in uv__pipe_queue_accept()
1134 handle->reqs_pending++; in uv__pipe_queue_accept()
1139 handle->reqs_pending++; in uv__pipe_queue_accept()
1184 pipe_client->handle = req->pipeHandle; in uv__pipe_accept()
1192 server->handle = INVALID_HANDLE_VALUE; in uv__pipe_accept()
1203 int uv__pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { in uv__pipe_listen() argument
1204 uv_loop_t* loop = handle->loop; in uv__pipe_listen()
1207 if (handle->flags & UV_HANDLE_LISTENING) { in uv__pipe_listen()
1208 handle->stream.serv.connection_cb = cb; in uv__pipe_listen()
1211 if (!(handle->flags & UV_HANDLE_BOUND)) { in uv__pipe_listen()
1215 if (handle->flags & UV_HANDLE_READING) { in uv__pipe_listen()
1219 if (!(handle->flags & UV_HANDLE_PIPESERVER)) { in uv__pipe_listen()
1223 if (handle->ipc) { in uv__pipe_listen()
1227 handle->flags |= UV_HANDLE_LISTENING; in uv__pipe_listen()
1228 INCREASE_ACTIVE_COUNT(loop, handle); in uv__pipe_listen()
1229 handle->stream.serv.connection_cb = cb; in uv__pipe_listen()
1232 assert(handle->pipe.serv.accept_reqs[0].pipeHandle != INVALID_HANDLE_VALUE); in uv__pipe_listen()
1234 for (i = 0; i < handle->pipe.serv.pending_instances; i++) { in uv__pipe_listen()
1235 uv__pipe_queue_accept(loop, handle, &handle->pipe.serv.accept_reqs[i], i == 0); in uv__pipe_listen()
1244 uv_pipe_t* handle = (uv_pipe_t*) req->data; in uv_pipe_zero_readfile_thread_proc() local
1245 uv_loop_t* loop = handle->loop; in uv_pipe_zero_readfile_thread_proc()
1246 volatile HANDLE* thread_ptr = &handle->pipe.conn.readfile_thread_handle; in uv_pipe_zero_readfile_thread_proc()
1247 CRITICAL_SECTION* lock = &handle->pipe.conn.readfile_thread_lock; in uv_pipe_zero_readfile_thread_proc()
1253 assert(handle->type == UV_NAMED_PIPE); in uv_pipe_zero_readfile_thread_proc()
1286 if (!ReadFile(handle->handle, &uv_zero_, 0, &bytes, NULL)) in uv_pipe_zero_readfile_thread_proc()
1319 uv_pipe_t* handle = (uv_pipe_t*) req->handle; in uv_pipe_writefile_thread_proc() local
1320 uv_loop_t* loop = handle->loop; in uv_pipe_writefile_thread_proc()
1324 assert(handle->type == UV_NAMED_PIPE); in uv_pipe_writefile_thread_proc()
1326 result = WriteFile(handle->handle, in uv_pipe_writefile_thread_proc()
1343 uv_tcp_t* handle; in post_completion_read_wait() local
1347 handle = (uv_tcp_t*)req->data; in post_completion_read_wait()
1348 assert(handle != NULL); in post_completion_read_wait()
1351 if (!PostQueuedCompletionStatus(handle->loop->iocp, in post_completion_read_wait()
1362 uv_tcp_t* handle; in post_completion_write_wait() local
1366 handle = (uv_tcp_t*)req->handle; in post_completion_write_wait()
1367 assert(handle != NULL); in post_completion_write_wait()
1370 if (!PostQueuedCompletionStatus(handle->loop->iocp, in post_completion_write_wait()
1379 static void uv__pipe_queue_read(uv_loop_t* loop, uv_pipe_t* handle) { in uv__pipe_queue_read() argument
1383 assert(handle->flags & UV_HANDLE_READING); in uv__pipe_queue_read()
1384 assert(!(handle->flags & UV_HANDLE_READ_PENDING)); in uv__pipe_queue_read()
1386 assert(handle->handle != INVALID_HANDLE_VALUE); in uv__pipe_queue_read()
1388 req = &handle->read_req; in uv__pipe_queue_read()
1390 if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) { in uv__pipe_queue_read()
1391 handle->pipe.conn.readfile_thread_handle = NULL; /* Reset cancellation. */ in uv__pipe_queue_read()
1401 if (handle->flags & UV_HANDLE_EMULATE_IOCP) { in uv__pipe_queue_read()
1407 result = ReadFile(handle->handle, in uv__pipe_queue_read()
1419 if (handle->flags & UV_HANDLE_EMULATE_IOCP) { in uv__pipe_queue_read()
1431 eof_timer_start(handle); in uv__pipe_queue_read()
1432 handle->flags |= UV_HANDLE_READ_PENDING; in uv__pipe_queue_read()
1433 handle->reqs_pending++; in uv__pipe_queue_read()
1438 handle->flags |= UV_HANDLE_READ_PENDING; in uv__pipe_queue_read()
1439 handle->reqs_pending++; in uv__pipe_queue_read()
1443 int uv__pipe_read_start(uv_pipe_t* handle, in uv__pipe_read_start() argument
1446 uv_loop_t* loop = handle->loop; in uv__pipe_read_start()
1448 handle->flags |= UV_HANDLE_READING; in uv__pipe_read_start()
1449 INCREASE_ACTIVE_COUNT(loop, handle); in uv__pipe_read_start()
1450 handle->read_cb = read_cb; in uv__pipe_read_start()
1451 handle->alloc_cb = alloc_cb; in uv__pipe_read_start()
1453 if (handle->read_req.event_handle == NULL) { in uv__pipe_read_start()
1454 handle->read_req.event_handle = CreateEvent(NULL, 0, 0, NULL); in uv__pipe_read_start()
1455 if (handle->read_req.event_handle == NULL) { in uv__pipe_read_start()
1462 if (!(handle->flags & UV_HANDLE_READ_PENDING)) { in uv__pipe_read_start()
1463 uv__pipe_queue_read(loop, handle); in uv__pipe_read_start()
1470 static void uv__insert_non_overlapped_write_req(uv_pipe_t* handle, in uv__insert_non_overlapped_write_req() argument
1473 if (handle->pipe.conn.non_overlapped_writes_tail) { in uv__insert_non_overlapped_write_req()
1475 handle->pipe.conn.non_overlapped_writes_tail->next_req; in uv__insert_non_overlapped_write_req()
1476 handle->pipe.conn.non_overlapped_writes_tail->next_req = (uv_req_t*)req; in uv__insert_non_overlapped_write_req()
1477 handle->pipe.conn.non_overlapped_writes_tail = req; in uv__insert_non_overlapped_write_req()
1480 handle->pipe.conn.non_overlapped_writes_tail = req; in uv__insert_non_overlapped_write_req()
1485 static uv_write_t* uv_remove_non_overlapped_write_req(uv_pipe_t* handle) { in uv_remove_non_overlapped_write_req() argument
1488 if (handle->pipe.conn.non_overlapped_writes_tail) { in uv_remove_non_overlapped_write_req()
1489 req = (uv_write_t*)handle->pipe.conn.non_overlapped_writes_tail->next_req; in uv_remove_non_overlapped_write_req()
1491 if (req == handle->pipe.conn.non_overlapped_writes_tail) { in uv_remove_non_overlapped_write_req()
1492 handle->pipe.conn.non_overlapped_writes_tail = NULL; in uv_remove_non_overlapped_write_req()
1494 handle->pipe.conn.non_overlapped_writes_tail->next_req = in uv_remove_non_overlapped_write_req()
1506 static void uv__queue_non_overlapped_write(uv_pipe_t* handle) { in uv__queue_non_overlapped_write() argument
1507 uv_write_t* req = uv_remove_non_overlapped_write_req(handle); in uv__queue_non_overlapped_write()
1580 uv_pipe_t* handle, in uv__pipe_write_data() argument
1589 assert(handle->handle != INVALID_HANDLE_VALUE); in uv__pipe_write_data()
1592 req->handle = (uv_stream_t*) handle; in uv__pipe_write_data()
1602 if (handle->flags & (UV_HANDLE_EMULATE_IOCP | UV_HANDLE_BLOCKING_WRITES)) { in uv__pipe_write_data()
1625 if ((handle->flags & in uv__pipe_write_data()
1630 WriteFile(handle->handle, write_buf.base, write_buf.len, &bytes, NULL); in uv__pipe_write_data()
1640 REGISTER_HANDLE_REQ(loop, handle); in uv__pipe_write_data()
1641 handle->reqs_pending++; in uv__pipe_write_data()
1642 handle->stream.conn.write_reqs_pending++; in uv__pipe_write_data()
1645 } else if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) { in uv__pipe_write_data()
1647 uv__insert_non_overlapped_write_req(handle, req); in uv__pipe_write_data()
1648 if (handle->stream.conn.write_reqs_pending == 0) { in uv__pipe_write_data()
1649 uv__queue_non_overlapped_write(handle); in uv__pipe_write_data()
1654 handle->write_queue_size += req->u.io.queued_bytes; in uv__pipe_write_data()
1655 } else if (handle->flags & UV_HANDLE_BLOCKING_WRITES) { in uv__pipe_write_data()
1657 result = WriteFile(handle->handle, in uv__pipe_write_data()
1676 handle->write_queue_size += req->u.io.queued_bytes; in uv__pipe_write_data()
1688 REGISTER_HANDLE_REQ(loop, handle); in uv__pipe_write_data()
1689 handle->reqs_pending++; in uv__pipe_write_data()
1690 handle->stream.conn.write_reqs_pending++; in uv__pipe_write_data()
1693 result = WriteFile(handle->handle, in uv__pipe_write_data()
1709 handle->write_queue_size += req->u.io.queued_bytes; in uv__pipe_write_data()
1712 if (handle->flags & UV_HANDLE_EMULATE_IOCP) { in uv__pipe_write_data()
1721 REGISTER_HANDLE_REQ(loop, handle); in uv__pipe_write_data()
1722 handle->reqs_pending++; in uv__pipe_write_data()
1723 handle->stream.conn.write_reqs_pending++; in uv__pipe_write_data()
1729 static DWORD uv__pipe_get_ipc_remote_pid(uv_pipe_t* handle) { in uv__pipe_get_ipc_remote_pid() argument
1730 DWORD* pid = &handle->pipe.conn.ipc_remote_pid; in uv__pipe_get_ipc_remote_pid()
1736 GetNamedPipeClientProcessId(handle->handle, pid); in uv__pipe_get_ipc_remote_pid()
1738 GetNamedPipeServerProcessId(handle->handle, pid); in uv__pipe_get_ipc_remote_pid()
1748 uv_pipe_t* handle, in uv__pipe_write_ipc() argument
1780 uv__pipe_get_ipc_remote_pid(handle), in uv__pipe_write_ipc()
1837 err = uv__pipe_write_data(loop, req, handle, bufs, buf_count, cb, 1); in uv__pipe_write_ipc()
1850 uv_pipe_t* handle, in uv__pipe_write() argument
1855 if (handle->ipc) { in uv__pipe_write()
1857 return uv__pipe_write_ipc(loop, req, handle, bufs, nbufs, send_handle, cb); in uv__pipe_write()
1861 return uv__pipe_write_data(loop, req, handle, bufs, nbufs, cb, 0); in uv__pipe_write()
1866 static void uv__pipe_read_eof(uv_loop_t* loop, uv_pipe_t* handle, in uv__pipe_read_eof() argument
1870 eof_timer_destroy(handle); in uv__pipe_read_eof()
1872 uv_read_stop((uv_stream_t*) handle); in uv__pipe_read_eof()
1874 handle->read_cb((uv_stream_t*) handle, UV_EOF, &buf); in uv__pipe_read_eof()
1878 static void uv__pipe_read_error(uv_loop_t* loop, uv_pipe_t* handle, int error, in uv__pipe_read_error() argument
1882 eof_timer_destroy(handle); in uv__pipe_read_error()
1884 uv_read_stop((uv_stream_t*) handle); in uv__pipe_read_error()
1886 handle->read_cb((uv_stream_t*)handle, uv_translate_sys_error(error), &buf); in uv__pipe_read_error()
1890 static void uv__pipe_read_error_or_eof(uv_loop_t* loop, uv_pipe_t* handle, in uv__pipe_read_error_or_eof() argument
1893 uv__pipe_read_eof(loop, handle, buf); in uv__pipe_read_error_or_eof()
1895 uv__pipe_read_error(loop, handle, error, buf); in uv__pipe_read_error_or_eof()
1901 uv_pipe_t* handle, in uv__pipe_queue_ipc_xfer_info() argument
1913 uv__queue_insert_tail(&handle->pipe.conn.ipc_xfer_queue, &item->member); in uv__pipe_queue_ipc_xfer_info()
1914 handle->pipe.conn.ipc_xfer_queue_length++; in uv__pipe_queue_ipc_xfer_info()
1921 static DWORD uv__pipe_read_exactly(uv_pipe_t* handle, void* buffer, DWORD count) { in uv__pipe_read_exactly() argument
1928 req = &handle->read_req; in uv__pipe_read_exactly()
1931 if (!ReadFile(handle->handle, in uv__pipe_read_exactly()
1938 if (!GetOverlappedResult(handle->handle, &req->u.io.overlapped, &bytes_read_now, TRUE)) in uv__pipe_read_exactly()
1951 uv_pipe_t* handle, in uv__pipe_read_data() argument
1962 handle->alloc_cb((uv_handle_t*) handle, *bytes_read, &buf); in uv__pipe_read_data()
1964 handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf); in uv__pipe_read_data()
1976 if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) { in uv__pipe_read_data()
1981 if (!PeekNamedPipe(handle->handle, NULL, 0, NULL, &bytes_available, NULL)) { in uv__pipe_read_data()
1987 if (max_bytes == 0 || ReadFile(handle->handle, buf.base, max_bytes, bytes_read, NULL)) in uv__pipe_read_data()
1997 req = &handle->read_req; in uv__pipe_read_data()
2000 if (ReadFile(handle->handle, buf.base, max_bytes, bytes_read, &req->u.io.overlapped)) { in uv__pipe_read_data()
2006 r = CancelIoEx(handle->handle, &req->u.io.overlapped); in uv__pipe_read_data()
2008 if (GetOverlappedResult(handle->handle, &req->u.io.overlapped, bytes_read, TRUE)) { in uv__pipe_read_data()
2021 handle->read_cb((uv_stream_t*) handle, *bytes_read, &buf); in uv__pipe_read_data()
2023 uv__pipe_read_error_or_eof(loop, handle, r, buf); in uv__pipe_read_data()
2029 static int uv__pipe_read_ipc(uv_loop_t* loop, uv_pipe_t* handle) { in uv__pipe_read_ipc() argument
2035 data_remaining = &handle->pipe.conn.ipc_data_frame.payload_remaining; in uv__pipe_read_ipc()
2040 more = uv__pipe_read_data(loop, handle, &bytes_read, bytes_read); in uv__pipe_read_ipc()
2052 handle, &frame_header, sizeof frame_header); in uv__pipe_read_ipc()
2090 err = uv__pipe_read_exactly(handle, &xfer_info, sizeof xfer_info); in uv__pipe_read_ipc()
2095 uv__pipe_queue_ipc_xfer_info(handle, xfer_type, &xfer_info); in uv__pipe_read_ipc()
2111 uv__pipe_read_error_or_eof(loop, handle, err, uv_null_buf_); in uv__pipe_read_ipc()
2117 uv_pipe_t* handle, in uv__process_pipe_read_req() argument
2122 assert(handle->type == UV_NAMED_PIPE); in uv__process_pipe_read_req()
2124 handle->flags &= ~(UV_HANDLE_READ_PENDING | UV_HANDLE_CANCELLATION_PENDING); in uv__process_pipe_read_req()
2125 DECREASE_PENDING_REQ_COUNT(handle); in uv__process_pipe_read_req()
2126 eof_timer_stop(handle); in uv__process_pipe_read_req()
2128 if (handle->read_req.wait_handle != INVALID_HANDLE_VALUE) { in uv__process_pipe_read_req()
2129 UnregisterWait(handle->read_req.wait_handle); in uv__process_pipe_read_req()
2130 handle->read_req.wait_handle = INVALID_HANDLE_VALUE; in uv__process_pipe_read_req()
2136 if (!(handle->flags & UV_HANDLE_READING)) in uv__process_pipe_read_req()
2147 uv__pipe_read_error_or_eof(loop, handle, err, uv_null_buf_); in uv__process_pipe_read_req()
2152 while (handle->flags & UV_HANDLE_READING) { in uv__process_pipe_read_req()
2155 if (handle->ipc) in uv__process_pipe_read_req()
2156 more = uv__pipe_read_ipc(loop, handle); in uv__process_pipe_read_req()
2158 more = uv__pipe_read_data(loop, handle, &bytes_requested, INT32_MAX); in uv__process_pipe_read_req()
2168 if ((handle->flags & UV_HANDLE_READING) && in uv__process_pipe_read_req()
2169 !(handle->flags & UV_HANDLE_READ_PENDING)) { in uv__process_pipe_read_req()
2170 uv__pipe_queue_read(loop, handle); in uv__process_pipe_read_req()
2175 void uv__process_pipe_write_req(uv_loop_t* loop, uv_pipe_t* handle, in uv__process_pipe_write_req() argument
2179 assert(handle->type == UV_NAMED_PIPE); in uv__process_pipe_write_req()
2181 assert(handle->write_queue_size >= req->u.io.queued_bytes); in uv__process_pipe_write_req()
2182 handle->write_queue_size -= req->u.io.queued_bytes; in uv__process_pipe_write_req()
2184 UNREGISTER_HANDLE_REQ(loop, handle); in uv__process_pipe_write_req()
2210 handle->stream.conn.write_reqs_pending--; in uv__process_pipe_write_req()
2212 if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE && in uv__process_pipe_write_req()
2213 handle->pipe.conn.non_overlapped_writes_tail) { in uv__process_pipe_write_req()
2214 assert(handle->stream.conn.write_reqs_pending > 0); in uv__process_pipe_write_req()
2215 uv__queue_non_overlapped_write(handle); in uv__process_pipe_write_req()
2218 if (handle->stream.conn.write_reqs_pending == 0 && in uv__process_pipe_write_req()
2219 uv__is_stream_shutting(handle)) in uv__process_pipe_write_req()
2220 uv__pipe_shutdown(loop, handle, handle->stream.conn.shutdown_req); in uv__process_pipe_write_req()
2222 DECREASE_PENDING_REQ_COUNT(handle); in uv__process_pipe_write_req()
2226 void uv__process_pipe_accept_req(uv_loop_t* loop, uv_pipe_t* handle, in uv__process_pipe_accept_req() argument
2230 assert(handle->type == UV_NAMED_PIPE); in uv__process_pipe_accept_req()
2232 if (handle->flags & UV_HANDLE_CLOSING) { in uv__process_pipe_accept_req()
2235 DECREASE_PENDING_REQ_COUNT(handle); in uv__process_pipe_accept_req()
2241 req->next_pending = handle->pipe.serv.pending_accepts; in uv__process_pipe_accept_req()
2242 handle->pipe.serv.pending_accepts = req; in uv__process_pipe_accept_req()
2244 if (handle->stream.serv.connection_cb) { in uv__process_pipe_accept_req()
2245 handle->stream.serv.connection_cb((uv_stream_t*)handle, 0); in uv__process_pipe_accept_req()
2252 if (!(handle->flags & UV_HANDLE_CLOSING)) { in uv__process_pipe_accept_req()
2253 uv__pipe_queue_accept(loop, handle, req, FALSE); in uv__process_pipe_accept_req()
2257 DECREASE_PENDING_REQ_COUNT(handle); in uv__process_pipe_accept_req()
2261 void uv__process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle, in uv__process_pipe_connect_req() argument
2267 assert(handle->type == UV_NAMED_PIPE); in uv__process_pipe_connect_req()
2269 UNREGISTER_HANDLE_REQ(loop, handle); in uv__process_pipe_connect_req()
2275 if (handle->flags & UV_HANDLE_CLOSING) in uv__process_pipe_connect_req()
2278 err = uv__set_pipe_handle(loop, handle, pipeHandle, -1, duplex_flags); in uv__process_pipe_connect_req()
2288 DECREASE_PENDING_REQ_COUNT(handle); in uv__process_pipe_connect_req()
2293 void uv__process_pipe_shutdown_req(uv_loop_t* loop, uv_pipe_t* handle, in uv__process_pipe_shutdown_req() argument
2297 assert(handle->type == UV_NAMED_PIPE); in uv__process_pipe_shutdown_req()
2300 handle->stream.conn.shutdown_req = NULL; in uv__process_pipe_shutdown_req()
2301 UNREGISTER_HANDLE_REQ(loop, handle); in uv__process_pipe_shutdown_req()
2303 if (handle->flags & UV_HANDLE_CLOSING) { in uv__process_pipe_shutdown_req()
2310 if (handle->flags & UV_HANDLE_READABLE) { in uv__process_pipe_shutdown_req()
2313 eof_timer_init(handle); in uv__process_pipe_shutdown_req()
2317 if (handle->flags & UV_HANDLE_READ_PENDING) { in uv__process_pipe_shutdown_req()
2318 eof_timer_start(handle); in uv__process_pipe_shutdown_req()
2324 close_pipe(handle); in uv__process_pipe_shutdown_req()
2332 DECREASE_PENDING_REQ_COUNT(handle); in uv__process_pipe_shutdown_req()
2414 static void eof_timer_close_cb(uv_handle_t* handle) { in eof_timer_close_cb() argument
2415 assert(handle->type == UV_TIMER); in eof_timer_close_cb()
2416 uv__free(handle); in eof_timer_close_cb()
2503 static int uv__pipe_getname(const uv_pipe_t* handle, char* buffer, size_t* size) { in uv__pipe_getname() argument
2516 if (handle->name != NULL) { in uv__pipe_getname()
2519 return uv__copy_utf16_to_utf8(handle->name, -1, buffer, size); in uv__pipe_getname()
2522 if (handle->handle == INVALID_HANDLE_VALUE) { in uv__pipe_getname()
2532 if (handle->flags & UV_HANDLE_CONNECTION && in uv__pipe_getname()
2533 handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) { in uv__pipe_getname()
2534 uv__pipe_interrupt_read((uv_pipe_t*) handle); /* cast away const warning */ in uv__pipe_getname()
2537 nt_status = pNtQueryInformationFile(handle->handle, in uv__pipe_getname()
2550 nt_status = pNtQueryInformationFile(handle->handle, in uv__pipe_getname()
2597 int uv_pipe_pending_count(uv_pipe_t* handle) { in uv_pipe_pending_count() argument
2598 if (!handle->ipc) in uv_pipe_pending_count()
2600 return handle->pipe.conn.ipc_xfer_queue_length; in uv_pipe_pending_count()
2604 int uv_pipe_getsockname(const uv_pipe_t* handle, char* buffer, size_t* size) { in uv_pipe_getsockname() argument
2605 if (handle->flags & UV_HANDLE_BOUND) in uv_pipe_getsockname()
2606 return uv__pipe_getname(handle, buffer, size); in uv_pipe_getsockname()
2608 if (handle->flags & UV_HANDLE_CONNECTION || in uv_pipe_getsockname()
2609 handle->handle != INVALID_HANDLE_VALUE) { in uv_pipe_getsockname()
2618 int uv_pipe_getpeername(const uv_pipe_t* handle, char* buffer, size_t* size) { in uv_pipe_getpeername() argument
2620 if (handle->flags & UV_HANDLE_BOUND) in uv_pipe_getpeername()
2623 if (handle->handle != INVALID_HANDLE_VALUE) in uv_pipe_getpeername()
2624 return uv__pipe_getname(handle, buffer, size); in uv_pipe_getpeername()
2626 if (handle->flags & UV_HANDLE_CONNECTION) { in uv_pipe_getpeername()
2627 if (handle->name != NULL) in uv_pipe_getpeername()
2628 return uv__pipe_getname(handle, buffer, size); in uv_pipe_getpeername()
2635 uv_handle_type uv_pipe_pending_type(uv_pipe_t* handle) { in uv_pipe_pending_type() argument
2636 if (!handle->ipc) in uv_pipe_pending_type()
2638 if (handle->pipe.conn.ipc_xfer_queue_length == 0) in uv_pipe_pending_type()
2644 int uv_pipe_chmod(uv_pipe_t* handle, int mode) { in uv_pipe_chmod() argument
2652 if (handle == NULL || handle->handle == INVALID_HANDLE_VALUE) in uv_pipe_chmod()
2669 if (GetSecurityInfo(handle->handle, in uv_pipe_chmod()
2698 if (SetSecurityInfo(handle->handle, in uv_pipe_chmod()