proxy_pollmgr.h revision 2e848e79ccf2e4285250a0af98ddb9eb28864878
1116N/A/* -*- indent-tabs-mode: nil; -*- */
1116N/A#ifndef _PROXY_POLLMGR_H_
1116N/A#define _PROXY_POLLMGR_H_
1116N/A
1116N/A#ifndef RT_OS_WINDOWS
1116N/A# include <unistd.h> /* for ssize_t */
1116N/A#endif
1116N/A#include "lwip/sys.h"
1116N/A
1116N/Aenum pollmgr_slot_t {
1116N/A POLLMGR_CHAN_PXTCP_ADD, /* new proxy tcp connection from guest */
1116N/A POLLMGR_CHAN_PXTCP_POLLIN, /* free space in ringbuf, may POLLIN */
1116N/A POLLMGR_CHAN_PXTCP_POLLOUT, /* schedule one-shot POLLOUT callback */
1116N/A POLLMGR_CHAN_PXTCP_DEL, /* delete pxtcp */
1116N/A POLLMGR_CHAN_PXTCP_RESET, /* send RST and delete pxtcp */
1116N/A
1116N/A POLLMGR_CHAN_PXUDP_ADD, /* new proxy udp conversation from guest */
1116N/A POLLMGR_CHAN_PXUDP_DEL, /* delete pxudp from pollmgr */
1116N/A
1116N/A POLLMGR_CHAN_PORTFWD, /* add/remove port forwarding rules */
1116N/A
1116N/A POLLMGR_SLOT_STATIC_COUNT,
1116N/A POLLMGR_SLOT_FIRST_DYNAMIC = POLLMGR_SLOT_STATIC_COUNT
1116N/A};
1116N/A
1116N/A
1116N/Astruct pollmgr_handler; /* forward */
1116N/Atypedef int (*pollmgr_callback)(struct pollmgr_handler *, SOCKET, int);
1116N/A
1116N/Astruct pollmgr_handler {
1116N/A pollmgr_callback callback;
1116N/A void *data;
1116N/A int slot;
1116N/A};
1116N/A
1116N/Astruct pollmgr_refptr {
1116N/A struct pollmgr_handler *ptr;
1116N/A sys_mutex_t lock;
1116N/A size_t strong;
1116N/A size_t weak;
1124N/A};
1116N/A
1116N/Aint pollmgr_init(void);
1116N/A
1116N/A/* static named slots (aka "channels") */
1116N/ASOCKET pollmgr_add_chan(int, struct pollmgr_handler *);
1116N/Assize_t pollmgr_chan_send(int, void *buf, size_t nbytes);
1116N/Avoid *pollmgr_chan_recv_ptr(struct pollmgr_handler *, SOCKET, int);
1116N/A
1116N/A/* dynamic slots */
1116N/Aint pollmgr_add(struct pollmgr_handler *, SOCKET, int);
1116N/A
1116N/A/* special-purpose strong/weak references */
1116N/Astruct pollmgr_refptr *pollmgr_refptr_create(struct pollmgr_handler *);
1116N/Avoid pollmgr_refptr_weak_ref(struct pollmgr_refptr *);
1116N/Astruct pollmgr_handler *pollmgr_refptr_get(struct pollmgr_refptr *);
1116N/Avoid pollmgr_refptr_unref(struct pollmgr_refptr *);
1116N/A
1116N/Avoid pollmgr_update_events(int, int);
1116N/Avoid pollmgr_del_slot(int);
1116N/A
1116N/Avoid pollmgr_thread(void *);
1116N/A
1116N/A/* buffer for callbacks to receive udp without worrying about truncation */
1116N/Aextern u8_t pollmgr_udpbuf[64 * 1024];
1116N/A
1116N/A#endif /* _PROXY_POLLMGR_H_ */
1116N/A