GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
gp_poll.h File Reference

A simple epoll wrapper. More...

#include <utils/gp_types.h>
#include <utils/gp_list.h>

Go to the source code of this file.

Data Structures

struct  gp_poll
 An epoll instance. More...
 
struct  gp_fd
 An epoll file descriptor. More...
 

Typedefs

typedef struct gp_poll gp_poll
 An epoll instance.
 

Enumerations

enum  gp_poll_events {
  GP_POLLIN = 0x01 , GP_POLLPRI = 0x02 , GP_POLLOUT = 0x04 , GP_POLLERR = 0x08 ,
  GP_POLLHUP = 0x10
}
 A gp_epoll flags. More...
 
enum  gp_poll_event_ret { GP_POLL_RET_OK = 0 , GP_POLL_RET_REM = 1 }
 A return value from the event() callback. More...
 

Functions

void gp_poll_clear (gp_poll *self)
 Removes all file descriptors from the poll.
 
int gp_poll_add (gp_poll *self, gp_fd *fd)
 Adds a file descriptor.
 
int gp_poll_rem (gp_poll *self, gp_fd *fd)
 Removes a file descriptor.
 
gp_fdgp_poll_rem_by_fd (gp_poll *self, int fd)
 Looks up and removes a gp_fd by a fd.
 
int gp_poll_wait (gp_poll *self, int timeout_ms)
 A wrapper around the poll().
 
static size_t gp_poll_fds (gp_poll *self)
 Returns a number of fds in the poll instance.
 

Detailed Description

A simple epoll wrapper.

Definition in file gp_poll.h.

Enumeration Type Documentation

◆ gp_poll_event_ret

A return value from the event() callback.

Enumerator
GP_POLL_RET_OK 

Processing datat was fine

GP_POLL_RET_REM 

Remove the fd from the epoll list

Definition at line 56 of file gp_poll.h.

◆ gp_poll_events

A gp_epoll flags.

This maps 1:1 to epoll and poll

Enumerator
GP_POLLIN 

There are data to read

GP_POLLPRI 

There is exceptional condition on the fd

GP_POLLOUT 

Writing is now possible

GP_POLLERR 

Error condition has happended

GP_POLLHUP 

Hang up

Definition at line 24 of file gp_poll.h.

Function Documentation

◆ gp_poll_add()

int gp_poll_add ( gp_poll self,
gp_fd fd 
)

Adds a file descriptor.

Parameters
selfThe gp_poll struct.
fdA struct gp_fd filled in by the user.
Returns
0 on success and -1 if the underlying epoll() call failed.

◆ gp_poll_clear()

void gp_poll_clear ( gp_poll self)

Removes all file descriptors from the poll.

Parameters
selfThe gp_poll struct.

◆ gp_poll_fds()

static size_t gp_poll_fds ( gp_poll self)
inlinestatic

Returns a number of fds in the poll instance.

Parameters
selfThe fds struct.
Returns
Number of fds in the queue.

Definition at line 144 of file gp_poll.h.

References gp_poll::fds.

◆ gp_poll_rem()

int gp_poll_rem ( gp_poll self,
gp_fd fd 
)

Removes a file descriptor.

Parameters
selfThe poll struct.
fdFile descriptor to be removed.
Returns
0 on success and -1 if fd is not in fds.

◆ gp_poll_rem_by_fd()

gp_fd * gp_poll_rem_by_fd ( gp_poll self,
int  fd 
)

Looks up and removes a gp_fd by a fd.

Parameters
selfThe poll struct.
fdA file descriptor for the lookup.
Returns
A gp_fd if found or NULL.

◆ gp_poll_wait()

int gp_poll_wait ( gp_poll self,
int  timeout_ms 
)

A wrapper around the poll().

Polls for file descriptors added by the gp_fds_add() function, calls event() callback for each fd if events are returned.

Parameters
selfThe fds struct.
timeout_msTimeout passed to poll().
Returns
A zero on success, -1 otherwise.