tor_multipath_voip/src/evt_core.h

59 lines
1.9 KiB
C
Raw Normal View History

2019-02-11 17:56:52 +00:00
#pragma once
#include <stdlib.h>
#include <stdio.h>
2019-02-11 21:40:00 +00:00
#include <unistd.h>
2019-02-11 17:56:52 +00:00
#include <sys/epoll.h>
2019-03-05 15:13:08 +00:00
#include <errno.h>
2019-02-11 17:56:52 +00:00
#include <glib-2.0/glib.h>
#include <glib-2.0/gmodule.h>
#include <glib-2.0/glib-object.h>
2019-02-11 21:40:00 +00:00
#include "net_tools.h"
#define EVT_CORE_MAX_EVENTS 10
2019-02-11 17:56:52 +00:00
struct evt_core_ctx;
struct evt_core_cat;
2019-02-18 20:55:53 +00:00
struct evt_core_fdinfo;
2019-02-11 17:56:52 +00:00
typedef void (*evt_core_free_app_ctx)(void*);
2019-02-20 16:46:58 +00:00
typedef int (*evt_core_cb)(struct evt_core_ctx*, struct evt_core_fdinfo*);
2019-02-11 17:56:52 +00:00
struct evt_core_cat {
void* app_ctx;
evt_core_free_app_ctx free_app_ctx;
evt_core_cb cb;
2019-02-18 20:55:53 +00:00
evt_core_cb err_cb;
2019-02-11 17:56:52 +00:00
char* name;
int flags;
2019-02-11 22:40:37 +00:00
GArray* socklist;
2019-02-11 17:56:52 +00:00
};
struct evt_core_ctx {
int epollfd;
2019-02-18 13:35:09 +00:00
GHashTable* catlist; // name -> category
GHashTable* socklist; // fd -> category
GHashTable* urltofd; // url -> fd, like "tcp:127.0.0.1:7500"
};
struct evt_core_fdinfo {
int fd;
char* url;
struct evt_core_cat* cat;
void* other;
evt_core_free_app_ctx free_other;
2019-02-11 17:56:52 +00:00
};
void evt_core_init(struct evt_core_ctx* ctx);
2019-02-11 21:40:00 +00:00
void evt_core_add_cat(struct evt_core_ctx* ctx, struct evt_core_cat* cat);
2019-03-21 17:43:38 +00:00
void evt_core_mv_fd(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, struct evt_core_cat* to_cat);
void evt_core_mv_fd2(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo, char* to_cat);
2019-03-22 16:14:35 +00:00
struct evt_core_fdinfo* evt_core_add_fd(struct evt_core_ctx* ctx, struct evt_core_fdinfo* user_data);
2019-02-15 14:45:56 +00:00
struct evt_core_cat* evt_core_rm_fd(struct evt_core_ctx* ctx, int fd);
2019-02-11 21:40:00 +00:00
void evt_core_free(struct evt_core_ctx* ctx);
void evt_core_loop(struct evt_core_ctx* ctx);
2019-02-18 14:11:12 +00:00
struct evt_core_fdinfo* evt_core_get_from_fd(struct evt_core_ctx* ctx, int fd);
struct evt_core_fdinfo* evt_core_get_from_url(struct evt_core_ctx* ctx, char* url);
2019-02-19 13:49:44 +00:00
void evt_core_free_app_ctx_simple(void* v);
2019-03-05 15:13:08 +00:00
struct evt_core_cat* evt_core_get_from_cat(struct evt_core_ctx* ctx, char* name);
struct evt_core_fdinfo* evt_core_get_first_from_cat(struct evt_core_ctx* ctx, char* name);