req-inl.h
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 #ifndef UV_WIN_REQ_INL_H_
23 #define UV_WIN_REQ_INL_H_
24 
25 #include <assert.h>
26 
27 #include "uv.h"
28 #include "internal.h"
29 
30 
31 #define SET_REQ_STATUS(req, status) \
32  (req)->u.io.overlapped.Internal = (ULONG_PTR) (status)
33 
34 #define SET_REQ_ERROR(req, error) \
35  SET_REQ_STATUS((req), NTSTATUS_FROM_WIN32((error)))
36 
37 /* Note: used open-coded in UV_REQ_INIT() because of a circular dependency
38  * between src/uv-common.h and src/win/internal.h.
39  */
40 #define SET_REQ_SUCCESS(req) \
41  SET_REQ_STATUS((req), STATUS_SUCCESS)
42 
43 #define GET_REQ_STATUS(req) \
44  ((NTSTATUS) (req)->u.io.overlapped.Internal)
45 
46 #define REQ_SUCCESS(req) \
47  (NT_SUCCESS(GET_REQ_STATUS((req))))
48 
49 #define GET_REQ_ERROR(req) \
50  (pRtlNtStatusToDosError(GET_REQ_STATUS((req))))
51 
52 #define GET_REQ_SOCK_ERROR(req) \
53  (uv_ntstatus_to_winsock_error(GET_REQ_STATUS((req))))
54 
55 
56 #define REGISTER_HANDLE_REQ(loop, handle, req) \
57  do { \
58  INCREASE_ACTIVE_COUNT((loop), (handle)); \
59  uv__req_register((loop), (req)); \
60  } while (0)
61 
62 #define UNREGISTER_HANDLE_REQ(loop, handle, req) \
63  do { \
64  DECREASE_ACTIVE_COUNT((loop), (handle)); \
65  uv__req_unregister((loop), (req)); \
66  } while (0)
67 
68 
69 #define UV_SUCCEEDED_WITHOUT_IOCP(result) \
70  ((result) && (handle->flags & UV_HANDLE_SYNC_BYPASS_IOCP))
71 
72 #define UV_SUCCEEDED_WITH_IOCP(result) \
73  ((result) || (GetLastError() == ERROR_IO_PENDING))
74 
75 
76 #define POST_COMPLETION_FOR_REQ(loop, req) \
77  if (!PostQueuedCompletionStatus((loop)->iocp, \
78  0, \
79  0, \
80  &((req)->u.io.overlapped))) { \
81  uv_fatal_error(GetLastError(), "PostQueuedCompletionStatus"); \
82  }
83 
84 
85 INLINE static uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped) {
86  return CONTAINING_RECORD(overlapped, uv_req_t, u.io.overlapped);
87 }
88 
89 
91  req->next_req = NULL;
92  if (loop->pending_reqs_tail) {
93 #ifdef _DEBUG
94  /* Ensure the request is not already in the queue, or the queue
95  * will get corrupted.
96  */
97  uv_req_t* current = loop->pending_reqs_tail;
98  do {
99  assert(req != current);
100  current = current->next_req;
101  } while(current != loop->pending_reqs_tail);
102 #endif
103 
104  req->next_req = loop->pending_reqs_tail->next_req;
105  loop->pending_reqs_tail->next_req = req;
106  loop->pending_reqs_tail = req;
107  } else {
108  req->next_req = req;
109  loop->pending_reqs_tail = req;
110  }
111 }
112 
113 
114 #define DELEGATE_STREAM_REQ(loop, req, method, handle_at) \
115  do { \
116  switch (((uv_handle_t*) (req)->handle_at)->type) { \
117  case UV_TCP: \
118  uv_process_tcp_##method##_req(loop, \
119  (uv_tcp_t*) ((req)->handle_at), \
120  req); \
121  break; \
122  \
123  case UV_NAMED_PIPE: \
124  uv_process_pipe_##method##_req(loop, \
125  (uv_pipe_t*) ((req)->handle_at), \
126  req); \
127  break; \
128  \
129  case UV_TTY: \
130  uv_process_tty_##method##_req(loop, \
131  (uv_tty_t*) ((req)->handle_at), \
132  req); \
133  break; \
134  \
135  default: \
136  assert(0); \
137  } \
138  } while (0)
139 
140 
142  uv_req_t* req;
143  uv_req_t* first;
144  uv_req_t* next;
145 
146  if (loop->pending_reqs_tail == NULL)
147  return 0;
148 
149  first = loop->pending_reqs_tail->next_req;
150  next = first;
151  loop->pending_reqs_tail = NULL;
152 
153  while (next != NULL) {
154  req = next;
155  next = req->next_req != first ? req->next_req : NULL;
156 
157  switch (req->type) {
158  case UV_READ:
160  break;
161 
162  case UV_WRITE:
164  break;
165 
166  case UV_ACCEPT:
167  DELEGATE_STREAM_REQ(loop, req, accept, data);
168  break;
169 
170  case UV_CONNECT:
172  break;
173 
174  case UV_SHUTDOWN:
175  /* Tcp shutdown requests don't come here. */
176  assert(((uv_shutdown_t*) req)->handle->type == UV_NAMED_PIPE);
178  loop,
180  (uv_shutdown_t*) req);
181  break;
182 
183  case UV_UDP_RECV:
185  break;
186 
187  case UV_UDP_SEND:
189  ((uv_udp_send_t*) req)->handle,
190  (uv_udp_send_t*) req);
191  break;
192 
193  case UV_WAKEUP:
195  break;
196 
197  case UV_SIGNAL_REQ:
199  break;
200 
201  case UV_POLL_REQ:
203  break;
204 
205  case UV_PROCESS_EXIT:
207  break;
208 
209  case UV_FS_EVENT_REQ:
211  break;
212 
213  default:
214  assert(0);
215  }
216  }
217 
218  return 1;
219 }
220 
221 #endif /* UV_WIN_REQ_INL_H_ */
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_process_s
Definition: uv.h:1037
uv_connect_s
Definition: uv.h:580
write
#define write
Definition: test-fs.c:47
uv_shutdown_s
Definition: uv.h:417
uv_process_proc_exit
void uv_process_proc_exit(uv_loop_t *loop, uv_process_t *handle)
Definition: win/process.c:865
u
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:351
uv_process_fs_event_req
void uv_process_fs_event_req(uv_loop_t *loop, uv_req_t *req, uv_fs_event_t *handle)
Definition: fs-event.c:407
uv_process_async_wakeup_req
void uv_process_async_wakeup_req(uv_loop_t *loop, uv_async_t *handle, uv_req_t *req)
Definition: win/async.c:86
uv_async_s
Definition: uv.h:834
req
static uv_connect_t req
Definition: test-connection-fail.c:30
uv_process_poll_req
void uv_process_poll_req(uv_loop_t *loop, uv_poll_t *handle, uv_req_t *req)
Definition: win/poll.c:617
uv_udp_s
Definition: uv.h:629
uv_process_reqs
static INLINE int uv_process_reqs(uv_loop_t *loop)
Definition: req-inl.h:141
INLINE
#define INLINE
Definition: third_party/libuv/src/win/internal.h:36
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
uv_udp_send_s
Definition: uv.h:645
uv_insert_pending_req
static INLINE void uv_insert_pending_req(uv_loop_t *loop, uv_req_t *req)
Definition: req-inl.h:90
uv_process_pipe_shutdown_req
void uv_process_pipe_shutdown_req(uv_loop_t *loop, uv_pipe_t *handle, uv_shutdown_t *req)
Definition: win/pipe.c:1969
uv.h
uv_signal_s
Definition: uv.h:1561
read
int read(izstream &zs, T *x, Items items)
Definition: bloaty/third_party/zlib/contrib/iostream2/zstream.h:115
uv_poll_s
Definition: uv.h:783
DELEGATE_STREAM_REQ
#define DELEGATE_STREAM_REQ(loop, req, method, handle_at)
Definition: req-inl.h:114
uv_overlapped_to_req
static INLINE uv_req_t * uv_overlapped_to_req(OVERLAPPED *overlapped)
Definition: req-inl.h:85
next
AllocList * next[kMaxLevel]
Definition: abseil-cpp/absl/base/internal/low_level_alloc.cc:100
first
StrT first
Definition: cxa_demangle.cpp:4884
uv_process_udp_recv_req
void uv_process_udp_recv_req(uv_loop_t *loop, uv_udp_t *handle, uv_req_t *req)
Definition: win/udp.c:460
uv_pipe_s
Definition: uv.h:757
uv_write_s
Definition: uv.h:522
handle
static csh handle
Definition: test_arm_regression.c:16
uv_process_signal_req
void uv_process_signal_req(uv_loop_t *loop, uv_signal_t *handle, uv_req_t *req)
Definition: win/signal.c:229
uv_loop_s
Definition: uv.h:1767
internal.h
uv_req_s
Definition: uv.h:404
uv_process_udp_send_req
void uv_process_udp_send_req(uv_loop_t *loop, uv_udp_t *handle, uv_udp_send_t *req)
Definition: win/udp.c:571


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