byedpi/conev.h

108 lines
1.9 KiB
C
Raw Normal View History

2023-06-03 19:52:10 +00:00
#include <stdint.h>
#ifndef __linux__
2024-02-18 20:20:52 +00:00
#define NOEPOLL
2023-06-03 19:52:10 +00:00
#endif
2024-02-18 20:20:52 +00:00
#ifdef _WIN32
#include <ws2tcpip.h>
#define poll(fds, cnt, to) WSAPoll(fds, cnt, to)
#define close(fd) closesocket(fd)
2023-06-03 19:52:10 +00:00
#else
2024-02-18 20:20:52 +00:00
#include <netinet/in.h>
#include <unistd.h>
#ifndef NOEPOLL
#include <sys/epoll.h>
#define POLLIN EPOLLIN
#define POLLOUT EPOLLOUT
#define POLLERR EPOLLERR
#define POLLHUP EPOLLHUP
#define POLLRDHUP EPOLLRDHUP
#else
#include <sys/poll.h>
#endif
2023-06-03 19:52:10 +00:00
#endif
2024-02-18 20:20:52 +00:00
#ifndef POLLRDHUP
#define POLLRDHUP POLLHUP
2023-06-03 19:52:10 +00:00
#endif
enum eid {
EV_ACCEPT,
EV_REQUEST,
EV_CONNECT,
EV_IGNORE,
2024-03-08 00:37:02 +00:00
EV_TUNNEL,
2024-03-08 18:33:25 +00:00
EV_PRE_TUNNEL,
2024-03-08 00:37:02 +00:00
EV_DESYNC
2023-06-03 19:52:10 +00:00
};
2023-07-05 08:33:07 +00:00
#define FLAG_S4 1
#define FLAG_S5 2
#define FLAG_CONN 4
2023-06-03 19:52:10 +00:00
#ifndef CONEV_H
char *eid_name[] = {
"EV_ACCEPT",
"EV_REQUEST",
"EV_CONNECT",
"EV_IGNORE",
2024-03-08 00:37:02 +00:00
"EV_TUNNEL",
2024-03-08 18:33:25 +00:00
"EV_PRE_TUNNEL",
2024-03-08 00:37:02 +00:00
"EV_DESYNC"
2023-06-03 19:52:10 +00:00
};
#endif
2024-03-08 00:37:02 +00:00
struct buffer {
ssize_t size;
int offset;
char *data;
};
2023-06-03 19:52:10 +00:00
struct eval {
int fd;
int index;
enum eid type;
struct eval *pair;
2024-03-08 00:37:02 +00:00
struct buffer buff;
2023-06-03 19:52:10 +00:00
int flag;
2023-07-07 13:26:04 +00:00
union {
struct sockaddr_in in;
struct sockaddr_in6 in6;
};
2024-03-08 00:37:02 +00:00
ssize_t recv_count;
int try_count;
2024-03-08 18:33:25 +00:00
int saved_m;
2023-06-03 19:52:10 +00:00
#ifndef NOEPOLL
uint32_t events;
#endif
};
struct poolhd {
int max;
int count;
int efd;
struct eval **links;
struct eval *items;
#ifndef NOEPOLL
struct epoll_event *pevents;
#else
struct pollfd *pevents;
#endif
};
struct poolhd *init_pool(int count);
struct eval *add_event(struct poolhd *pool, enum eid type, int fd, int e);
struct eval *add_pair(struct poolhd *pool, struct eval *val, int sfd, int e);
void del_event(struct poolhd *pool, struct eval *val);
void destroy_pool(struct poolhd *pool);
struct eval *next_event(struct poolhd *pool, int *offs, int *type);
2023-10-10 18:24:46 +00:00
int mod_etype(struct poolhd *pool, struct eval *val, int type, char rm);