Rizin
unix-like reverse engineering framework and cli tools
stream.c File Reference
#include <assert.h>
#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"

Go to the source code of this file.

Functions

int uv_listen (uv_stream_t *stream, int backlog, uv_connection_cb cb)
 
int uv_accept (uv_stream_t *server, uv_stream_t *client)
 
int uv_read_start (uv_stream_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
 
int uv_read_stop (uv_stream_t *handle)
 
int uv_write (uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
 
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)
 
int uv_try_write (uv_stream_t *stream, const uv_buf_t bufs[], unsigned int nbufs)
 
int uv_shutdown (uv_shutdown_t *req, uv_stream_t *handle, uv_shutdown_cb cb)
 
int uv_is_readable (const uv_stream_t *handle)
 
int uv_is_writable (const uv_stream_t *handle)
 
int uv_stream_set_blocking (uv_stream_t *handle, int blocking)
 

Function Documentation

◆ uv_accept()

int uv_accept ( uv_stream_t server,
uv_stream_t client 
)

Definition at line 49 of file stream.c.

49  {
50  int err;
51 
52  err = ERROR_INVALID_PARAMETER;
53  switch (server->type) {
54  case UV_TCP:
55  err = uv_tcp_accept((uv_tcp_t*)server, (uv_tcp_t*)client);
56  break;
57  case UV_NAMED_PIPE:
58  err = uv_pipe_accept((uv_pipe_t*)server, client);
59  break;
60  default:
61  assert(0);
62  }
63 
65 }
static bool err
Definition: armass.c:435
assert(limit<=UINT32_MAX/2)
Definition: uv.h:767
Definition: uv.h:547
int uv_tcp_accept(uv_tcp_t *server, uv_tcp_t *client)
Definition: tcp.c:657
int uv_pipe_accept(uv_pipe_t *server, uv_stream_t *client)
Definition: pipe.c:876
UV_EXTERN int uv_translate_sys_error(int sys_errno)
Definition: core.c:1249

References assert(), done, err, uv__stream_queued_fds_s::fds, NULL, uv__stream_queued_fds_s::offset, uv__close(), uv__free(), uv__io_start(), uv__stream_open(), UV_HANDLE_BOUND, UV_HANDLE_READABLE, UV_HANDLE_WRITABLE, uv_pipe_accept(), uv_tcp_accept(), uv_translate_sys_error(), and uv_udp_open().

Referenced by on_new_connection().

◆ uv_is_readable()

int uv_is_readable ( const uv_stream_t handle)

Definition at line 223 of file stream.c.

223  {
224  return !!(handle->flags & UV_HANDLE_READABLE);
225 }
static mcore_handle handle
Definition: asm_mcore.c:8
@ UV_HANDLE_READABLE
Definition: uv-common.h:92

References handle, and UV_HANDLE_READABLE.

◆ uv_is_writable()

int uv_is_writable ( const uv_stream_t handle)

Definition at line 228 of file stream.c.

228  {
229  return !!(handle->flags & UV_HANDLE_WRITABLE);
230 }
@ UV_HANDLE_WRITABLE
Definition: uv-common.h:93

References handle, and UV_HANDLE_WRITABLE.

◆ uv_listen()

int uv_listen ( uv_stream_t stream,
int  backlog,
uv_connection_cb  cb 
)

Definition at line 30 of file stream.c.

30  {
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 }
voidpf stream
Definition: ioapi.h:138
int uv_pipe_listen(uv_pipe_t *handle, int backlog, uv_connection_cb cb)
Definition: pipe.c:94
int uv_tcp_listen(uv_tcp_t *tcp, int backlog, uv_connection_cb cb)
Definition: tcp.c:328
static const char * cb[]
Definition: z80_tab.h:176

References assert(), cb, err, uv__handle_start, uv_pipe_listen(), uv_tcp_listen(), and uv_translate_sys_error().

Referenced by main().

◆ uv_read_start()

int uv_read_start ( uv_stream_t handle,
uv_alloc_cb  alloc_cb,
uv_read_cb  read_cb 
)

Definition at line 68 of file stream.c.

69  {
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:
83  err = uv_tcp_read_start((uv_tcp_t*)handle, alloc_cb, read_cb);
84  break;
85  case UV_NAMED_PIPE:
86  err = uv_pipe_read_start((uv_pipe_t*)handle, alloc_cb, read_cb);
87  break;
88  case UV_TTY:
89  err = uv_tty_read_start((uv_tty_t*) handle, alloc_cb, read_cb);
90  break;
91  default:
92  assert(0);
93  }
94 
96 }
Definition: uv.h:714
int uv_tcp_read_start(uv_tcp_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: tcp.c:726
int uv_pipe_read_start(uv_pipe_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: pipe.c:1177
int uv_tty_read_start(uv_tty_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: tty.c:1018
@ UV_HANDLE_READING
Definition: uv-common.h:90

References assert(), err, handle, uv__handle_start, uv__io_start(), uv__stream_fd, uv__stream_osx_interrupt_select(), UV_HANDLE_CLOSING, UV_HANDLE_READABLE, UV_HANDLE_READING, uv_pipe_read_start(), uv_tcp_read_start(), uv_translate_sys_error(), and uv_tty_read_start().

Referenced by main(), on_connect(), and on_new_connection().

◆ uv_read_stop()

int uv_read_stop ( uv_stream_t handle)

Definition at line 99 of file stream.c.

99  {
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 }
#define DECREASE_ACTIVE_COUNT(loop, handle)
Definition: handle-inl.h:32
void uv__pipe_read_stop(uv_pipe_t *handle)
Definition: pipe.c:775
int uv_tty_read_stop(uv_tty_t *handle)
Definition: tty.c:1054

References DECREASE_ACTIVE_COUNT, err, handle, NULL, uv__handle_stop, uv__io_active(), uv__io_stop(), uv__pipe_read_stop(), uv__stream_osx_interrupt_select(), UV_HANDLE_READING, uv_translate_sys_error(), and uv_tty_read_stop().

Referenced by eof_timer_cb(), uv_pipe_read_eof(), and uv_pipe_read_error().

◆ uv_shutdown()

int uv_shutdown ( uv_shutdown_t req,
uv_stream_t handle,
uv_shutdown_cb  cb 
)

Definition at line 198 of file stream.c.

198  {
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 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
Definition: handle-inl.h:88
#define REGISTER_HANDLE_REQ(loop, handle, req)
Definition: req-inl.h:56
Definition: uv.h:1780
uv_loop_t * loop
Definition: main.c:7
@ UV_HANDLE_SHUTTING
Definition: uv-common.h:84
#define uv__is_closing(h)
Definition: uv-common.h:255
#define UV_REQ_INIT(req, typ)
Definition: uv-common.h:322

References assert(), cb, handle, loop, REGISTER_HANDLE_REQ, req, uv__io_start(), uv__is_closing, uv__req_init, uv__stream_fd, uv__stream_osx_interrupt_select(), UV_HANDLE_SHUT, UV_HANDLE_SHUTTING, UV_HANDLE_WRITABLE, UV_REQ_INIT, and uv_want_endgame().

◆ uv_stream_set_blocking()

int uv_stream_set_blocking ( uv_stream_t handle,
int  blocking 
)

Definition at line 233 of file stream.c.

233  {
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_BLOCKING_WRITES
Definition: uv-common.h:98

References handle, uv__nonblock, uv__stream_fd, and UV_HANDLE_BLOCKING_WRITES.

◆ uv_try_write()

int uv_try_write ( uv_stream_t stream,
const uv_buf_t  bufs[],
unsigned int  nbufs 
)

Definition at line 176 of file stream.c.

178  {
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 }
int uv__tcp_try_write(uv_tcp_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
Definition: tcp.c:968
int uv__tty_try_write(uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
Definition: tty.c:2212
static char bufs[4][128]
Buffers for uint64_to_str() and uint64_to_nicestr()
Definition: util.c:18
@ UV_HANDLE_CLOSING
Definition: uv-common.h:74

References assert(), bufs, NULL, QUEUE_REMOVE, r, req, uv__count_bufs(), uv__free(), uv__io_active(), uv__io_stop(), uv__req_unregister, uv__stream_osx_interrupt_select(), uv__tcp_try_write(), uv__tty_try_write(), uv__write_req_size(), UV_HANDLE_CLOSING, UV_HANDLE_WRITABLE, uv_try_write_cb(), and uv_write().

◆ 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 at line 119 of file stream.c.

123  {
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 }
#define NULL
Definition: cris-opc.c:27
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: pipe.c:1578
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: tty.c:2182
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: tcp.c:901

References assert(), bufs, cb, err, handle, loop, NULL, req, uv__pipe_write(), UV_HANDLE_WRITABLE, uv_tcp_write(), uv_translate_sys_error(), uv_tty_write(), and uv_write2().

Referenced by echo_read(), main(), update(), and write_data().

◆ 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 at line 151 of file stream.c.

156  {
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 }
int uv_write(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
Definition: stream.c:1492

References ARRAY_SIZE, assert(), bufs, cb, err, handle, loop, memcpy(), NULL, QUEUE_INIT, QUEUE_INSERT_TAIL, req, uv__count_bufs(), uv__handle_fd(), uv__io_start(), uv__malloc(), uv__pipe_write(), uv__req_init, uv__stream_fd, uv__stream_osx_interrupt_select(), uv__write(), UV_HANDLE_BLOCKING_WRITES, UV_HANDLE_WRITABLE, uv_translate_sys_error(), and uv_write().

Referenced by on_new_connection().