win/stream.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 
24 #include "uv.h"
25 #include "internal.h"
26 #include "handle-inl.h"
27 #include "req-inl.h"
28 
29 
31  int err;
32 
33  err = ERROR_INVALID_PARAMETER;
34  switch (stream->type) {
35  case UV_TCP:
36  err = uv_tcp_listen((uv_tcp_t*)stream, backlog, cb);
37  break;
38  case UV_NAMED_PIPE:
39  err = uv_pipe_listen((uv_pipe_t*)stream, backlog, cb);
40  break;
41  default:
42  assert(0);
43  }
44 
46 }
47 
48 
50  int err;
51 
52  err = ERROR_INVALID_PARAMETER;
53  switch (server->type) {
54  case UV_TCP:
56  break;
57  case UV_NAMED_PIPE:
59  break;
60  default:
61  assert(0);
62  }
63 
65 }
66 
67 
70  int err;
71 
72  if (handle->flags & UV_HANDLE_READING) {
73  return UV_EALREADY;
74  }
75 
76  if (!(handle->flags & UV_HANDLE_READABLE)) {
77  return UV_ENOTCONN;
78  }
79 
80  err = ERROR_INVALID_PARAMETER;
81  switch (handle->type) {
82  case UV_TCP:
84  break;
85  case UV_NAMED_PIPE:
87  break;
88  case UV_TTY:
90  break;
91  default:
92  assert(0);
93  }
94 
96 }
97 
98 
100  int err;
101 
102  if (!(handle->flags & UV_HANDLE_READING))
103  return 0;
104 
105  err = 0;
106  if (handle->type == UV_TTY) {
108  } else if (handle->type == UV_NAMED_PIPE) {
110  } else {
111  handle->flags &= ~UV_HANDLE_READING;
113  }
114 
115  return uv_translate_sys_error(err);
116 }
117 
118 
121  const uv_buf_t bufs[],
122  unsigned int nbufs,
123  uv_write_cb cb) {
124  uv_loop_t* loop = handle->loop;
125  int err;
126 
127  if (!(handle->flags & UV_HANDLE_WRITABLE)) {
128  return UV_EPIPE;
129  }
130 
131  err = ERROR_INVALID_PARAMETER;
132  switch (handle->type) {
133  case UV_TCP:
134  err = uv_tcp_write(loop, req, (uv_tcp_t*) handle, bufs, nbufs, cb);
135  break;
136  case UV_NAMED_PIPE:
138  loop, req, (uv_pipe_t*) handle, bufs, nbufs, NULL, cb);
139  break;
140  case UV_TTY:
141  err = uv_tty_write(loop, req, (uv_tty_t*) handle, bufs, nbufs, cb);
142  break;
143  default:
144  assert(0);
145  }
146 
147  return uv_translate_sys_error(err);
148 }
149 
150 
153  const uv_buf_t bufs[],
154  unsigned int nbufs,
155  uv_stream_t* send_handle,
156  uv_write_cb cb) {
157  uv_loop_t* loop = handle->loop;
158  int err;
159 
160  if (send_handle == NULL) {
161  return uv_write(req, handle, bufs, nbufs, cb);
162  }
163 
164  if (handle->type != UV_NAMED_PIPE || !((uv_pipe_t*) handle)->ipc) {
165  return UV_EINVAL;
166  } else if (!(handle->flags & UV_HANDLE_WRITABLE)) {
167  return UV_EPIPE;
168  }
169 
171  loop, req, (uv_pipe_t*) handle, bufs, nbufs, send_handle, cb);
172  return uv_translate_sys_error(err);
173 }
174 
175 
177  const uv_buf_t bufs[],
178  unsigned int nbufs) {
179  if (stream->flags & UV_HANDLE_CLOSING)
180  return UV_EBADF;
181  if (!(stream->flags & UV_HANDLE_WRITABLE))
182  return UV_EPIPE;
183 
184  switch (stream->type) {
185  case UV_TCP:
186  return uv__tcp_try_write((uv_tcp_t*) stream, bufs, nbufs);
187  case UV_TTY:
188  return uv__tty_try_write((uv_tty_t*) stream, bufs, nbufs);
189  case UV_NAMED_PIPE:
190  return UV_EAGAIN;
191  default:
192  assert(0);
193  return UV_ENOSYS;
194  }
195 }
196 
197 
199  uv_loop_t* loop = handle->loop;
200 
201  if (!(handle->flags & UV_HANDLE_WRITABLE) ||
202  handle->flags & UV_HANDLE_SHUTTING ||
204  return UV_ENOTCONN;
205  }
206 
207  UV_REQ_INIT(req, UV_SHUTDOWN);
208  req->handle = handle;
209  req->cb = cb;
210 
211  handle->flags &= ~UV_HANDLE_WRITABLE;
212  handle->flags |= UV_HANDLE_SHUTTING;
213  handle->stream.conn.shutdown_req = req;
214  handle->reqs_pending++;
216 
218 
219  return 0;
220 }
221 
222 
224  return !!(handle->flags & UV_HANDLE_READABLE);
225 }
226 
227 
229  return !!(handle->flags & UV_HANDLE_WRITABLE);
230 }
231 
232 
234  if (handle->type != UV_NAMED_PIPE)
235  return UV_EINVAL;
236 
237  if (blocking != 0)
239  else
241 
242  return 0;
243 }
UV_HANDLE_WRITABLE
@ UV_HANDLE_WRITABLE
Definition: uv-common.h:85
uv__is_closing
#define uv__is_closing(h)
Definition: uv-common.h:238
async_greeter_server_with_graceful_shutdown.loop
loop
Definition: async_greeter_server_with_graceful_shutdown.py:59
uv_shutdown
int uv_shutdown(uv_shutdown_t *req, uv_stream_t *handle, uv_shutdown_cb cb)
Definition: win/stream.c:198
read_cb
static void read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
Definition: benchmark-pound.c:138
uv_is_writable
int uv_is_writable(const uv_stream_t *handle)
Definition: win/stream.c:228
uv__pipe_write
int uv__pipe_write(uv_loop_t *loop, uv_write_t *req, uv_pipe_t *handle, const uv_buf_t bufs[], size_t nbufs, uv_stream_t *send_handle, uv_write_cb cb)
Definition: win/pipe.c:1580
uv__tty_try_write
int uv__tty_try_write(uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
Definition: win/tty.c:2212
uv_shutdown_s
Definition: uv.h:417
client
Definition: examples/python/async_streaming/client.py:1
uv_read_start
int uv_read_start(uv_stream_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: win/stream.c:68
uv_tty_s
Definition: uv.h:704
uv_write2
int uv_write2(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_stream_t *send_handle, uv_write_cb cb)
Definition: win/stream.c:151
uv_connect_s::handle
uv_stream_t * handle
Definition: uv.h:583
error_ref_leak.err
err
Definition: error_ref_leak.py:35
uv_listen
int uv_listen(uv_stream_t *stream, int backlog, uv_connection_cb cb)
Definition: win/stream.c:30
uv_read_cb
void(* uv_read_cb)(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
Definition: uv.h:309
alloc_cb
static void alloc_cb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
Definition: benchmark-pound.c:84
uv_read_stop
int uv_read_stop(uv_stream_t *handle)
Definition: win/stream.c:99
uv_want_endgame
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
Definition: handle-inl.h:88
UV_HANDLE_BLOCKING_WRITES
@ UV_HANDLE_BLOCKING_WRITES
Definition: uv-common.h:90
uv_tcp_listen
int uv_tcp_listen(uv_tcp_t *tcp, int backlog, uv_connection_cb cb)
Definition: unix/tcp.c:328
uv_connect_s::cb
UV_REQ_FIELDS uv_connect_cb cb
Definition: uv.h:582
uv_alloc_cb
void(* uv_alloc_cb)(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
Definition: uv.h:306
uv_stream_s
Definition: uv.h:491
uv_stream_set_blocking
int uv_stream_set_blocking(uv_stream_t *handle, int blocking)
Definition: win/stream.c:233
req-inl.h
uv_accept
int uv_accept(uv_stream_t *server, uv_stream_t *client)
Definition: win/stream.c:49
req
static uv_connect_t req
Definition: test-connection-fail.c:30
uv_translate_sys_error
UV_EXTERN int uv_translate_sys_error(int sys_errno)
Definition: unix/core.c:1244
DECREASE_ACTIVE_COUNT
#define DECREASE_ACTIVE_COUNT(loop, handle)
Definition: handle-inl.h:32
uv_pipe_listen
int uv_pipe_listen(uv_pipe_t *handle, int backlog, uv_connection_cb cb)
Definition: unix/pipe.c:94
uv_pipe_read_start
int uv_pipe_read_start(uv_pipe_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: win/pipe.c:1179
uv_tty_write
int uv_tty_write(uv_loop_t *loop, uv_write_t *req, uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
Definition: win/tty.c:2182
REGISTER_HANDLE_REQ
#define REGISTER_HANDLE_REQ(loop, handle, req)
Definition: req-inl.h:56
uv_shutdown_cb
void(* uv_shutdown_cb)(uv_shutdown_t *req, int status)
Definition: uv.h:314
uv_try_write
int uv_try_write(uv_stream_t *stream, const uv_buf_t bufs[], unsigned int nbufs)
Definition: win/stream.c:176
uv_tty_read_start
int uv_tty_read_start(uv_tty_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: win/tty.c:1017
UV_HANDLE_SHUTTING
@ UV_HANDLE_SHUTTING
Definition: uv-common.h:76
uv_is_readable
int uv_is_readable(const uv_stream_t *handle)
Definition: win/stream.c:223
uv_tcp_s
Definition: uv.h:544
uv_tty_read_stop
int uv_tty_read_stop(uv_tty_t *handle)
Definition: win/tty.c:1053
bufs
static uv_buf_t bufs[5]
Definition: benchmark-udp-pummel.c:51
uv__tcp_try_write
int uv__tcp_try_write(uv_tcp_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
Definition: win/tcp.c:916
uv.h
UV_REQ_INIT
#define UV_REQ_INIT(req, typ)
Definition: uv-common.h:305
UV_HANDLE_CLOSING
@ UV_HANDLE_CLOSING
Definition: uv-common.h:66
uv_buf_t
Definition: unix.h:121
UV_HANDLE_READABLE
@ UV_HANDLE_READABLE
Definition: uv-common.h:84
uv_write_cb
void(* uv_write_cb)(uv_write_t *req, int status)
Definition: uv.h:312
server
Definition: examples/python/async_streaming/server.py:1
uv_connection_cb
void(* uv_connection_cb)(uv_stream_t *server, int status)
Definition: uv.h:315
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_HANDLE_READING
@ UV_HANDLE_READING
Definition: uv-common.h:82
uv_handle_s
Definition: uv.h:441
uv_write
int uv_write(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
Definition: win/stream.c:119
uv_loop_s
Definition: uv.h:1767
internal.h
uv_tcp_write
int uv_tcp_write(uv_loop_t *loop, uv_write_t *req, uv_tcp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
Definition: win/tcp.c:849
handle-inl.h
uv_tcp_read_start
int uv_tcp_read_start(uv_tcp_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: win/tcp.c:728
uv_pipe_accept
int uv_pipe_accept(uv_pipe_t *server, uv_stream_t *client)
Definition: win/pipe.c:878
uv_tcp_accept
int uv_tcp_accept(uv_tcp_t *server, uv_tcp_t *client)
Definition: win/tcp.c:659
cb
OPENSSL_EXPORT pem_password_cb * cb
Definition: pem.h:351
uv__pipe_read_stop
void uv__pipe_read_stop(uv_pipe_t *handle)
Definition: win/pipe.c:777
stream
voidpf stream
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:20