lokinet/include/llarp/ev.h

69 lines
1.8 KiB
C
Raw Normal View History

2018-01-25 16:24:33 +00:00
#ifndef LLARP_EV_H
#define LLARP_EV_H
2018-01-29 14:19:00 +00:00
#include <stdbool.h>
2018-01-29 14:27:24 +00:00
#include <stdint.h>
#include <stdlib.h>
2018-01-25 16:24:33 +00:00
#include <sys/socket.h>
#ifdef __cplusplus
extern "C" {
#endif
2018-01-29 14:27:24 +00:00
struct llarp_ev_loop;
void llarp_ev_loop_alloc(struct llarp_ev_loop **ev);
void llarp_ev_loop_free(struct llarp_ev_loop **ev);
int llarp_ev_loop_run(struct llarp_ev_loop *ev);
/** stop event loop and wait for it to complete all jobs */
void llarp_ev_loop_stop(struct llarp_ev_loop *ev);
struct llarp_udp_listener {
2018-02-01 17:07:01 +00:00
struct sockaddr_in6 *addr;
2018-01-29 14:27:24 +00:00
void *user;
void *impl;
void (*recvfrom)(struct llarp_udp_listener *, const struct sockaddr *, char *,
ssize_t);
void (*closed)(struct llarp_udp_listener *);
};
int llarp_ev_add_udp_listener(struct llarp_ev_loop *ev,
struct llarp_udp_listener *listener);
int llarp_ev_close_udp_listener(struct llarp_udp_listener *listener);
2018-02-01 13:21:00 +00:00
struct llarp_ev_async_call;
2018-01-31 19:59:26 +00:00
typedef void (*llarp_ev_work_func)(struct llarp_ev_async_call *);
2018-02-01 13:21:00 +00:00
struct llarp_ev_caller;
2018-01-31 19:59:26 +00:00
struct llarp_ev_async_call {
2018-01-29 14:27:24 +00:00
/** the loop this job belongs to */
2018-01-31 19:59:26 +00:00
const struct llarp_ev_loop *loop;
/** private implementation */
2018-02-01 13:21:00 +00:00
const struct llarp_ev_caller *parent;
2018-01-29 14:27:24 +00:00
/** user data */
2018-01-31 19:59:26 +00:00
const void *user;
2018-02-01 13:21:00 +00:00
/**
2018-01-31 19:59:26 +00:00
work is called async when ready in the event loop thread
must not free from inside this call as it is done elsewhere
*/
const llarp_ev_work_func work;
2018-01-29 14:27:24 +00:00
};
2018-02-01 13:21:00 +00:00
struct llarp_ev_caller *llarp_ev_prepare_async(struct llarp_ev_loop *ev,
llarp_ev_work_func func);
bool llarp_ev_call_async(struct llarp_ev_caller *c, void *user);
2018-01-31 19:59:26 +00:00
2018-02-01 22:34:04 +00:00
bool larp_ev_call_many_async(struct llarp_ev_caller *c, void **users, size_t n);
2018-02-01 13:21:00 +00:00
void llarp_ev_caller_stop(struct llarp_ev_caller *c);
2018-01-29 14:27:24 +00:00
2018-01-25 16:24:33 +00:00
#ifdef __cplusplus
}
#endif
#endif