1 | /* -*- indent-tabs-mode: nil; -*- */
|
---|
2 | #ifndef _PROXY_POLLMGR_H_
|
---|
3 | #define _PROXY_POLLMGR_H_
|
---|
4 |
|
---|
5 | #ifndef RT_OS_WINDOWS
|
---|
6 | # include <unistd.h> /* for ssize_t */
|
---|
7 | #endif
|
---|
8 | #include "lwip/sys.h"
|
---|
9 |
|
---|
10 | enum pollmgr_slot_t {
|
---|
11 | POLLMGR_CHAN_PXTCP_ADD, /* new proxy tcp connection from guest */
|
---|
12 | POLLMGR_CHAN_PXTCP_POLLIN, /* free space in ringbuf, may POLLIN */
|
---|
13 | POLLMGR_CHAN_PXTCP_POLLOUT, /* schedule one-shot POLLOUT callback */
|
---|
14 | POLLMGR_CHAN_PXTCP_DEL, /* delete pxtcp */
|
---|
15 | POLLMGR_CHAN_PXTCP_RESET, /* send RST and delete pxtcp */
|
---|
16 |
|
---|
17 | POLLMGR_CHAN_PXUDP_ADD, /* new proxy udp conversation from guest */
|
---|
18 | POLLMGR_CHAN_PXUDP_DEL, /* delete pxudp from pollmgr */
|
---|
19 |
|
---|
20 | POLLMGR_CHAN_PORTFWD, /* add/remove port forwarding rules */
|
---|
21 |
|
---|
22 | POLLMGR_SLOT_STATIC_COUNT,
|
---|
23 | POLLMGR_SLOT_FIRST_DYNAMIC = POLLMGR_SLOT_STATIC_COUNT
|
---|
24 | };
|
---|
25 |
|
---|
26 |
|
---|
27 | struct pollmgr_handler; /* forward */
|
---|
28 | typedef int (*pollmgr_callback)(struct pollmgr_handler *, SOCKET, int);
|
---|
29 |
|
---|
30 | struct pollmgr_handler {
|
---|
31 | pollmgr_callback callback;
|
---|
32 | void *data;
|
---|
33 | int slot;
|
---|
34 | };
|
---|
35 |
|
---|
36 | struct pollmgr_refptr {
|
---|
37 | struct pollmgr_handler *ptr;
|
---|
38 | sys_mutex_t lock;
|
---|
39 | size_t strong;
|
---|
40 | size_t weak;
|
---|
41 | };
|
---|
42 |
|
---|
43 | int pollmgr_init(void);
|
---|
44 |
|
---|
45 | /* static named slots (aka "channels") */
|
---|
46 | SOCKET pollmgr_add_chan(int, struct pollmgr_handler *);
|
---|
47 | ssize_t pollmgr_chan_send(int, void *buf, size_t nbytes);
|
---|
48 | void *pollmgr_chan_recv_ptr(struct pollmgr_handler *, SOCKET, int);
|
---|
49 |
|
---|
50 | /* dynamic slots */
|
---|
51 | int pollmgr_add(struct pollmgr_handler *, SOCKET, int);
|
---|
52 |
|
---|
53 | /* special-purpose strong/weak references */
|
---|
54 | struct pollmgr_refptr *pollmgr_refptr_create(struct pollmgr_handler *);
|
---|
55 | void pollmgr_refptr_weak_ref(struct pollmgr_refptr *);
|
---|
56 | struct pollmgr_handler *pollmgr_refptr_get(struct pollmgr_refptr *);
|
---|
57 | void pollmgr_refptr_unref(struct pollmgr_refptr *);
|
---|
58 |
|
---|
59 | void pollmgr_update_events(int, int);
|
---|
60 | void pollmgr_del_slot(int);
|
---|
61 |
|
---|
62 | void pollmgr_thread(void *);
|
---|
63 |
|
---|
64 | /* buffer for callbacks to receive udp without worrying about truncation */
|
---|
65 | extern u8_t pollmgr_udpbuf[64 * 1024];
|
---|
66 |
|
---|
67 | #endif /* _PROXY_POLLMGR_H_ */
|
---|