GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_poll.h
Go to the documentation of this file.
1//SPDX-License-Identifier: LGPL-2.0-or-later
2/*
3
4 Copyright (c) 2019-2023 Cyril Hrubis <metan@ucw.cz>
5
6 */
7
13#ifndef UTILS_GP_POLL
14#define UTILS_GP_POLL
15
16#include <utils/gp_types.h>
17#include <utils/gp_list.h>
18
26 GP_POLLIN = 0x01,
28 GP_POLLPRI = 0x02,
30 GP_POLLOUT = 0x04,
32 GP_POLLERR = 0x08,
34 GP_POLLHUP = 0x10,
35};
36
37#define GP_POLLIN GP_POLLIN
38#define GP_POLLPRI GP_POLLPRI
39#define GP_POLLOUT GP_POLLOUT
40#define GP_POLLERR GP_POLLERR
41#define GP_POLLHUP GP_POLLHUP
42
46typedef struct gp_poll {
48 gp_dlist fds;
50 int ep_fd;
52
62
70struct gp_fd {
72 gp_dlist_head lhead;
78 enum gp_poll_event_ret (*event)(gp_fd *self);
80 uint32_t events;
82 uint32_t revents;
84 int fd;
86 void *priv;
87};
88
95
104int gp_poll_add(gp_poll *self, gp_fd *fd);
105
114int gp_poll_rem(gp_poll *self, gp_fd *fd);
115
125
136int gp_poll_wait(gp_poll *self, int timeout_ms);
137
144static inline size_t gp_poll_fds(gp_poll *self)
145{
146 return self->fds.cnt;
147}
148
149#endif /* UTILS_GP_POLL */
A linked list implementation.
int gp_poll_wait(gp_poll *self, int timeout_ms)
A wrapper around the poll().
int gp_poll_add(gp_poll *self, gp_fd *fd)
Adds a file descriptor.
void gp_poll_clear(gp_poll *self)
Removes all file descriptors from the poll.
gp_poll_event_ret
A return value from the event() callback.
Definition gp_poll.h:56
@ GP_POLL_RET_OK
Definition gp_poll.h:58
@ GP_POLL_RET_REM
Definition gp_poll.h:60
gp_poll_events
A gp_epoll flags.
Definition gp_poll.h:24
gp_fd * gp_poll_rem_by_fd(gp_poll *self, int fd)
Looks up and removes a gp_fd by a fd.
static size_t gp_poll_fds(gp_poll *self)
Returns a number of fds in the poll instance.
Definition gp_poll.h:144
int gp_poll_rem(gp_poll *self, gp_fd *fd)
Removes a file descriptor.
An epoll file descriptor.
Definition gp_poll.h:70
int fd
A file descriptor.
Definition gp_poll.h:84
gp_dlist_head lhead
Linked list pointers.
Definition gp_poll.h:72
uint32_t revents
Events returned from epoll.
Definition gp_poll.h:82
uint32_t events
Epoll events to watch.
Definition gp_poll.h:80
void * priv
Definition gp_poll.h:86
enum gp_poll_event_ret(* event)(gp_fd *self)
Epoll event handler.
Definition gp_poll.h:78
An epoll instance.
Definition gp_poll.h:46
int ep_fd
Definition gp_poll.h:50
gp_dlist fds
Definition gp_poll.h:48
Common header for types.