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 {
50 int ep_fd;
52
62
70struct gp_fd {
78 enum gp_poll_event_ret (*event)(gp_fd *self);
84 uint32_t events;
90 uint32_t revents;
92 int fd;
94 void *priv;
95};
96
103
112int gp_poll_add(gp_poll *self, gp_fd *fd);
113
122int gp_poll_rem(gp_poll *self, gp_fd *fd);
123
133
144int gp_poll_wait(gp_poll *self, int timeout_ms);
145
152static inline size_t gp_poll_fds(gp_poll *self)
153{
154 return self->fds.cnt;
155}
156
157#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:152
int gp_poll_rem(gp_poll *self, gp_fd *fd)
Removes a file descriptor.
A double linked list header.
Definition gp_list.h:34
A double linked list pointers.
Definition gp_list.h:56
size_t cnt
A number of elements in the list.
Definition gp_list.h:62
An epoll file descriptor.
Definition gp_poll.h:70
int fd
A file descriptor.
Definition gp_poll.h:92
gp_dlist_head lhead
Linked list pointers.
Definition gp_poll.h:72
uint32_t revents
Events returned from epoll.
Definition gp_poll.h:90
uint32_t events
Epoll events to watch.
Definition gp_poll.h:84
void * priv
Definition gp_poll.h:94
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.