handle.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include <assert.h>
23 #include <io.h>
24 #include <stdlib.h>
25 
26 #include "uv.h"
27 #include "internal.h"
28 #include "handle-inl.h"
29 
30 
32  HANDLE handle;
33  DWORD mode;
34 
35  if (file < 0) {
36  return UV_UNKNOWN_HANDLE;
37  }
38 
40 
41  switch (GetFileType(handle)) {
42  case FILE_TYPE_CHAR:
43  if (GetConsoleMode(handle, &mode)) {
44  return UV_TTY;
45  } else {
46  return UV_FILE;
47  }
48 
49  case FILE_TYPE_PIPE:
50  return UV_NAMED_PIPE;
51 
52  case FILE_TYPE_DISK:
53  return UV_FILE;
54 
55  default:
56  return UV_UNKNOWN_HANDLE;
57  }
58 }
59 
60 
62  return (handle->flags & UV_HANDLE_ACTIVE) &&
63  !(handle->flags & UV_HANDLE_CLOSING);
64 }
65 
66 
68  uv_loop_t* loop = handle->loop;
69 
70  if (handle->flags & UV_HANDLE_CLOSING) {
71  assert(0);
72  return;
73  }
74 
75  handle->close_cb = cb;
76 
77  /* Handle-specific close actions */
78  switch (handle->type) {
79  case UV_TCP:
81  return;
82 
83  case UV_NAMED_PIPE:
85  return;
86 
87  case UV_TTY:
89  return;
90 
91  case UV_UDP:
93  return;
94 
95  case UV_POLL:
97  return;
98 
99  case UV_TIMER:
103  return;
104 
105  case UV_PREPARE:
109  return;
110 
111  case UV_CHECK:
115  return;
116 
117  case UV_IDLE:
121  return;
122 
123  case UV_ASYNC:
125  return;
126 
127  case UV_SIGNAL:
129  return;
130 
131  case UV_PROCESS:
133  return;
134 
135  case UV_FS_EVENT:
137  return;
138 
139  case UV_FS_POLL:
142  return;
143 
144  default:
145  /* Not supported */
146  abort();
147  }
148 }
149 
150 
152  return !!(handle->flags & (UV_HANDLE_CLOSING | UV_HANDLE_CLOSED));
153 }
154 
155 
157  return uv__get_osfhandle(fd);
158 }
159 
161  return _open_osfhandle((intptr_t) os_fd, 0);
162 }
async_greeter_server_with_graceful_shutdown.loop
loop
Definition: async_greeter_server_with_graceful_shutdown.py:59
uv_fs_event_s
Definition: uv.h:1533
uv_signal_close
void uv_signal_close(uv_loop_t *loop, uv_signal_t *handle)
Definition: win/signal.c:257
UV_HANDLE_CLOSED
@ UV_HANDLE_CLOSED
Definition: uv-common.h:67
uv_process_s
Definition: uv.h:1037
uv_poll_close
int uv_poll_close(uv_loop_t *loop, uv_poll_t *handle)
Definition: win/poll.c:626
uv_handle_type
uv_handle_type
Definition: uv.h:189
uv_get_osfhandle
uv_os_fd_t uv_get_osfhandle(int fd)
Definition: handle.c:156
uv_prepare_s
Definition: uv.h:804
uv_process_close
void uv_process_close(uv_loop_t *loop, uv_process_t *handle)
Definition: win/process.c:903
uv_tty_s
Definition: uv.h:704
uv_is_closing
int uv_is_closing(const uv_handle_t *handle)
Definition: handle.c:151
uv_prepare_stop
UV_EXTERN int uv_prepare_stop(uv_prepare_t *prepare)
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
uv_guess_handle
uv_handle_type uv_guess_handle(uv_file file)
Definition: handle.c:31
uv_timer_stop
UV_EXTERN int uv_timer_stop(uv_timer_t *handle)
Definition: timer.c:97
uv_want_endgame
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
Definition: handle-inl.h:88
uv_idle_stop
UV_EXTERN int uv_idle_stop(uv_idle_t *idle)
uv_udp_close
void uv_udp_close(uv_loop_t *loop, uv_udp_t *handle)
Definition: win/udp.c:182
uv__handle_closing
#define uv__handle_closing(handle)
Definition: handle-inl.h:63
uv_pipe_close
void uv_pipe_close(uv_loop_t *loop, uv_pipe_t *handle)
Definition: win/pipe.c:820
uv_async_s
Definition: uv.h:834
uv_check_s
Definition: uv.h:814
uv_open_osfhandle
int uv_open_osfhandle(uv_os_fd_t os_fd)
Definition: handle.c:160
UV_FILE
@ UV_FILE
Definition: uv.h:194
uv_udp_s
Definition: uv.h:629
uv_async_close
void uv_async_close(uv_loop_t *loop, uv_async_t *handle)
Definition: win/async.c:57
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
uv_check_stop
UV_EXTERN int uv_check_stop(uv_check_t *check)
uv_close
void uv_close(uv_handle_t *handle, uv_close_cb cb)
Definition: handle.c:67
uv_file
int uv_file
Definition: unix.h:126
uv_timer_s
Definition: uv.h:850
uv_tcp_s
Definition: uv.h:544
uv.h
UV_HANDLE_CLOSING
@ UV_HANDLE_CLOSING
Definition: uv-common.h:66
uv_signal_s
Definition: uv.h:1561
uv_is_active
int uv_is_active(const uv_handle_t *handle)
Definition: handle.c:61
uv_poll_s
Definition: uv.h:783
uv_os_fd_t
int uv_os_fd_t
Definition: unix.h:128
uv_fs_poll_s
Definition: uv.h:1544
uv__get_osfhandle
static INLINE HANDLE uv__get_osfhandle(int fd)
Definition: handle-inl.h:166
uv_idle_s
Definition: uv.h:824
uv_tcp_close
void uv_tcp_close(uv_loop_t *loop, uv_tcp_t *tcp)
Definition: win/tcp.c:1374
uv__fs_poll_close
void uv__fs_poll_close(uv_fs_poll_t *handle)
Definition: fs-poll.c:164
uv_pipe_s
Definition: uv.h:757
handle
static csh handle
Definition: test_arm_regression.c:16
uv_handle_s
Definition: uv.h:441
uv_loop_s
Definition: uv.h:1767
uv_close_cb
void(* uv_close_cb)(uv_handle_t *handle)
Definition: uv.h:316
internal.h
uv_tty_close
void uv_tty_close(uv_tty_t *handle)
Definition: win/tty.c:2249
uv_fs_event_close
void uv_fs_event_close(uv_loop_t *loop, uv_fs_event_t *handle)
Definition: fs-event.c:566
handle-inl.h
cb
OPENSSL_EXPORT pem_password_cb * cb
Definition: pem.h:351
UV_HANDLE_ACTIVE
@ UV_HANDLE_ACTIVE
Definition: uv-common.h:68
UV_UNKNOWN_HANDLE
@ UV_UNKNOWN_HANDLE
Definition: uv.h:190


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:10