Concord - C Discord API library
A Discord API wrapper library written in C
io_poller.h File Reference
#include <stdbool.h>
#include <curl/curl.h>
Include dependency graph for io_poller.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef int io_poller_socket
 a socket or file descriptor More...
 
typedef void(* io_poller_cb) (struct io_poller *io, enum io_poller_events events, void *user_data)
 callback for when an event is triggered by the socket More...
 
typedef int(* io_poller_curl_cb) (struct io_poller *io, CURLM *multi, void *user_data)
 callback for when curl multi should be performed on More...
 

Enumerations

enum  io_poller_events { IO_POLLER_IN = 1 << 0 , IO_POLLER_OUT = 1 << 1 }
 The flags to poll for. More...
 

Functions

struct io_poller * io_poller_create (void)
 
void io_poller_destroy (struct io_poller *io)
 
void io_poller_wakeup (struct io_poller *io)
 wakeup the thread listening to this io_poller More...
 
int io_poller_poll (struct io_poller *io, int milliseconds)
 wait for events to be triggered More...
 
int io_poller_perform (struct io_poller *io)
 performs any actions needed and clears events set by io_poller_poll More...
 
bool io_poller_socket_add (struct io_poller *io, io_poller_socket sock, enum io_poller_events events, io_poller_cb cb, void *user_data)
 adds or modifies a socket or file descriptor to watch list More...
 
bool io_poller_socket_del (struct io_poller *io, io_poller_socket sock)
 removes a socket or file descriptor from watch list More...
 
bool io_poller_curlm_add (struct io_poller *io, CURLM *multi, io_poller_curl_cb cb, void *user_data)
 add or modifies a curl multi to watch list More...
 
bool io_poller_curlm_del (struct io_poller *io, CURLM *multi)
 remove curl multi from watch list More...
 
bool io_poller_curlm_enable_perform (struct io_poller *io, CURLM *multi)
 this multi should be performed on next cycle causing poll to return immediately More...
 

Typedef Documentation

◆ io_poller_socket

typedef int io_poller_socket

a socket or file descriptor

◆ io_poller_cb

typedef void(* io_poller_cb) (struct io_poller *io, enum io_poller_events events, void *user_data)

callback for when an event is triggered by the socket

◆ io_poller_curl_cb

typedef int(* io_poller_curl_cb) (struct io_poller *io, CURLM *multi, void *user_data)

callback for when curl multi should be performed on

Enumeration Type Documentation

◆ io_poller_events

The flags to poll for.

Enumerator
IO_POLLER_IN 
IO_POLLER_OUT 

Function Documentation

◆ io_poller_create()

struct io_poller * io_poller_create ( void  )

◆ io_poller_destroy()

void io_poller_destroy ( struct io_poller *  io)

◆ io_poller_wakeup()

void io_poller_wakeup ( struct io_poller *  io)

wakeup the thread listening to this io_poller

Parameters
iothe io_poller to wake up

◆ io_poller_poll()

int io_poller_poll ( struct io_poller *  io,
int  milliseconds 
)

wait for events to be triggered

Parameters
iothe io_poller to poll on
milliseconds-1 for infinity, or ms to poll for
Returns
-1 for error, or number of sockets that have events waiting

◆ io_poller_perform()

int io_poller_perform ( struct io_poller *  io)

performs any actions needed and clears events set by io_poller_poll

Parameters
iothe io_poller to perform on
Returns
0 on success

◆ io_poller_socket_add()

bool io_poller_socket_add ( struct io_poller *  io,
io_poller_socket  sock,
enum io_poller_events  events,
io_poller_cb  cb,
void *  user_data 
)

adds or modifies a socket or file descriptor to watch list

Parameters
iothe io_poller to add socket to
sockthe file descriptor or socket to handle
eventsthe events to watch for
cbthe callback for when any event is triggered
user_datacustom user data
Returns
true on success

◆ io_poller_socket_del()

bool io_poller_socket_del ( struct io_poller *  io,
io_poller_socket  sock 
)

removes a socket or file descriptor from watch list

Parameters
iothe io_poller to remove the socket from
sockthe file descriptor or socket to remove
Returns
true on success

◆ io_poller_curlm_add()

bool io_poller_curlm_add ( struct io_poller *  io,
CURLM *  multi,
io_poller_curl_cb  cb,
void *  user_data 
)

add or modifies a curl multi to watch list

Parameters
iothe io_poller to add curl multi to
multithe curl multi to add or modify
cbthe callback for when curl multi should be performed on
user_datacustom user data
Returns
true on success

◆ io_poller_curlm_del()

bool io_poller_curlm_del ( struct io_poller *  io,
CURLM *  multi 
)

remove curl multi from watch list

Parameters
iothe io_poller to remove curl multi from
multithe curl multi to remove
Returns
true on success

◆ io_poller_curlm_enable_perform()

bool io_poller_curlm_enable_perform ( struct io_poller *  io,
CURLM *  multi 
)

this multi should be performed on next cycle causing poll to return immediately

Parameters
iothe io_poller to enable perform on
multithe multi that should be performed
Returns
true on success