1 | /* $Id: proxy_pollmgr.h 56230 2015-06-03 21:25:33Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NAT Network - poll manager, definitions and declarations.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2014 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef _PROXY_POLLMGR_H_
|
---|
19 | #define _PROXY_POLLMGR_H_
|
---|
20 |
|
---|
21 | #ifndef RT_OS_WINDOWS
|
---|
22 | # include <unistd.h> /* for ssize_t */
|
---|
23 | #endif
|
---|
24 | #include "lwip/sys.h"
|
---|
25 |
|
---|
26 | enum pollmgr_slot_t {
|
---|
27 | POLLMGR_CHAN_PXTCP_ADD, /* new proxy tcp connection from guest */
|
---|
28 | POLLMGR_CHAN_PXTCP_POLLIN, /* free space in ringbuf, may POLLIN */
|
---|
29 | POLLMGR_CHAN_PXTCP_POLLOUT, /* schedule one-shot POLLOUT callback */
|
---|
30 | POLLMGR_CHAN_PXTCP_DEL, /* delete pxtcp */
|
---|
31 | POLLMGR_CHAN_PXTCP_RESET, /* send RST and delete pxtcp */
|
---|
32 |
|
---|
33 | POLLMGR_CHAN_PXUDP_ADD, /* new proxy udp conversation from guest */
|
---|
34 | POLLMGR_CHAN_PXUDP_DEL, /* delete pxudp from pollmgr */
|
---|
35 |
|
---|
36 | POLLMGR_CHAN_PORTFWD, /* add/remove port forwarding rules */
|
---|
37 |
|
---|
38 | POLLMGR_SLOT_STATIC_COUNT,
|
---|
39 | POLLMGR_SLOT_FIRST_DYNAMIC = POLLMGR_SLOT_STATIC_COUNT
|
---|
40 | };
|
---|
41 |
|
---|
42 |
|
---|
43 | struct pollmgr_handler; /* forward */
|
---|
44 | typedef int (*pollmgr_callback)(struct pollmgr_handler *, SOCKET, int);
|
---|
45 |
|
---|
46 | struct pollmgr_handler {
|
---|
47 | pollmgr_callback callback;
|
---|
48 | void *data;
|
---|
49 | int slot;
|
---|
50 | };
|
---|
51 |
|
---|
52 | struct pollmgr_refptr {
|
---|
53 | struct pollmgr_handler *ptr;
|
---|
54 | sys_mutex_t lock;
|
---|
55 | size_t strong;
|
---|
56 | size_t weak;
|
---|
57 | };
|
---|
58 |
|
---|
59 | int pollmgr_init(void);
|
---|
60 |
|
---|
61 | /* static named slots (aka "channels") */
|
---|
62 | SOCKET pollmgr_add_chan(int, struct pollmgr_handler *);
|
---|
63 | ssize_t pollmgr_chan_send(int, void *buf, size_t nbytes);
|
---|
64 | void *pollmgr_chan_recv_ptr(struct pollmgr_handler *, SOCKET, int);
|
---|
65 |
|
---|
66 | /* dynamic slots */
|
---|
67 | int pollmgr_add(struct pollmgr_handler *, SOCKET, int);
|
---|
68 |
|
---|
69 | /* special-purpose strong/weak references */
|
---|
70 | struct pollmgr_refptr *pollmgr_refptr_create(struct pollmgr_handler *);
|
---|
71 | void pollmgr_refptr_weak_ref(struct pollmgr_refptr *);
|
---|
72 | struct pollmgr_handler *pollmgr_refptr_get(struct pollmgr_refptr *);
|
---|
73 | void pollmgr_refptr_unref(struct pollmgr_refptr *);
|
---|
74 |
|
---|
75 | void pollmgr_update_events(int, int);
|
---|
76 | void pollmgr_del_slot(int);
|
---|
77 |
|
---|
78 | void pollmgr_thread(void *);
|
---|
79 |
|
---|
80 | /* buffer for callbacks to receive udp without worrying about truncation */
|
---|
81 | extern u8_t pollmgr_udpbuf[64 * 1024];
|
---|
82 |
|
---|
83 | #endif /* _PROXY_POLLMGR_H_ */
|
---|