Rizin
unix-like reverse engineering framework and cli tools
poll.c File Reference
#include "uv.h"
#include "internal.h"
#include <unistd.h>
#include <assert.h>
#include <errno.h>

Go to the source code of this file.

Functions

static void uv__poll_io (uv_loop_t *loop, uv__io_t *w, unsigned int events)
 
int uv_poll_init (uv_loop_t *loop, uv_poll_t *handle, int fd)
 
int uv_poll_init_socket (uv_loop_t *loop, uv_poll_t *handle, uv_os_sock_t socket)
 
static void uv__poll_stop (uv_poll_t *handle)
 
int uv_poll_stop (uv_poll_t *handle)
 
int uv_poll_start (uv_poll_t *handle, int pevents, uv_poll_cb poll_cb)
 
void uv__poll_close (uv_poll_t *handle)
 

Function Documentation

◆ uv__poll_close()

void uv__poll_close ( uv_poll_t handle)

Definition at line 148 of file poll.c.

148  {
150 }
static mcore_handle handle
Definition: asm_mcore.c:8
static void uv__poll_stop(uv_poll_t *handle)
Definition: poll.c:102

References handle, and uv__poll_stop().

Referenced by uv_close().

◆ uv__poll_io()

static void uv__poll_io ( uv_loop_t loop,
uv__io_t w,
unsigned int  events 
)
static

Definition at line 30 of file poll.c.

30  {
32  int pevents;
33 
34  handle = container_of(w, uv_poll_t, io_watcher);
35 
36  /*
37  * As documented in the kernel source fs/kernfs/file.c #780
38  * poll will return POLLERR|POLLPRI in case of sysfs
39  * polling. This does not happen in case of out-of-band
40  * TCP messages.
41  *
42  * The above is the case on (at least) FreeBSD and Linux.
43  *
44  * So to properly determine a POLLPRI or a POLLERR we need
45  * to check for both.
46  */
47  if ((events & POLLERR) && !(events & UV__POLLPRI)) {
48  uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
50  handle->poll_cb(handle, UV_EBADF, 0);
51  return;
52  }
53 
54  pevents = 0;
55  if (events & POLLIN)
56  pevents |= UV_READABLE;
57  if (events & UV__POLLPRI)
58  pevents |= UV_PRIORITIZED;
59  if (events & POLLOUT)
60  pevents |= UV_WRITABLE;
61  if (events & UV__POLLRDHUP)
62  pevents |= UV_DISCONNECT;
63 
64  handle->poll_cb(handle, 0, pevents);
65 }
#define w
Definition: crypto_rc6.c:13
#define container_of(ptr, type, member)
Definition: rz_types.h:650
Definition: uv.h:793
uv_loop_t * loop
Definition: main.c:7
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:910
#define UV__POLLRDHUP
Definition: internal.h:116
#define UV__POLLPRI
Definition: internal.h:122
#define uv__handle_stop(h)
Definition: uv-common.h:266
@ UV_WRITABLE
Definition: uv.h:801
@ UV_DISCONNECT
Definition: uv.h:802
@ UV_PRIORITIZED
Definition: uv.h:803
@ UV_READABLE
Definition: uv.h:800

References container_of, handle, loop, uv__handle_stop, uv__io_stop(), UV__POLLPRI, UV__POLLRDHUP, UV_DISCONNECT, UV_PRIORITIZED, UV_READABLE, UV_WRITABLE, and w.

Referenced by uv_poll_init().

◆ uv__poll_stop()

static void uv__poll_stop ( uv_poll_t handle)
static

Definition at line 102 of file poll.c.

102  {
103  uv__io_stop(handle->loop,
104  &handle->io_watcher,
105  POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
107  uv__platform_invalidate_fd(handle->loop, handle->io_watcher.fd);
108 }
void uv__platform_invalidate_fd(uv_loop_t *loop, int fd)
Definition: aix.c:1280

References handle, uv__handle_stop, uv__io_stop(), uv__platform_invalidate_fd(), UV__POLLPRI, and UV__POLLRDHUP.

Referenced by uv__poll_close(), uv_poll_start(), and uv_poll_stop().

◆ uv_poll_init()

int uv_poll_init ( uv_loop_t loop,
uv_poll_t handle,
int  fd 
)

Definition at line 68 of file poll.c.

68  {
69  int err;
70 
71  if (uv__fd_exists(loop, fd))
72  return UV_EEXIST;
73 
75  if (err)
76  return err;
77 
78  /* If ioctl(FIONBIO) reports ENOTTY, try fcntl(F_GETFL) + fcntl(F_SETFL).
79  * Workaround for e.g. kqueue fds not supporting ioctls.
80  */
81  err = uv__nonblock(fd, 1);
82  if (err == UV_ENOTTY)
85 
86  if (err)
87  return err;
88 
89  uv__handle_init(loop, (uv_handle_t*) handle, UV_POLL);
90  uv__io_init(&handle->io_watcher, uv__poll_io, fd);
91  handle->poll_cb = NULL;
92  return 0;
93 }
int uv__io_check_fd(uv_loop_t *loop, int fd)
Definition: aix.c:115
static bool err
Definition: armass.c:435
#define NULL
Definition: cris-opc.c:27
int uv__nonblock_ioctl(int fd, int set)
Definition: core.c:578
int uv__fd_exists(uv_loop_t *loop, int fd)
Definition: core.c:965
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
Definition: core.c:865
int uv__nonblock_fcntl(int fd, int set)
Definition: core.c:608
#define uv__nonblock
Definition: internal.h:170
static void uv__poll_io(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: poll.c:30
#define uv__handle_init(loop_, h, type_)
Definition: uv-common.h:301
static const z80_opcode fd[]
Definition: z80_tab.h:997

Referenced by uv_poll_init_socket().

◆ uv_poll_init_socket()

int uv_poll_init_socket ( uv_loop_t loop,
uv_poll_t handle,
uv_os_sock_t  socket 
)

Definition at line 96 of file poll.c.

97  {
98  return uv_poll_init(loop, handle, socket);
99 }
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 socket
Definition: sflib.h:79
int uv_poll_init(uv_loop_t *loop, uv_poll_t *handle, int fd)
Definition: poll.c:68

Referenced by uv_poll_init().

◆ uv_poll_start()

int uv_poll_start ( uv_poll_t handle,
int  pevents,
uv_poll_cb  poll_cb 
)

Definition at line 118 of file poll.c.

118  {
119  int events;
120 
121  assert((pevents & ~(UV_READABLE | UV_WRITABLE | UV_DISCONNECT |
122  UV_PRIORITIZED)) == 0);
124 
126 
127  if (pevents == 0)
128  return 0;
129 
130  events = 0;
131  if (pevents & UV_READABLE)
132  events |= POLLIN;
133  if (pevents & UV_PRIORITIZED)
134  events |= UV__POLLPRI;
135  if (pevents & UV_WRITABLE)
136  events |= POLLOUT;
137  if (pevents & UV_DISCONNECT)
138  events |= UV__POLLRDHUP;
139 
140  uv__io_start(handle->loop, &handle->io_watcher, events);
142  handle->poll_cb = poll_cb;
143 
144  return 0;
145 }
static void poll_cb(uv_fs_t *req)
Definition: fs-poll.c:185
assert(limit<=UINT32_MAX/2)
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:882
#define uv__is_closing(h)
Definition: uv-common.h:255
#define uv__handle_start(h)
Definition: uv-common.h:258

◆ uv_poll_stop()

int uv_poll_stop ( uv_poll_t handle)

Definition at line 111 of file poll.c.

111  {
114  return 0;
115 }