mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 17:59:04 +00:00
Replaced internal opaque types by structs.
This commit is contained in:
@@ -84,12 +84,12 @@
|
||||
|
||||
|
||||
/* --- ENGINE INTERFACE PROTOTYPES --- */
|
||||
static int epoll_init(mspool *nsp);
|
||||
static void epoll_destroy(mspool *nsp);
|
||||
static int epoll_iod_register(mspool *nsp, msiod *iod, int ev);
|
||||
static int epoll_iod_unregister(mspool *nsp, msiod *iod);
|
||||
static int epoll_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr);
|
||||
static int epoll_loop(mspool *nsp, int msec_timeout);
|
||||
static int epoll_init(struct npool *nsp);
|
||||
static void epoll_destroy(struct npool *nsp);
|
||||
static int epoll_iod_register(struct npool *nsp, struct niod *iod, int ev);
|
||||
static int epoll_iod_unregister(struct npool *nsp, struct niod *iod);
|
||||
static int epoll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
|
||||
static int epoll_loop(struct npool *nsp, int msec_timeout);
|
||||
|
||||
|
||||
/* ---- ENGINE DEFINITION ---- */
|
||||
@@ -105,20 +105,20 @@ struct io_engine engine_epoll = {
|
||||
|
||||
|
||||
/* --- INTERNAL PROTOTYPES --- */
|
||||
static void iterate_through_event_lists(mspool *nsp, int evcount);
|
||||
static void iterate_through_event_lists(struct npool *nsp, int evcount);
|
||||
|
||||
/* defined in nsock_core.c */
|
||||
void process_iod_events(mspool *nsp, msiod *nsi, int ev);
|
||||
void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev);
|
||||
void process_expired_events(mspool *nsp);
|
||||
void process_iod_events(struct npool *nsp, struct niod *nsi, int ev);
|
||||
void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int ev);
|
||||
void process_expired_events(struct npool *nsp);
|
||||
#if HAVE_PCAP
|
||||
#ifndef PCAP_CAN_DO_SELECT
|
||||
int pcap_read_on_nonselect(mspool *nsp);
|
||||
int pcap_read_on_nonselect(struct npool *nsp);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* defined in nsock_event.c */
|
||||
void update_first_events(msevent *nse);
|
||||
void update_first_events(struct nevent *nse);
|
||||
|
||||
|
||||
extern struct timeval nsock_tod;
|
||||
@@ -137,7 +137,7 @@ struct epoll_engine_info {
|
||||
};
|
||||
|
||||
|
||||
int epoll_init(mspool *nsp) {
|
||||
int epoll_init(struct npool *nsp) {
|
||||
struct epoll_engine_info *einfo;
|
||||
|
||||
einfo = (struct epoll_engine_info *)safe_malloc(sizeof(struct epoll_engine_info));
|
||||
@@ -151,7 +151,7 @@ int epoll_init(mspool *nsp) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void epoll_destroy(mspool *nsp) {
|
||||
void epoll_destroy(struct npool *nsp) {
|
||||
struct epoll_engine_info *einfo = (struct epoll_engine_info *)nsp->engine_data;
|
||||
|
||||
assert(einfo != NULL);
|
||||
@@ -160,7 +160,7 @@ void epoll_destroy(mspool *nsp) {
|
||||
free(einfo);
|
||||
}
|
||||
|
||||
int epoll_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
int epoll_iod_register(struct npool *nsp, struct niod *iod, int ev) {
|
||||
int sd;
|
||||
struct epoll_event epev;
|
||||
struct epoll_engine_info *einfo = (struct epoll_engine_info *)nsp->engine_data;
|
||||
@@ -188,7 +188,7 @@ int epoll_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int epoll_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
int epoll_iod_unregister(struct npool *nsp, struct niod *iod) {
|
||||
iod->watched_events = EV_NONE;
|
||||
|
||||
/* some IODs can be unregistered here if they're associated to an event that was
|
||||
@@ -205,7 +205,7 @@ int epoll_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int epoll_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
int epoll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
|
||||
int sd;
|
||||
struct epoll_event epev;
|
||||
int new_events;
|
||||
@@ -243,7 +243,7 @@ int epoll_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int epoll_loop(mspool *nsp, int msec_timeout) {
|
||||
int epoll_loop(struct npool *nsp, int msec_timeout) {
|
||||
int results_left = 0;
|
||||
int event_msecs; /* msecs before an event goes off */
|
||||
int combined_msecs;
|
||||
@@ -264,7 +264,7 @@ int epoll_loop(mspool *nsp, int msec_timeout) {
|
||||
}
|
||||
|
||||
do {
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
|
||||
nsock_log_debug_all(nsp, "wait for events");
|
||||
|
||||
@@ -339,12 +339,12 @@ static inline int get_evmask(struct epoll_engine_info *einfo, int n) {
|
||||
/* Iterate through all the event lists (such as connect_events, read_events,
|
||||
* timer_events, etc) and take action for those that have completed (due to
|
||||
* timeout, i/o, etc) */
|
||||
void iterate_through_event_lists(mspool *nsp, int evcount) {
|
||||
void iterate_through_event_lists(struct npool *nsp, int evcount) {
|
||||
struct epoll_engine_info *einfo = (struct epoll_engine_info *)nsp->engine_data;
|
||||
int n;
|
||||
|
||||
for (n = 0; n < evcount; n++) {
|
||||
msiod *nsi = (msiod *)einfo->events[n].data.ptr;
|
||||
struct niod *nsi = (struct niod *)einfo->events[n].data.ptr;
|
||||
|
||||
assert(nsi);
|
||||
|
||||
|
||||
@@ -77,12 +77,12 @@
|
||||
|
||||
|
||||
/* --- ENGINE INTERFACE PROTOTYPES --- */
|
||||
static int kqueue_init(mspool *nsp);
|
||||
static void kqueue_destroy(mspool *nsp);
|
||||
static int kqueue_iod_register(mspool *nsp, msiod *iod, int ev);
|
||||
static int kqueue_iod_unregister(mspool *nsp, msiod *iod);
|
||||
static int kqueue_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr);
|
||||
static int kqueue_loop(mspool *nsp, int msec_timeout);
|
||||
static int kqueue_init(struct npool *nsp);
|
||||
static void kqueue_destroy(struct npool *nsp);
|
||||
static int kqueue_iod_register(struct npool *nsp, struct niod *iod, int ev);
|
||||
static int kqueue_iod_unregister(struct npool *nsp, struct niod *iod);
|
||||
static int kqueue_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
|
||||
static int kqueue_loop(struct npool *nsp, int msec_timeout);
|
||||
|
||||
|
||||
/* ---- ENGINE DEFINITION ---- */
|
||||
@@ -98,20 +98,20 @@ struct io_engine engine_kqueue = {
|
||||
|
||||
|
||||
/* --- INTERNAL PROTOTYPES --- */
|
||||
static void iterate_through_event_lists(mspool *nsp, int evcount);
|
||||
static void iterate_through_event_lists(struct npool *nsp, int evcount);
|
||||
|
||||
/* defined in nsock_core.c */
|
||||
void process_iod_events(mspool *nsp, msiod *nsi, int ev);
|
||||
void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev);
|
||||
void process_expired_events(mspool *nsp);
|
||||
void process_iod_events(struct npool *nsp, struct niod *nsi, int ev);
|
||||
void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int ev);
|
||||
void process_expired_events(struct npool *nsp);
|
||||
#if HAVE_PCAP
|
||||
#ifndef PCAP_CAN_DO_SELECT
|
||||
int pcap_read_on_nonselect(mspool *nsp);
|
||||
int pcap_read_on_nonselect(struct npool *nsp);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* defined in nsock_event.c */
|
||||
void update_first_events(msevent *nse);
|
||||
void update_first_events(struct nevent *nse);
|
||||
|
||||
|
||||
extern struct timeval nsock_tod;
|
||||
@@ -128,7 +128,7 @@ struct kqueue_engine_info {
|
||||
};
|
||||
|
||||
|
||||
int kqueue_init(mspool *nsp) {
|
||||
int kqueue_init(struct npool *nsp) {
|
||||
struct kqueue_engine_info *kinfo;
|
||||
|
||||
kinfo = (struct kqueue_engine_info *)safe_malloc(sizeof(struct kqueue_engine_info));
|
||||
@@ -143,7 +143,7 @@ int kqueue_init(mspool *nsp) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void kqueue_destroy(mspool *nsp) {
|
||||
void kqueue_destroy(struct npool *nsp) {
|
||||
struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data;
|
||||
|
||||
assert(kinfo != NULL);
|
||||
@@ -152,7 +152,7 @@ void kqueue_destroy(mspool *nsp) {
|
||||
free(kinfo);
|
||||
}
|
||||
|
||||
int kqueue_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
int kqueue_iod_register(struct npool *nsp, struct niod *iod, int ev) {
|
||||
struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data;
|
||||
|
||||
assert(!IOD_PROPGET(iod, IOD_REGISTERED));
|
||||
@@ -168,7 +168,7 @@ int kqueue_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int kqueue_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
int kqueue_iod_unregister(struct npool *nsp, struct niod *iod) {
|
||||
struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data;
|
||||
|
||||
/* some IODs can be unregistered here if they're associated to an event that was
|
||||
@@ -186,7 +186,7 @@ int kqueue_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
|
||||
#define EV_SETFLAG(_set, _ev) (((_set) & (_ev)) ? (EV_ADD|EV_ENABLE) : (EV_ADD|EV_DISABLE))
|
||||
|
||||
int kqueue_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
int kqueue_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
|
||||
struct kevent kev[2];
|
||||
int new_events, i;
|
||||
struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data;
|
||||
@@ -218,7 +218,7 @@ int kqueue_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int kqueue_loop(mspool *nsp, int msec_timeout) {
|
||||
int kqueue_loop(struct npool *nsp, int msec_timeout) {
|
||||
int results_left = 0;
|
||||
int event_msecs; /* msecs before an event goes off */
|
||||
int combined_msecs;
|
||||
@@ -238,7 +238,7 @@ int kqueue_loop(mspool *nsp, int msec_timeout) {
|
||||
}
|
||||
|
||||
do {
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
|
||||
nsock_log_debug_all(nsp, "wait for events");
|
||||
|
||||
@@ -304,7 +304,7 @@ int kqueue_loop(mspool *nsp, int msec_timeout) {
|
||||
|
||||
/* ---- INTERNAL FUNCTIONS ---- */
|
||||
|
||||
static inline int get_evmask(msiod *nsi, const struct kevent *kev) {
|
||||
static inline int get_evmask(struct niod *nsi, const struct kevent *kev) {
|
||||
int evmask = EV_NONE;
|
||||
|
||||
/* generate the corresponding event mask with nsock event flags */
|
||||
@@ -333,15 +333,15 @@ static inline int get_evmask(msiod *nsi, const struct kevent *kev) {
|
||||
/* Iterate through all the event lists (such as connect_events, read_events,
|
||||
* timer_events, etc) and take action for those that have completed (due to
|
||||
* timeout, i/o, etc) */
|
||||
void iterate_through_event_lists(mspool *nsp, int evcount) {
|
||||
void iterate_through_event_lists(struct npool *nsp, int evcount) {
|
||||
int n;
|
||||
struct kqueue_engine_info *kinfo = (struct kqueue_engine_info *)nsp->engine_data;
|
||||
msiod *nsi;
|
||||
struct niod *nsi;
|
||||
|
||||
for (n = 0; n < evcount; n++) {
|
||||
struct kevent *kev = &kinfo->events[n];
|
||||
|
||||
nsi = (msiod *)kev->udata;
|
||||
nsi = (struct niod *)kev->udata;
|
||||
|
||||
/* process all the pending events for this IOD */
|
||||
process_iod_events(nsp, nsi, get_evmask(nsi, kev));
|
||||
@@ -352,7 +352,7 @@ void iterate_through_event_lists(mspool *nsp, int evcount) {
|
||||
for (n = 0; n < evcount; n++) {
|
||||
struct kevent *kev = &kinfo->events[n];
|
||||
|
||||
nsi = (msiod *)kev->udata;
|
||||
nsi = (struct niod *)kev->udata;
|
||||
|
||||
if (nsi->state == NSIOD_STATE_DELETED) {
|
||||
if (IOD_PROPGET(nsi, IOD_PROCESSED)) {
|
||||
|
||||
@@ -109,12 +109,12 @@
|
||||
|
||||
|
||||
/* --- ENGINE INTERFACE PROTOTYPES --- */
|
||||
static int poll_init(mspool *nsp);
|
||||
static void poll_destroy(mspool *nsp);
|
||||
static int poll_iod_register(mspool *nsp, msiod *iod, int ev);
|
||||
static int poll_iod_unregister(mspool *nsp, msiod *iod);
|
||||
static int poll_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr);
|
||||
static int poll_loop(mspool *nsp, int msec_timeout);
|
||||
static int poll_init(struct npool *nsp);
|
||||
static void poll_destroy(struct npool *nsp);
|
||||
static int poll_iod_register(struct npool *nsp, struct niod *iod, int ev);
|
||||
static int poll_iod_unregister(struct npool *nsp, struct niod *iod);
|
||||
static int poll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
|
||||
static int poll_loop(struct npool *nsp, int msec_timeout);
|
||||
|
||||
|
||||
/* ---- ENGINE DEFINITION ---- */
|
||||
@@ -130,20 +130,20 @@ struct io_engine engine_poll = {
|
||||
|
||||
|
||||
/* --- INTERNAL PROTOTYPES --- */
|
||||
static void iterate_through_event_lists(mspool *nsp);
|
||||
static void iterate_through_event_lists(struct npool *nsp);
|
||||
|
||||
/* defined in nsock_core.c */
|
||||
void process_iod_events(mspool *nsp, msiod *nsi, int ev);
|
||||
void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev);
|
||||
void process_expired_events(mspool *nsp);
|
||||
void process_iod_events(struct npool *nsp, struct niod *nsi, int ev);
|
||||
void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int ev);
|
||||
void process_expired_events(struct npool *nsp);
|
||||
#if HAVE_PCAP
|
||||
#ifndef PCAP_CAN_DO_SELECT
|
||||
int pcap_read_on_nonselect(mspool *nsp);
|
||||
int pcap_read_on_nonselect(struct npool *nsp);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* defined in nsock_event.c */
|
||||
void update_first_events(msevent *nse);
|
||||
void update_first_events(struct nevent *nse);
|
||||
|
||||
|
||||
extern struct timeval nsock_tod;
|
||||
@@ -192,7 +192,7 @@ static inline int evlist_grow(struct poll_engine_info *pinfo) {
|
||||
}
|
||||
|
||||
|
||||
int poll_init(mspool *nsp) {
|
||||
int poll_init(struct npool *nsp) {
|
||||
struct poll_engine_info *pinfo;
|
||||
|
||||
pinfo = (struct poll_engine_info *)safe_malloc(sizeof(struct poll_engine_info));
|
||||
@@ -205,7 +205,7 @@ int poll_init(mspool *nsp) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void poll_destroy(mspool *nsp) {
|
||||
void poll_destroy(struct npool *nsp) {
|
||||
struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data;
|
||||
|
||||
assert(pinfo != NULL);
|
||||
@@ -213,7 +213,7 @@ void poll_destroy(mspool *nsp) {
|
||||
free(pinfo);
|
||||
}
|
||||
|
||||
int poll_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
int poll_iod_register(struct npool *nsp, struct niod *iod, int ev) {
|
||||
struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data;
|
||||
int sd;
|
||||
|
||||
@@ -244,7 +244,7 @@ int poll_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int poll_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
int poll_iod_unregister(struct npool *nsp, struct niod *iod) {
|
||||
iod->watched_events = EV_NONE;
|
||||
|
||||
/* some IODs can be unregistered here if they're associated to an event that was
|
||||
@@ -266,7 +266,7 @@ int poll_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int poll_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
int poll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
|
||||
int sd;
|
||||
int new_events;
|
||||
struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data;
|
||||
@@ -301,7 +301,7 @@ int poll_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int poll_loop(mspool *nsp, int msec_timeout) {
|
||||
int poll_loop(struct npool *nsp, int msec_timeout) {
|
||||
int results_left = 0;
|
||||
int event_msecs; /* msecs before an event goes off */
|
||||
int combined_msecs;
|
||||
@@ -314,7 +314,7 @@ int poll_loop(mspool *nsp, int msec_timeout) {
|
||||
return 0; /* No need to wait on 0 events ... */
|
||||
|
||||
do {
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
|
||||
nsock_log_debug_all(nsp, "wait for events");
|
||||
|
||||
@@ -374,7 +374,7 @@ int poll_loop(mspool *nsp, int msec_timeout) {
|
||||
|
||||
/* ---- INTERNAL FUNCTIONS ---- */
|
||||
|
||||
static inline int get_evmask(mspool *nsp, msiod *nsi) {
|
||||
static inline int get_evmask(struct npool *nsp, struct niod *nsi) {
|
||||
struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data;
|
||||
int sd, evmask = EV_NONE;
|
||||
POLLFD *pev;
|
||||
@@ -406,7 +406,7 @@ static inline int get_evmask(mspool *nsp, msiod *nsi) {
|
||||
/* Iterate through all the event lists (such as connect_events, read_events,
|
||||
* timer_events, etc) and take action for those that have completed (due to
|
||||
* timeout, i/o, etc) */
|
||||
void iterate_through_event_lists(mspool *nsp) {
|
||||
void iterate_through_event_lists(struct npool *nsp) {
|
||||
gh_lnode_t *current, *next, *last;
|
||||
|
||||
last = gh_list_last_elem(&nsp->active_iods);
|
||||
@@ -414,7 +414,7 @@ void iterate_through_event_lists(mspool *nsp) {
|
||||
for (current = gh_list_first_elem(&nsp->active_iods);
|
||||
current != NULL && gh_lnode_prev(current) != last;
|
||||
current = next) {
|
||||
msiod *nsi = container_of(current, msiod, nodeq);
|
||||
struct niod *nsi = container_of(current, struct niod, nodeq);
|
||||
|
||||
process_iod_events(nsp, nsi, get_evmask(nsp, nsi));
|
||||
|
||||
|
||||
@@ -70,12 +70,12 @@
|
||||
|
||||
|
||||
/* --- ENGINE INTERFACE PROTOTYPES --- */
|
||||
static int select_init(mspool *nsp);
|
||||
static void select_destroy(mspool *nsp);
|
||||
static int select_iod_register(mspool *nsp, msiod *iod, int ev);
|
||||
static int select_iod_unregister(mspool *nsp, msiod *iod);
|
||||
static int select_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr);
|
||||
static int select_loop(mspool *nsp, int msec_timeout);
|
||||
static int select_init(struct npool *nsp);
|
||||
static void select_destroy(struct npool *nsp);
|
||||
static int select_iod_register(struct npool *nsp, struct niod *iod, int ev);
|
||||
static int select_iod_unregister(struct npool *nsp, struct niod *iod);
|
||||
static int select_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
|
||||
static int select_loop(struct npool *nsp, int msec_timeout);
|
||||
|
||||
|
||||
/* ---- ENGINE DEFINITION ---- */
|
||||
@@ -91,21 +91,21 @@ struct io_engine engine_select = {
|
||||
|
||||
|
||||
/* --- INTERNAL PROTOTYPES --- */
|
||||
static void iterate_through_event_lists(mspool *nsp);
|
||||
static void iterate_through_event_lists(struct npool *nsp);
|
||||
|
||||
/* defined in nsock_core.c */
|
||||
void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev);
|
||||
void process_iod_events(mspool *nsp, msiod *nsi, int ev);
|
||||
void process_expired_events(mspool *nsp);
|
||||
void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int ev);
|
||||
void process_iod_events(struct npool *nsp, struct niod *nsi, int ev);
|
||||
void process_expired_events(struct npool *nsp);
|
||||
|
||||
#if HAVE_PCAP
|
||||
#ifndef PCAP_CAN_DO_SELECT
|
||||
int pcap_read_on_nonselect(mspool *nsp);
|
||||
int pcap_read_on_nonselect(struct npool *nsp);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* defined in nsock_event.c */
|
||||
void update_first_events(msevent *nse);
|
||||
void update_first_events(struct nevent *nse);
|
||||
|
||||
|
||||
extern struct timeval nsock_tod;
|
||||
@@ -133,7 +133,7 @@ struct select_engine_info {
|
||||
};
|
||||
|
||||
|
||||
int select_init(mspool *nsp) {
|
||||
int select_init(struct npool *nsp) {
|
||||
struct select_engine_info *sinfo;
|
||||
|
||||
sinfo = (struct select_engine_info *)safe_malloc(sizeof(struct select_engine_info));
|
||||
@@ -149,12 +149,12 @@ int select_init(mspool *nsp) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void select_destroy(mspool *nsp) {
|
||||
void select_destroy(struct npool *nsp) {
|
||||
assert(nsp->engine_data != NULL);
|
||||
free(nsp->engine_data);
|
||||
}
|
||||
|
||||
int select_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
int select_iod_register(struct npool *nsp, struct niod *iod, int ev) {
|
||||
assert(!IOD_PROPGET(iod, IOD_REGISTERED));
|
||||
|
||||
iod->watched_events = ev;
|
||||
@@ -163,7 +163,7 @@ int select_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int select_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
int select_iod_unregister(struct npool *nsp, struct niod *iod) {
|
||||
struct select_engine_info *sinfo = (struct select_engine_info *)nsp->engine_data;
|
||||
|
||||
iod->watched_events = EV_NONE;
|
||||
@@ -197,7 +197,7 @@ int select_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int select_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
int select_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
|
||||
int sd;
|
||||
struct select_engine_info *sinfo = (struct select_engine_info *)nsp->engine_data;
|
||||
|
||||
@@ -238,7 +238,7 @@ int select_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int select_loop(mspool *nsp, int msec_timeout) {
|
||||
int select_loop(struct npool *nsp, int msec_timeout) {
|
||||
int results_left = 0;
|
||||
int event_msecs; /* msecs before an event goes off */
|
||||
int combined_msecs;
|
||||
@@ -253,7 +253,7 @@ int select_loop(mspool *nsp, int msec_timeout) {
|
||||
return 0; /* No need to wait on 0 events ... */
|
||||
|
||||
do {
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
|
||||
nsock_log_debug_all(nsp, "wait for events");
|
||||
|
||||
@@ -330,7 +330,7 @@ int select_loop(mspool *nsp, int msec_timeout) {
|
||||
|
||||
/* ---- INTERNAL FUNCTIONS ---- */
|
||||
|
||||
static inline int get_evmask(const mspool *nsp, const msiod *nsi) {
|
||||
static inline int get_evmask(const struct npool *nsp, const struct niod *nsi) {
|
||||
struct select_engine_info *sinfo = (struct select_engine_info *)nsp->engine_data;
|
||||
int sd, evmask;
|
||||
|
||||
@@ -369,7 +369,7 @@ static inline int get_evmask(const mspool *nsp, const msiod *nsi) {
|
||||
/* Iterate through all the event lists (such as connect_events, read_events,
|
||||
* timer_events, etc) and take action for those that have completed (due to
|
||||
* timeout, i/o, etc) */
|
||||
void iterate_through_event_lists(mspool *nsp) {
|
||||
void iterate_through_event_lists(struct npool *nsp) {
|
||||
gh_lnode_t *current, *next, *last;
|
||||
|
||||
last = gh_list_last_elem(&nsp->active_iods);
|
||||
@@ -377,7 +377,7 @@ void iterate_through_event_lists(mspool *nsp) {
|
||||
for (current = gh_list_first_elem(&nsp->active_iods);
|
||||
current != NULL && gh_lnode_prev(current) != last;
|
||||
current = next) {
|
||||
msiod *nsi = container_of(current, msiod, nodeq);
|
||||
struct niod *nsi = container_of(current, struct niod, nodeq);
|
||||
|
||||
if (nsi->state != NSIOD_STATE_DELETED && nsi->events_pending)
|
||||
process_iod_events(nsp, nsi, get_evmask(nsp, nsi));
|
||||
|
||||
@@ -185,7 +185,7 @@ static char *get_addr_string(const struct sockaddr_storage *ss, size_t sslen) {
|
||||
* In case we have support for UNIX domain sockets, function returns
|
||||
* string containing path to UNIX socket if the address family is AF_UNIX,
|
||||
* otherwise it returns string containing "<address>:<port>". */
|
||||
char *get_peeraddr_string(const msiod *iod) {
|
||||
char *get_peeraddr_string(const struct niod *iod) {
|
||||
if (iod->peerlen > 0)
|
||||
return get_addr_string(&iod->peer, iod->peerlen);
|
||||
else
|
||||
@@ -193,6 +193,6 @@ char *get_peeraddr_string(const msiod *iod) {
|
||||
}
|
||||
|
||||
/* Get the local bind address string. */
|
||||
char *get_localaddr_string(const msiod *iod) {
|
||||
char *get_localaddr_string(const struct niod *iod) {
|
||||
return get_addr_string(&iod->local, iod->locallen);
|
||||
}
|
||||
|
||||
@@ -92,10 +92,10 @@ const char *get_unixsock_path(const struct sockaddr_storage *addr);
|
||||
/* Get the peer address string. In case of a Unix domain socket, returns the
|
||||
* path to UNIX socket, otherwise it returns string containing
|
||||
* "<address>:<port>". */
|
||||
char *get_peeraddr_string(const msiod *iod);
|
||||
char *get_peeraddr_string(const struct niod *iod);
|
||||
|
||||
/* Get the local bind address string. */
|
||||
char *get_localaddr_string(const msiod *iod);
|
||||
char *get_localaddr_string(const struct niod *iod);
|
||||
|
||||
#endif /* NETUTILS_H */
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static int mksock_bind_addr(mspool *ms, msiod *iod) {
|
||||
static int mksock_bind_addr(struct npool *ms, struct niod *iod) {
|
||||
int rc;
|
||||
int one = 1;
|
||||
|
||||
@@ -90,7 +90,7 @@ static int mksock_bind_addr(mspool *ms, msiod *iod) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mksock_set_ipopts(mspool *ms, msiod *iod) {
|
||||
static int mksock_set_ipopts(struct npool *ms, struct niod *iod) {
|
||||
int rc;
|
||||
|
||||
errno = 0;
|
||||
@@ -105,7 +105,7 @@ static int mksock_set_ipopts(mspool *ms, msiod *iod) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mksock_bind_device(mspool *ms, msiod *iod) {
|
||||
static int mksock_bind_device(struct npool *ms, struct niod *iod) {
|
||||
int rc;
|
||||
|
||||
rc = socket_bindtodevice(iod->sd, ms->device);
|
||||
@@ -122,7 +122,7 @@ static int mksock_bind_device(mspool *ms, msiod *iod) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mksock_set_broadcast(mspool *ms, msiod *iod) {
|
||||
static int mksock_set_broadcast(struct npool *ms, struct niod *iod) {
|
||||
int rc;
|
||||
int one = 1;
|
||||
|
||||
@@ -141,7 +141,7 @@ static int mksock_set_broadcast(mspool *ms, msiod *iod) {
|
||||
* broadcast flag. Trying to change these functions after making this call will
|
||||
* not have an effect. This function needs to be called before you try to read
|
||||
* or write on the iod. */
|
||||
static int nsock_make_socket(mspool *ms, msiod *iod, int family, int type, int proto) {
|
||||
static int nsock_make_socket(struct npool *ms, struct niod *iod, int family, int type, int proto) {
|
||||
|
||||
/* inheritable_socket is from nbase */
|
||||
iod->sd = (int)inheritable_socket(family, type, proto);
|
||||
@@ -172,8 +172,8 @@ static int nsock_make_socket(mspool *ms, msiod *iod, int family, int type, int p
|
||||
}
|
||||
|
||||
int nsock_setup_udp(nsock_pool nsp, nsock_iod ms_iod, int af) {
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
|
||||
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||
|
||||
@@ -187,14 +187,14 @@ int nsock_setup_udp(nsock_pool nsp, nsock_iod ms_iod, int af) {
|
||||
|
||||
/* This does the actual logistics of requesting a TCP connection. It is shared
|
||||
* by nsock_connect_tcp and nsock_connect_ssl */
|
||||
void nsock_connect_internal(mspool *ms, msevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen,
|
||||
void nsock_connect_internal(struct npool *ms, struct nevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen,
|
||||
unsigned short port) {
|
||||
|
||||
struct sockaddr_in *sin;
|
||||
#if HAVE_IPV6
|
||||
struct sockaddr_in6 *sin6;
|
||||
#endif
|
||||
msiod *iod = nse->iod;
|
||||
struct niod *iod = nse->iod;
|
||||
|
||||
if (iod->px_ctx /* proxy enabled */
|
||||
&& proto == IPPROTO_TCP /* restrict proxying to TCP connections */
|
||||
@@ -275,14 +275,14 @@ void nsock_connect_internal(mspool *ms, msevent *nse, int type, int proto, struc
|
||||
* connect). sslen should be the sizeof the structure you are passing in. */
|
||||
nsock_event_id nsock_connect_unixsock_stream(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, struct sockaddr *saddr, size_t sslen) {
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||
|
||||
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "UNIX domain socket (STREAM) connection requested to %s (IOD #%li) EID %li",
|
||||
@@ -301,14 +301,14 @@ nsock_event_id nsock_connect_unixsock_stream(nsock_pool nsp, nsock_iod nsiod, ns
|
||||
* connect). sslen should be the sizeof the structure you are passing in. */
|
||||
nsock_event_id nsock_connect_unixsock_datagram(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handler handler,
|
||||
void *userdata, struct sockaddr *saddr, size_t sslen) {
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||
|
||||
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_CONNECT, nsi, -1, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, -1, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "UNIX domain socket (DGRAM) connection requested to %s (IOD #%li) EID %li",
|
||||
@@ -329,14 +329,14 @@ nsock_event_id nsock_connect_unixsock_datagram(nsock_pool nsp, nsock_iod nsiod,
|
||||
* sizeof the structure you are passing in. */
|
||||
nsock_event_id nsock_connect_tcp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, struct sockaddr *saddr, size_t sslen, unsigned short port) {
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||
|
||||
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "TCP connection requested to %s:%hu (IOD #%li) EID %li",
|
||||
@@ -357,14 +357,14 @@ nsock_event_id nsock_connect_tcp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_hand
|
||||
nsock_event_id nsock_connect_sctp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, struct sockaddr *saddr, size_t sslen, unsigned short port) {
|
||||
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||
|
||||
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "SCTP association requested to %s:%hu (IOD #%li) EID %li",
|
||||
@@ -393,16 +393,16 @@ nsock_event_id nsock_connect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
|
||||
return (nsock_event_id)0; /* UNREACHED */
|
||||
#else
|
||||
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
|
||||
if (!ms->sslctx)
|
||||
nsp_ssl_init(ms);
|
||||
|
||||
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_CONNECT_SSL, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_CONNECT_SSL, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
/* Set our SSL_SESSION so we can benefit from session-id reuse. */
|
||||
@@ -431,14 +431,14 @@ nsock_event_id nsock_reconnect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_han
|
||||
fatal("nsock_reconnect_ssl called - but nsock was built w/o SSL support. QUITTING");
|
||||
return (nsock_event_id) 0; /* UNREACHED */
|
||||
#else
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
|
||||
if (!ms->sslctx)
|
||||
nsp_ssl_init(ms);
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_CONNECT_SSL, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_CONNECT_SSL, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
/* Set our SSL_SESSION so we can benefit from session-id reuse. */
|
||||
@@ -473,14 +473,14 @@ nsock_event_id nsock_reconnect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_han
|
||||
nsock_event_id nsock_connect_udp(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handler handler, void *userdata,
|
||||
struct sockaddr *saddr, size_t sslen, unsigned short port) {
|
||||
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||
|
||||
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_CONNECT, nsi, -1, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_CONNECT, nsi, -1, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "UDP connection requested to %s:%hu (IOD #%li) EID %li",
|
||||
@@ -506,7 +506,7 @@ nsock_event_id nsock_connect_udp(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
|
||||
* sizeof(sockaddr_storage) if that is what you are passing). */
|
||||
int nsi_getlastcommunicationinfo(nsock_iod ms_iod, int *protocol, int *af, struct sockaddr *local,
|
||||
struct sockaddr *remote, size_t socklen) {
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
int ret = 1;
|
||||
struct sockaddr_storage sock;
|
||||
socklen_t slen = sizeof(struct sockaddr_storage);
|
||||
|
||||
@@ -95,7 +95,7 @@ struct timeval nsock_tod;
|
||||
|
||||
/* Internal function defined in nsock_event.c
|
||||
* Update the nse->iod first events, assuming nse is about to be deleted */
|
||||
void update_first_events(msevent *nse);
|
||||
void update_first_events(struct nevent *nse);
|
||||
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ void update_first_events(msevent *nse);
|
||||
* cleared after the first is completed.
|
||||
* The socket_count_* functions return the event to transmit to update_events()
|
||||
*/
|
||||
int socket_count_zero(msiod *iod, mspool *ms) {
|
||||
int socket_count_zero(struct niod *iod, struct npool *ms) {
|
||||
iod->readsd_count = 0;
|
||||
iod->writesd_count = 0;
|
||||
#if HAVE_PCAP
|
||||
@@ -117,38 +117,38 @@ int socket_count_zero(msiod *iod, mspool *ms) {
|
||||
return nsock_engine_iod_unregister(ms, iod);
|
||||
}
|
||||
|
||||
static int socket_count_read_inc(msiod *iod) {
|
||||
static int socket_count_read_inc(struct niod *iod) {
|
||||
assert(iod->readsd_count >= 0);
|
||||
iod->readsd_count++;
|
||||
return EV_READ;
|
||||
}
|
||||
|
||||
static int socket_count_read_dec(msiod *iod) {
|
||||
static int socket_count_read_dec(struct niod *iod) {
|
||||
assert(iod->readsd_count > 0);
|
||||
iod->readsd_count--;
|
||||
return (iod->readsd_count == 0) ? EV_READ : EV_NONE;
|
||||
}
|
||||
|
||||
static int socket_count_write_inc(msiod *iod) {
|
||||
static int socket_count_write_inc(struct niod *iod) {
|
||||
assert(iod->writesd_count >= 0);
|
||||
iod->writesd_count++;
|
||||
return EV_WRITE;
|
||||
}
|
||||
|
||||
static int socket_count_write_dec(msiod *iod) {
|
||||
static int socket_count_write_dec(struct niod *iod) {
|
||||
assert(iod->writesd_count > 0);
|
||||
iod->writesd_count--;
|
||||
return (iod->writesd_count == 0) ? EV_WRITE : EV_NONE;
|
||||
}
|
||||
|
||||
#if HAVE_PCAP
|
||||
static int socket_count_readpcap_inc(msiod *iod) {
|
||||
static int socket_count_readpcap_inc(struct niod *iod) {
|
||||
assert(iod->readpcapsd_count >= 0);
|
||||
iod->readpcapsd_count++;
|
||||
return EV_READ;
|
||||
}
|
||||
|
||||
static int socket_count_readpcap_dec(msiod *iod) {
|
||||
static int socket_count_readpcap_dec(struct niod *iod) {
|
||||
assert(iod->readpcapsd_count > 0);
|
||||
iod->readpcapsd_count--;
|
||||
return (iod->readpcapsd_count == 0) ? EV_READ : EV_NONE;
|
||||
@@ -158,7 +158,7 @@ static int socket_count_readpcap_dec(msiod *iod) {
|
||||
#if HAVE_OPENSSL
|
||||
/* Call socket_count_read_dec or socket_count_write_dec on nse->iod depending on
|
||||
* the current value of nse->sslinfo.ssl_desire. */
|
||||
static int socket_count_dec_ssl_desire(msevent *nse) {
|
||||
static int socket_count_dec_ssl_desire(struct nevent *nse) {
|
||||
assert(nse->iod->ssl != NULL);
|
||||
assert(nse->sslinfo.ssl_desire == SSL_ERROR_WANT_READ ||
|
||||
nse->sslinfo.ssl_desire == SSL_ERROR_WANT_WRITE);
|
||||
@@ -179,7 +179,7 @@ static int socket_count_dec_ssl_desire(msevent *nse) {
|
||||
* If this counter reaches zero, the event won't be watched anymore by the
|
||||
* IO engine for this IOD.
|
||||
*/
|
||||
static void update_events(msiod * iod, mspool *ms, int ev_inc, int ev_dec) {
|
||||
static void update_events(struct niod * iod, struct npool *ms, int ev_inc, int ev_dec) {
|
||||
int setmask, clrmask, ev_temp;
|
||||
|
||||
/* Filter out events that belong to both sets. */
|
||||
@@ -211,7 +211,7 @@ static void update_events(msiod * iod, mspool *ms, int ev_inc, int ev_dec) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a new event for a given IOD. msevents are stored in separate event lists
|
||||
/* Add a new event for a given IOD. nevents are stored in separate event lists
|
||||
* (in the nsock pool) and are grouped by IOD within each list.
|
||||
*
|
||||
* This function appends the event _before_ the first similar event we have for
|
||||
@@ -222,8 +222,8 @@ static void update_events(msiod * iod, mspool *ms, int ev_inc, int ev_dec) {
|
||||
* reentrancy, as it will prevent the new event to be processed in the event
|
||||
* loop just after its addition.
|
||||
*/
|
||||
static int iod_add_event(msiod *iod, msevent *nse) {
|
||||
mspool *nsp = iod->nsp;
|
||||
static int iod_add_event(struct niod *iod, struct nevent *nse) {
|
||||
struct npool *nsp = iod->nsp;
|
||||
|
||||
switch (nse->type) {
|
||||
case NSE_TYPE_CONNECT:
|
||||
@@ -302,7 +302,7 @@ static int iod_add_event(msiod *iod, msevent *nse) {
|
||||
* case of more information or an event timeout */
|
||||
|
||||
/* The event type handlers -- the first three arguments of each are the same:
|
||||
* mspool *ms msevent *nse -- the event we have new info on enum nse_status --
|
||||
* struct npool *ms struct nevent *nse -- the event we have new info on enum nse_status --
|
||||
* The reason for the call, usually NSE_STATUS_SUCCESS (which generally means a
|
||||
* successful I/O call or NSE_STATUS_TIMEOUT or NSE_STATUS_CANCELLED
|
||||
*
|
||||
@@ -319,10 +319,10 @@ static int iod_add_event(msiod *iod, msevent *nse) {
|
||||
|
||||
/* handle_connect_results assumes that select or poll have already shown the
|
||||
* descriptor to be active */
|
||||
void handle_connect_result(mspool *ms, msevent *nse, enum nse_status status) {
|
||||
void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status status) {
|
||||
int optval;
|
||||
socklen_t optlen = sizeof(int);
|
||||
msiod *iod = nse->iod;
|
||||
struct niod *iod = nse->iod;
|
||||
#if HAVE_OPENSSL
|
||||
int sslerr;
|
||||
int rc = 0;
|
||||
@@ -519,12 +519,12 @@ static int errcode_is_failure(int err) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void handle_write_result(mspool *ms, msevent *nse, enum nse_status status) {
|
||||
void handle_write_result(struct npool *ms, struct nevent *nse, enum nse_status status) {
|
||||
int bytesleft;
|
||||
char *str;
|
||||
int res;
|
||||
int err;
|
||||
msiod *iod = nse->iod;
|
||||
struct niod *iod = nse->iod;
|
||||
|
||||
if (status == NSE_STATUS_TIMEOUT || status == NSE_STATUS_CANCELLED) {
|
||||
nse->event_done = 1;
|
||||
@@ -601,17 +601,17 @@ void handle_write_result(mspool *ms, msevent *nse, enum nse_status status) {
|
||||
}
|
||||
}
|
||||
|
||||
void handle_timer_result(mspool *ms, msevent *nse, enum nse_status status) {
|
||||
void handle_timer_result(struct npool *ms, struct nevent *nse, enum nse_status status) {
|
||||
/* Ooh this is a hard job :) */
|
||||
nse->event_done = 1;
|
||||
nse->status = status;
|
||||
}
|
||||
|
||||
/* Returns -1 if an error, otherwise the number of newly written bytes */
|
||||
static int do_actual_read(mspool *ms, msevent *nse) {
|
||||
static int do_actual_read(struct npool *ms, struct nevent *nse) {
|
||||
char buf[8192];
|
||||
int buflen = 0;
|
||||
msiod *iod = nse->iod;
|
||||
struct niod *iod = nse->iod;
|
||||
int err = 0;
|
||||
int max_chunk = NSOCK_READ_CHUNK_SIZE;
|
||||
int startlen = fs_length(&nse->iobuf);
|
||||
@@ -742,11 +742,11 @@ static int do_actual_read(mspool *ms, msevent *nse) {
|
||||
}
|
||||
|
||||
|
||||
void handle_read_result(mspool *ms, msevent *nse, enum nse_status status) {
|
||||
void handle_read_result(struct npool *ms, struct nevent *nse, enum nse_status status) {
|
||||
unsigned int count;
|
||||
char *str;
|
||||
int rc, len;
|
||||
msiod *iod = nse->iod;
|
||||
struct niod *iod = nse->iod;
|
||||
|
||||
if (status == NSE_STATUS_TIMEOUT) {
|
||||
nse->event_done = 1;
|
||||
@@ -817,8 +817,8 @@ void handle_read_result(mspool *ms, msevent *nse, enum nse_status status) {
|
||||
}
|
||||
|
||||
#if HAVE_PCAP
|
||||
void handle_pcap_read_result(mspool *ms, msevent *nse, enum nse_status status) {
|
||||
msiod *iod = nse->iod;
|
||||
void handle_pcap_read_result(struct npool *ms, struct nevent *nse, enum nse_status status) {
|
||||
struct niod *iod = nse->iod;
|
||||
mspcap *mp = (mspcap *)iod->pcap;
|
||||
|
||||
switch (status) {
|
||||
@@ -858,15 +858,15 @@ void handle_pcap_read_result(mspool *ms, msevent *nse, enum nse_status status) {
|
||||
}
|
||||
|
||||
/* Returns whether something was read */
|
||||
int pcap_read_on_nonselect(mspool *nsp) {
|
||||
int pcap_read_on_nonselect(struct npool *nsp) {
|
||||
gh_lnode_t *current, *next;
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
int ret = 0;
|
||||
|
||||
for (current = gh_list_first_elem(&nsp->pcap_read_events);
|
||||
current != NULL;
|
||||
current = next) {
|
||||
nse = lnode_msevent2(current);
|
||||
nse = lnode_nevent2(current);
|
||||
if (do_actual_pcap_read(nse) == 1) {
|
||||
/* something received */
|
||||
ret++;
|
||||
@@ -887,7 +887,7 @@ int pcap_read_on_nonselect(mspool *nsp) {
|
||||
* For example you could do a series of 15 second runs, allowing you to do other
|
||||
* stuff between them */
|
||||
enum nsock_loopstatus nsock_loop(nsock_pool nsp, int msec_timeout) {
|
||||
mspool *ms = (mspool *)nsp;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct timeval loop_timeout;
|
||||
int msecs_left;
|
||||
unsigned long loopnum = 0;
|
||||
@@ -945,7 +945,7 @@ enum nsock_loopstatus nsock_loop(nsock_pool nsp, int msec_timeout) {
|
||||
return quitstatus;
|
||||
}
|
||||
|
||||
void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev) {
|
||||
void process_event(struct npool *nsp, gh_list_t *evlist, struct nevent *nse, int ev) {
|
||||
int match_r = 0, match_w = 0;
|
||||
#if HAVE_OPENSSL
|
||||
int desire_r = 0, desire_w = 0;
|
||||
@@ -962,7 +962,7 @@ void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev) {
|
||||
case NSE_TYPE_CONNECT_SSL:
|
||||
if (ev != EV_NONE)
|
||||
handle_connect_result(nsp, nse, NSE_STATUS_SUCCESS);
|
||||
if (msevent_timedout(nse))
|
||||
if (event_timedout(nse))
|
||||
handle_connect_result(nsp, nse, NSE_STATUS_TIMEOUT);
|
||||
break;
|
||||
|
||||
@@ -979,7 +979,7 @@ void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev) {
|
||||
if (!nse->iod->ssl && match_r)
|
||||
handle_read_result(nsp, nse, NSE_STATUS_SUCCESS);
|
||||
|
||||
if (msevent_timedout(nse))
|
||||
if (event_timedout(nse))
|
||||
handle_read_result(nsp, nse, NSE_STATUS_TIMEOUT);
|
||||
break;
|
||||
|
||||
@@ -996,12 +996,12 @@ void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev) {
|
||||
if (!nse->iod->ssl && match_w)
|
||||
handle_write_result(nsp, nse, NSE_STATUS_SUCCESS);
|
||||
|
||||
if (msevent_timedout(nse))
|
||||
if (event_timedout(nse))
|
||||
handle_write_result(nsp, nse, NSE_STATUS_TIMEOUT);
|
||||
break;
|
||||
|
||||
case NSE_TYPE_TIMER:
|
||||
if (msevent_timedout(nse))
|
||||
if (event_timedout(nse))
|
||||
handle_timer_result(nsp, nse, NSE_STATUS_SUCCESS);
|
||||
break;
|
||||
|
||||
@@ -1019,7 +1019,7 @@ void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev) {
|
||||
if (fs_length(&(nse->iobuf)) > 0)
|
||||
handle_pcap_read_result(nsp, nse, NSE_STATUS_SUCCESS);
|
||||
|
||||
if (msevent_timedout(nse))
|
||||
if (event_timedout(nse))
|
||||
handle_pcap_read_result(nsp, nse, NSE_STATUS_TIMEOUT);
|
||||
|
||||
#if PCAP_BSD_SELECT_HACK
|
||||
@@ -1065,11 +1065,11 @@ void process_event(mspool *nsp, gh_list_t *evlist, msevent *nse, int ev) {
|
||||
nsock_log_debug_all(nsp, "NSE #%lu: Sending event", nse->id);
|
||||
|
||||
/* WooHoo! The event is ready to be sent */
|
||||
msevent_dispatch_and_delete(nsp, nse, 1);
|
||||
event_dispatch_and_delete(nsp, nse, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void process_iod_events(mspool *nsp, msiod *nsi, int ev) {
|
||||
void process_iod_events(struct npool *nsp, struct niod *nsi, int ev) {
|
||||
int i = 0;
|
||||
/* store addresses of the pointers to the first elements of each kind instead
|
||||
* of storing the values, as a connect can add a read for instance */
|
||||
@@ -1116,14 +1116,14 @@ void process_iod_events(mspool *nsp, msiod *nsi, int ev) {
|
||||
for (current = *start_elems[i];
|
||||
current != NULL && gh_lnode_prev(current) != last;
|
||||
current = next) {
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
|
||||
#if HAVE_PCAP
|
||||
if (evlists[i] == &nsi->nsp->pcap_read_events)
|
||||
nse = lnode_msevent2(current);
|
||||
nse = lnode_nevent2(current);
|
||||
else
|
||||
#endif
|
||||
nse = lnode_msevent(current);
|
||||
nse = lnode_nevent(current);
|
||||
|
||||
/* events are grouped by IOD. Break if we're done with the events for the
|
||||
* current IOD */
|
||||
@@ -1147,7 +1147,7 @@ void process_iod_events(mspool *nsp, msiod *nsi, int ev) {
|
||||
}
|
||||
}
|
||||
|
||||
static int msevent_unref(mspool *nsp, msevent *nse) {
|
||||
static int nevent_unref(struct npool *nsp, struct nevent *nse) {
|
||||
switch (nse->type) {
|
||||
case NSE_TYPE_CONNECT:
|
||||
case NSE_TYPE_CONNECT_SSL:
|
||||
@@ -1196,31 +1196,31 @@ static int msevent_unref(mspool *nsp, msevent *nse) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void process_expired_events(mspool *nsp) {
|
||||
void process_expired_events(struct npool *nsp) {
|
||||
for (;;) {
|
||||
gh_hnode_t *hnode;
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
|
||||
hnode = gh_heap_min(&nsp->expirables);
|
||||
if (!hnode)
|
||||
break;
|
||||
|
||||
nse = container_of(hnode, msevent, expire);
|
||||
if (!msevent_timedout(nse))
|
||||
nse = container_of(hnode, struct nevent, expire);
|
||||
if (!event_timedout(nse))
|
||||
break;
|
||||
|
||||
gh_heap_pop(&nsp->expirables);
|
||||
process_event(nsp, NULL, nse, EV_NONE);
|
||||
assert(nse->event_done);
|
||||
update_first_events(nse);
|
||||
msevent_unref(nsp, nse);
|
||||
nevent_unref(nsp, nse);
|
||||
}
|
||||
}
|
||||
|
||||
/* Calling this function will cause nsock_loop to quit on its next iteration
|
||||
* with a return value of NSOCK_LOOP_QUIT. */
|
||||
void nsock_loop_quit(nsock_pool nsp) {
|
||||
mspool *ms = (mspool *)nsp;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
ms->quit = 1;
|
||||
}
|
||||
|
||||
@@ -1238,7 +1238,7 @@ const struct timeval *nsock_gettimeofday() {
|
||||
/* Adds an event to the appropriate nsp event list, handles housekeeping such as
|
||||
* adjusting the descriptor select/poll lists, registering the timeout value,
|
||||
* etc. */
|
||||
void nsp_add_event(mspool *nsp, msevent *nse) {
|
||||
void nsp_add_event(struct npool *nsp, struct nevent *nse) {
|
||||
nsock_log_debug(nsp, "NSE #%lu: Adding event (timeout in %ldms)",
|
||||
nse->id,
|
||||
(long)TIMEVAL_MSEC_SUBTRACT(nse->timeout, nsock_tod));
|
||||
@@ -1327,8 +1327,8 @@ void nsp_add_event(mspool *nsp, msevent *nse) {
|
||||
|
||||
/* An event has been completed and the handler is about to be called. This
|
||||
* function writes out tracing data about the event if necessary */
|
||||
void nsock_trace_handler_callback(mspool *ms, msevent *nse) {
|
||||
msiod *nsi;
|
||||
void nsock_trace_handler_callback(struct npool *ms, struct nevent *nse) {
|
||||
struct niod *nsi;
|
||||
char *str;
|
||||
int strlength = 0;
|
||||
char displaystr[256];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/***************************************************************************
|
||||
* nsock_event.c -- Functions dealing with nsock_events (and their *
|
||||
* msevent internal representation. An event is created when you do *
|
||||
* struct nevent internal representation. An event is created when you do *
|
||||
* various calls (for reading, writing, connecting, timers, etc) and is *
|
||||
* provided back to you in the callback when the call completes or *
|
||||
* fails. It is automatically destroyed after the callback returns *
|
||||
@@ -73,38 +73,38 @@ extern struct timeval nsock_tod;
|
||||
|
||||
/* Find the type of an event that spawned a callback */
|
||||
enum nse_type nse_type(nsock_event nse) {
|
||||
msevent *me = (msevent *)nse;
|
||||
struct nevent *me = (struct nevent *)nse;
|
||||
return me->type;
|
||||
}
|
||||
|
||||
enum nse_status nse_status(nsock_event nse) {
|
||||
msevent *me = (msevent *)nse;
|
||||
struct nevent *me = (struct nevent *)nse;
|
||||
return me->status;
|
||||
}
|
||||
|
||||
int nse_eof(nsock_event nse) {
|
||||
msevent *me = (msevent *)nse;
|
||||
struct nevent *me = (struct nevent *)nse;
|
||||
return me->eof;
|
||||
}
|
||||
|
||||
/* Obtains the nsock_iod (see below) associated with the event. Note that
|
||||
* some events (such as timers) don't have an nsock_iod associated with them */
|
||||
nsock_iod nse_iod(nsock_event ms_event) {
|
||||
msevent *nse = (msevent *)ms_event;
|
||||
struct nevent *nse = (struct nevent *)ms_event;
|
||||
return (nsock_iod) nse->iod;
|
||||
}
|
||||
|
||||
/* This next function returns the errno style error code -- which is only valid
|
||||
* if the status is NSE_STATUS_ERROR */
|
||||
int nse_errorcode(nsock_event nse) {
|
||||
msevent *me = (msevent *)nse;
|
||||
struct nevent *me = (struct nevent *)nse;
|
||||
return me->errnum;
|
||||
}
|
||||
|
||||
/* Every event has an ID which will be unique throughout the program's execution
|
||||
* unless you use (literally) billions of them */
|
||||
nsock_event_id nse_id(nsock_event nse) {
|
||||
msevent *me = (msevent *)nse;
|
||||
struct nevent *me = (struct nevent *)nse;
|
||||
return me->id;
|
||||
}
|
||||
|
||||
@@ -112,14 +112,14 @@ nsock_event_id nse_id(nsock_event nse) {
|
||||
* provides the buffer that was read in as well as the number of chars read.
|
||||
* The buffer should not be modified or free'd */
|
||||
char *nse_readbuf(nsock_event nse, int *nbytes) {
|
||||
msevent *me = (msevent *)nse;
|
||||
struct nevent *me = (struct nevent *)nse;
|
||||
|
||||
if (nbytes)
|
||||
*nbytes = fs_length(&(me->iobuf));
|
||||
return fs_str(&(me->iobuf));
|
||||
}
|
||||
|
||||
static void first_ev_next(msevent *nse, gh_lnode_t **first, int nodeq2) {
|
||||
static void first_ev_next(struct nevent *nse, gh_lnode_t **first, int nodeq2) {
|
||||
if (!first || !*first)
|
||||
return;
|
||||
|
||||
@@ -128,12 +128,12 @@ static void first_ev_next(msevent *nse, gh_lnode_t **first, int nodeq2) {
|
||||
|
||||
next = gh_lnode_next(*first);
|
||||
if (next) {
|
||||
msevent *newevent;
|
||||
struct nevent *newevent;
|
||||
|
||||
if (nodeq2)
|
||||
newevent = lnode_msevent2(next);
|
||||
newevent = lnode_nevent2(next);
|
||||
else
|
||||
newevent = lnode_msevent(next);
|
||||
newevent = lnode_nevent(next);
|
||||
|
||||
if (newevent->iod == nse->iod)
|
||||
*first = next;
|
||||
@@ -145,7 +145,7 @@ static void first_ev_next(msevent *nse, gh_lnode_t **first, int nodeq2) {
|
||||
}
|
||||
}
|
||||
|
||||
void update_first_events(msevent *nse) {
|
||||
void update_first_events(struct nevent *nse) {
|
||||
switch (get_event_id_type(nse->id)) {
|
||||
case NSE_TYPE_CONNECT:
|
||||
case NSE_TYPE_CONNECT_SSL:
|
||||
@@ -184,12 +184,12 @@ void update_first_events(msevent *nse) {
|
||||
* step. This function returns zero if the event is not found, nonzero
|
||||
* otherwise. */
|
||||
int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) {
|
||||
mspool *nsp = (mspool *)ms_pool;
|
||||
struct npool *nsp = (struct npool *)ms_pool;
|
||||
enum nse_type type;
|
||||
unsigned int i;
|
||||
gh_list_t *event_list = NULL, *event_list2 = NULL;
|
||||
gh_lnode_t *current, *next;
|
||||
msevent *nse = NULL;
|
||||
struct nevent *nse = NULL;
|
||||
|
||||
assert(nsp);
|
||||
|
||||
@@ -216,9 +216,9 @@ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) {
|
||||
gh_hnode_t *hnode;
|
||||
|
||||
hnode = gh_heap_find(&nsp->expirables, i);
|
||||
nse = container_of(hnode, msevent, expire);
|
||||
nse = container_of(hnode, struct nevent, expire);
|
||||
if (nse->id == id)
|
||||
return msevent_cancel(nsp, nse, NULL, NULL, notify);
|
||||
return nevent_delete(nsp, nse, NULL, NULL, notify);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -236,7 +236,7 @@ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) {
|
||||
/* Now we try to find the event in the list */
|
||||
for (current = gh_list_first_elem(event_list); current != NULL; current = next) {
|
||||
next = gh_lnode_next(current);
|
||||
nse = lnode_msevent(current);
|
||||
nse = lnode_nevent(current);
|
||||
if (nse->id == id)
|
||||
break;
|
||||
}
|
||||
@@ -245,7 +245,7 @@ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) {
|
||||
event_list = event_list2;
|
||||
for (current = gh_list_first_elem(event_list); current != NULL; current = next) {
|
||||
next = gh_lnode_next(current);
|
||||
nse = lnode_msevent2(current);
|
||||
nse = lnode_nevent2(current);
|
||||
if (nse->id == id)
|
||||
break;
|
||||
}
|
||||
@@ -253,17 +253,17 @@ int nsock_event_cancel(nsock_pool ms_pool, nsock_event_id id, int notify) {
|
||||
if (current == NULL)
|
||||
return 0;
|
||||
|
||||
return msevent_cancel(nsp, nse, event_list, current, notify);
|
||||
return nevent_delete(nsp, nse, event_list, current, notify);
|
||||
}
|
||||
|
||||
/* An internal function for cancelling an event when you already have a pointer
|
||||
* to the msevent (use nsock_event_cancel if you just have an ID). The
|
||||
* to the struct nevent (use nsock_event_cancel if you just have an ID). The
|
||||
* event_list passed in should correspond to the type of the event. For example,
|
||||
* with NSE_TYPE_READ, you would pass in &nsp->read_events;. elem is the list
|
||||
* element in event_list which holds the event. Pass a nonzero for notify if
|
||||
* you want the program owning the event to be notified that it has been
|
||||
* cancelled */
|
||||
int msevent_cancel(mspool *nsp, msevent *nse, gh_list_t *event_list,
|
||||
int nevent_delete(struct npool *nsp, struct nevent *nse, gh_list_t *event_list,
|
||||
gh_lnode_t *elem, int notify) {
|
||||
if (nse->event_done) {
|
||||
/* This event has already been marked for death somewhere else -- it will be
|
||||
@@ -272,8 +272,8 @@ int msevent_cancel(mspool *nsp, msevent *nse, gh_list_t *event_list,
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsock_log_info(nsp, "msevent_cancel on event #%li (type %s)",
|
||||
nse->id, nse_type2str(nse->type));
|
||||
nsock_log_info(nsp, "%s on event #%li (type %s)", __func__, nse->id,
|
||||
nse_type2str(nse->type));
|
||||
|
||||
/* Now that we found the event... we go through the motions of cleanly
|
||||
* cancelling it */
|
||||
@@ -347,7 +347,7 @@ int msevent_cancel(mspool *nsp, msevent *nse, gh_list_t *event_list,
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
msevent_dispatch_and_delete(nsp, nse, notify);
|
||||
event_dispatch_and_delete(nsp, nse, notify);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -355,7 +355,7 @@ int msevent_cancel(mspool *nsp, msevent *nse, gh_list_t *event_list,
|
||||
* nonzero) and then deletes the event. This function does NOT delete the event
|
||||
* from any lists it might be on (eg nsp->read_list etc.) nse->event_done
|
||||
* MUST be true when you call this */
|
||||
void msevent_dispatch_and_delete(mspool *nsp, msevent *nse, int notify) {
|
||||
void event_dispatch_and_delete(struct npool *nsp, struct nevent *nse, int notify) {
|
||||
assert(nsp);
|
||||
assert(nse);
|
||||
|
||||
@@ -377,7 +377,7 @@ void msevent_dispatch_and_delete(mspool *nsp, msevent *nse, int notify) {
|
||||
/* FIXME: We should be updating stats here ... */
|
||||
|
||||
/* Now we clobber the event ... */
|
||||
msevent_delete(nsp, nse);
|
||||
event_delete(nsp, nse);
|
||||
}
|
||||
|
||||
/* OK -- the idea is that we want the type included in the rightmost two bits
|
||||
@@ -386,7 +386,7 @@ void msevent_dispatch_and_delete(mspool *nsp, msevent *nse, int notify) {
|
||||
* definition of a "correct" wraparound is that it goes from the highest number
|
||||
* back to one (not zero) because we don't want event numbers to ever be zero.
|
||||
* */
|
||||
nsock_event_id get_new_event_id(mspool *ms, enum nse_type type) {
|
||||
nsock_event_id get_new_event_id(struct npool *ms, enum nse_type type) {
|
||||
int type_code = (int)type;
|
||||
unsigned long serial = ms->next_event_serial++;
|
||||
unsigned long max_serial_allowed;
|
||||
@@ -409,31 +409,31 @@ enum nse_type get_event_id_type(nsock_event_id event_id) {
|
||||
return (enum nse_type)((event_id & ((1 << TYPE_CODE_NUM_BITS) - 1)));
|
||||
}
|
||||
|
||||
|
||||
/* Create a new event structure -- must be deleted later with msevent_delete,
|
||||
* unless it returns NULL (failure). NULL can be passed in for the msiod and
|
||||
* the userdata if not available */
|
||||
msevent *msevent_new(mspool *nsp, enum nse_type type, msiod *msiod, int timeout_msecs,
|
||||
/* Create a new event structure -- must be deleted later with event_delete,
|
||||
* unless it returns NULL (failure). NULL can be passed in for the struct niod
|
||||
* and the userdata if not available */
|
||||
struct nevent *event_new(struct npool *nsp, enum nse_type type,
|
||||
struct niod *iod, int timeout_msecs,
|
||||
nsock_ev_handler handler, void *userdata) {
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
gh_lnode_t *lnode;
|
||||
|
||||
/* Bring us up to date for the timeout calculation. */
|
||||
gettimeofday(&nsock_tod, NULL);
|
||||
|
||||
if (msiod) {
|
||||
msiod->events_pending++;
|
||||
assert(msiod->state != NSIOD_STATE_DELETED);
|
||||
if (iod) {
|
||||
iod->events_pending++;
|
||||
assert(iod->state != NSIOD_STATE_DELETED);
|
||||
}
|
||||
|
||||
/* First we check if one is available from the free list ... */
|
||||
lnode = gh_list_pop(&nsp->free_events);
|
||||
if (!lnode)
|
||||
nse = (msevent *)safe_malloc(sizeof(msevent));
|
||||
nse = (struct nevent *)safe_malloc(sizeof(*nse));
|
||||
else
|
||||
nse = lnode_msevent(lnode);
|
||||
nse = lnode_nevent(lnode);
|
||||
|
||||
memset(nse, 0, sizeof(msevent));
|
||||
memset(nse, 0, sizeof(*nse));
|
||||
|
||||
nse->id = get_new_event_id(nsp, type);
|
||||
nse->type = type;
|
||||
@@ -451,8 +451,8 @@ msevent *msevent_new(mspool *nsp, enum nse_type type, msiod *msiod, int timeout_
|
||||
mspcap *mp;
|
||||
int sz;
|
||||
|
||||
assert(msiod != NULL);
|
||||
mp = (mspcap *)msiod->pcap;
|
||||
assert(iod != NULL);
|
||||
mp = (mspcap *)iod->pcap;
|
||||
assert(mp);
|
||||
|
||||
sz = mp->snaplen+1 + sizeof(nsock_pcap);
|
||||
@@ -465,27 +465,27 @@ msevent *msevent_new(mspool *nsp, enum nse_type type, msiod *msiod, int timeout_
|
||||
TIMEVAL_MSEC_ADD(nse->timeout, nsock_tod, timeout_msecs);
|
||||
}
|
||||
|
||||
nse->iod = msiod;
|
||||
nse->iod = iod;
|
||||
nse->handler = handler;
|
||||
nse->userdata = userdata;
|
||||
|
||||
if (nse->iod == NULL)
|
||||
nsock_log_debug(nsp, "msevent_new (IOD #NULL) (EID #%li)", nse->id);
|
||||
nsock_log_debug(nsp, "%s (IOD #NULL) (EID #%li)", __func__, nse->id);
|
||||
else
|
||||
nsock_log_debug(nsp, "msevent_new (IOD #%li) (EID #%li)", nse->iod->id,
|
||||
nsock_log_debug(nsp, "%s (IOD #%li) (EID #%li)", __func__, nse->iod->id,
|
||||
nse->id);
|
||||
return nse;
|
||||
}
|
||||
|
||||
/* Free an msevent which was allocated with msevent_new, including all internal
|
||||
/* Free an struct nevent which was allocated with event_new, including all internal
|
||||
* resources. Note -- we assume that nse->iod->events_pending (if it exists)
|
||||
* has ALREADY been decremented (done during msevent_dispatch_and_delete) -- so
|
||||
* remember to do this if you call msevent_delete() directly */
|
||||
void msevent_delete(mspool *nsp, msevent *nse) {
|
||||
* has ALREADY been decremented (done during event_dispatch_and_delete) -- so
|
||||
* remember to do this if you call event_delete() directly */
|
||||
void event_delete(struct npool *nsp, struct nevent *nse) {
|
||||
if (nse->iod == NULL)
|
||||
nsock_log_debug(nsp, "msevent_delete (IOD #NULL) (EID #%li)", nse->id);
|
||||
nsock_log_debug(nsp, "%s (IOD #NULL) (EID #%li)", __func__, nse->id);
|
||||
else
|
||||
nsock_log_debug(nsp, "msevent_delete (IOD #%li) (EID #%li)", nse->iod->id, nse->id);
|
||||
nsock_log_debug(nsp, "%s (IOD #%li) (EID #%li)", __func__, nse->iod->id, nse->id);
|
||||
|
||||
/* First free the IOBuf inside it if necessary */
|
||||
if (nse->type == NSE_TYPE_READ || nse->type == NSE_TYPE_WRITE) {
|
||||
@@ -535,7 +535,7 @@ const char *nse_status2str(enum nse_status status) {
|
||||
}
|
||||
}
|
||||
|
||||
int msevent_timedout(msevent *nse) {
|
||||
int event_timedout(struct nevent *nse) {
|
||||
if (nse->event_done)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ enum nsock_read_types {
|
||||
NSOCK_READ
|
||||
};
|
||||
|
||||
enum msiod_state {
|
||||
enum iod_state {
|
||||
NSIOD_STATE_DELETED,
|
||||
NSIOD_STATE_INITIAL,
|
||||
|
||||
@@ -152,7 +152,7 @@ struct writeinfo {
|
||||
|
||||
/* Remember that callers of this library should NOT be accessing these
|
||||
* fields directly */
|
||||
typedef struct {
|
||||
struct npool {
|
||||
|
||||
/* Every msp has a unique (across the program execution) id */
|
||||
unsigned long id;
|
||||
@@ -177,7 +177,7 @@ typedef struct {
|
||||
/* Active iods and related lists of events */
|
||||
gh_list_t active_iods;
|
||||
|
||||
/* msiod structures that have been freed for reuse */
|
||||
/* struct niod structures that have been freed for reuse */
|
||||
gh_list_t free_iods;
|
||||
/* When an event is deleted, we stick it here for later reuse */
|
||||
gh_list_t free_events;
|
||||
@@ -217,12 +217,12 @@ typedef struct {
|
||||
* nsock_proxychain_new() or nsp_set_proxychain(). */
|
||||
struct proxy_chain *px_chain;
|
||||
|
||||
} mspool;
|
||||
};
|
||||
|
||||
|
||||
/* nsock_iod is like a "file descriptor" for the nsock library. You use it to
|
||||
* request events. */
|
||||
typedef struct {
|
||||
struct niod {
|
||||
/* The socket descriptor related to the event */
|
||||
int sd;
|
||||
|
||||
@@ -245,10 +245,10 @@ typedef struct {
|
||||
|
||||
int watched_events;
|
||||
|
||||
/* The mspool used to create the iod (used for deletion) */
|
||||
mspool *nsp;
|
||||
/* The struct npool used to create the iod (used for deletion) */
|
||||
struct npool *nsp;
|
||||
|
||||
enum msiod_state state;
|
||||
enum iod_state state;
|
||||
|
||||
/* The host and port we are connected to using sd (saves a call to getpeername) */
|
||||
struct sockaddr_storage peer;
|
||||
@@ -264,9 +264,9 @@ typedef struct {
|
||||
/* -1 if none yet, otherwise IPPROTO_TCP, etc. */
|
||||
int lastproto;
|
||||
|
||||
/* The mspool keeps track of msiods that have been allocated so that it can
|
||||
* destroy them if the msp is deleted. This pointer makes it easy to remove
|
||||
* this msiod from the allocated list when necessary */
|
||||
/* The struct npool keeps track of NIODs that have been allocated so that it
|
||||
* can destroy them if the msp is deleted. This pointer makes it easy to
|
||||
* remove this struct niod from the allocated list when necessary */
|
||||
gh_lnode_t nodeq;
|
||||
|
||||
#define IOD_REGISTERED 0x01
|
||||
@@ -309,12 +309,12 @@ typedef struct {
|
||||
|
||||
struct proxy_chain_context *px_ctx;
|
||||
|
||||
} msiod;
|
||||
};
|
||||
|
||||
|
||||
/* nsock_event_t handles a single event. Its ID is generally returned when the
|
||||
* event is created, and the event is included in callbacks */
|
||||
typedef struct {
|
||||
struct nevent {
|
||||
/* Every event has an ID which is unique for a given nsock unless you blow
|
||||
* through more than 500,000,000 events */
|
||||
nsock_event_id id;
|
||||
@@ -343,7 +343,7 @@ typedef struct {
|
||||
int errnum;
|
||||
|
||||
/* The nsock I/O descriptor related to event (if applicable) */
|
||||
msiod *iod;
|
||||
struct niod *iod;
|
||||
|
||||
/* The handler to call when event is complete */
|
||||
nsock_ev_handler handler;
|
||||
@@ -369,7 +369,7 @@ typedef struct {
|
||||
* that other crap */
|
||||
unsigned int event_done: 1;
|
||||
unsigned int eof: 1;
|
||||
} msevent;
|
||||
};
|
||||
|
||||
|
||||
struct io_engine {
|
||||
@@ -377,137 +377,138 @@ struct io_engine {
|
||||
const char *name;
|
||||
|
||||
/* Engine constructor */
|
||||
int (*init)(mspool *nsp);
|
||||
int (*init)(struct npool *nsp);
|
||||
|
||||
/* Engine destructor */
|
||||
void (*destroy)(mspool *nsp);
|
||||
void (*destroy)(struct npool *nsp);
|
||||
|
||||
/* Register a new IOD to the engine */
|
||||
int (*iod_register)(mspool *nsp, msiod *iod, int ev);
|
||||
int (*iod_register)(struct npool *nsp, struct niod *iod, int ev);
|
||||
|
||||
/* Remove a registered IOD */
|
||||
int (*iod_unregister)(mspool *nsp, msiod *iod);
|
||||
int (*iod_unregister)(struct npool *nsp, struct niod *iod);
|
||||
|
||||
/* Modify events for a registered IOD.
|
||||
* - ev_set represent the events to add
|
||||
* - ev_clr represent the events to delete (if set) */
|
||||
int (*iod_modify)(mspool *nsp, msiod *iod, int ev_set, int ev_clr);
|
||||
int (*iod_modify)(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr);
|
||||
|
||||
/* Main engine loop */
|
||||
int (*loop)(mspool *nsp, int msec_timeout);
|
||||
int (*loop)(struct npool *nsp, int msec_timeout);
|
||||
};
|
||||
|
||||
/* ----------- NSOCK I/O ENGINE CONVENIENCE WRAPPERS ------------ */
|
||||
static inline int nsock_engine_init(mspool *nsp) {
|
||||
static inline int nsock_engine_init(struct npool *nsp) {
|
||||
return nsp->engine->init(nsp);
|
||||
}
|
||||
|
||||
static inline void nsock_engine_destroy(mspool *nsp) {
|
||||
static inline void nsock_engine_destroy(struct npool *nsp) {
|
||||
nsp->engine->destroy(nsp);
|
||||
return;
|
||||
}
|
||||
|
||||
static inline int nsock_engine_iod_register(mspool *nsp, msiod *iod, int ev) {
|
||||
static inline int nsock_engine_iod_register(struct npool *nsp, struct niod *iod, int ev) {
|
||||
return nsp->engine->iod_register(nsp, iod, ev);
|
||||
}
|
||||
|
||||
static inline int nsock_engine_iod_unregister(mspool *nsp, msiod *iod) {
|
||||
static inline int nsock_engine_iod_unregister(struct npool *nsp, struct niod *iod) {
|
||||
return nsp->engine->iod_unregister(nsp, iod);
|
||||
}
|
||||
|
||||
static inline int nsock_engine_iod_modify(mspool *nsp, msiod *iod, int ev_set, int ev_clr) {
|
||||
static inline int nsock_engine_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr) {
|
||||
return nsp->engine->iod_modify(nsp, iod, ev_set, ev_clr);
|
||||
}
|
||||
|
||||
static inline int nsock_engine_loop(mspool *nsp, int msec_timeout) {
|
||||
static inline int nsock_engine_loop(struct npool *nsp, int msec_timeout) {
|
||||
return nsp->engine->loop(nsp, msec_timeout);
|
||||
}
|
||||
|
||||
/* ------------------- PROTOTYPES ------------------- */
|
||||
|
||||
int msevent_timedout(msevent *nse);
|
||||
int event_timedout(struct nevent *nse);
|
||||
|
||||
/* Get a new nsock_event_id, given a type */
|
||||
nsock_event_id get_new_event_id(mspool *nsp, enum nse_type type);
|
||||
nsock_event_id get_new_event_id(struct npool *nsp, enum nse_type type);
|
||||
|
||||
/* Take an event ID and return the type (NSE_TYPE_CONNECT, etc */
|
||||
enum nse_type get_event_id_type(nsock_event_id event_id);
|
||||
|
||||
/* Create a new event structure -- must be deleted later with msevent_delete,
|
||||
* unless it returns NULL (failure). NULL can be passed in for the msiod and
|
||||
/* Create a new event structure -- must be deleted later with event_delete,
|
||||
* unless it returns NULL (failure). NULL can be passed in for the struct niod and
|
||||
* the userdata if not available. */
|
||||
msevent *msevent_new(mspool *nsp, enum nse_type type, msiod *msiod, int timeout_msecs, nsock_ev_handler handler, void *userdata);
|
||||
struct nevent *event_new(struct npool *nsp, enum nse_type type, struct niod *iod,
|
||||
int timeout_msecs, nsock_ev_handler handler, void *userdata);
|
||||
|
||||
/* An internal function for cancelling an event when you already have a pointer
|
||||
* to the msevent (use nsock_event_cancel if you just have an ID). The
|
||||
* to the struct nevent (use nsock_event_cancel if you just have an ID). The
|
||||
* event_list passed in should correspond to the type of the event. For
|
||||
* example, with NSE_TYPE_READ, you would pass in &iod->read_events;. elem
|
||||
* is the list element in event_list which holds the event. Pass a nonzero for
|
||||
* notify if you want the program owning the event to be notified that it has
|
||||
* been cancelled */
|
||||
int msevent_cancel(mspool *nsp, msevent *nse, gh_list_t *event_list, gh_lnode_t *elem, int notify);
|
||||
int nevent_delete(struct npool *nsp, struct nevent *nse, gh_list_t *event_list, gh_lnode_t *elem, int notify);
|
||||
|
||||
/* Adjust various statistics, dispatches the event handler (if notify is
|
||||
* nonzero) and then deletes the event. This function does NOT delete the event
|
||||
* from any lists it might be on (eg nsp->read_list etc.) nse->event_done
|
||||
* MUST be true when you call this */
|
||||
void msevent_dispatch_and_delete(mspool *nsp, msevent *nse, int notify);
|
||||
void event_dispatch_and_delete(struct npool *nsp, struct nevent *nse, int notify);
|
||||
|
||||
/* Free an msevent which was allocated with msevent_new, including all internal
|
||||
/* Free an struct nevent which was allocated with event_new, including all internal
|
||||
* resources. Note -- we assume that nse->iod->events_pending (if it exists)
|
||||
* has ALREADY been decremented (done during msevent_dispatch_and_delete) -- so
|
||||
* remember to do this if you call msevent_delete() directly */
|
||||
void msevent_delete(mspool *nsp, msevent *nse);
|
||||
* has ALREADY been decremented (done during event_dispatch_and_delete) -- so
|
||||
* remember to do this if you call event_delete() directly */
|
||||
void event_delete(struct npool *nsp, struct nevent *nse);
|
||||
|
||||
/* Add an event to the appropriate nsp event list, handles housekeeping such as
|
||||
* adjusting the descriptor select/poll lists, registering the timeout value,
|
||||
* etc. */
|
||||
void nsp_add_event(mspool *nsp, msevent *nse);
|
||||
void nsp_add_event(struct npool *nsp, struct nevent *nse);
|
||||
|
||||
void nsock_connect_internal(mspool *ms, msevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen, unsigned short port);
|
||||
void nsock_connect_internal(struct npool *ms, struct nevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen, unsigned short port);
|
||||
|
||||
/* Comments on using the following handle_*_result functions are available in nsock_core.c */
|
||||
|
||||
/* handle_connect_results assumes that select or poll have already shown the
|
||||
* descriptor to be active */
|
||||
void handle_connect_result(mspool *ms, msevent *nse, enum nse_status status);
|
||||
void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status status);
|
||||
|
||||
void handle_read_result(mspool *ms, msevent *nse, enum nse_status status);
|
||||
void handle_read_result(struct npool *ms, struct nevent *nse, enum nse_status status);
|
||||
|
||||
void handle_write_result(mspool *ms, msevent *nse, enum nse_status status);
|
||||
void handle_write_result(struct npool *ms, struct nevent *nse, enum nse_status status);
|
||||
|
||||
void handle_timer_result(mspool *ms, msevent *nse, enum nse_status status);
|
||||
void handle_timer_result(struct npool *ms, struct nevent *nse, enum nse_status status);
|
||||
|
||||
#if HAVE_PCAP
|
||||
void handle_pcap_read_result(mspool *ms, msevent *nse, enum nse_status status);
|
||||
void handle_pcap_read_result(struct npool *ms, struct nevent *nse, enum nse_status status);
|
||||
#endif
|
||||
|
||||
/* An event has been completed and the handler is about to be called. This
|
||||
* function writes out tracing data about the event if necessary */
|
||||
void nsock_trace_handler_callback(mspool *ms, msevent *nse);
|
||||
void nsock_trace_handler_callback(struct npool *ms, struct nevent *nse);
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
/* Sets the ssl session of an nsock_iod, increments usage count. The session
|
||||
* should not have been set yet (as no freeing is done) */
|
||||
void nsi_set_ssl_session(msiod *iod, SSL_SESSION *sessid);
|
||||
void nsi_set_ssl_session(struct niod *iod, SSL_SESSION *sessid);
|
||||
#endif
|
||||
|
||||
static inline msevent *next_expirable_event(mspool *nsp) {
|
||||
static inline struct nevent *next_expirable_event(struct npool *nsp) {
|
||||
gh_hnode_t *hnode;
|
||||
|
||||
hnode = gh_heap_min(&nsp->expirables);
|
||||
if (!hnode)
|
||||
return NULL;
|
||||
|
||||
return container_of(hnode, msevent, expire);
|
||||
return container_of(hnode, struct nevent, expire);
|
||||
}
|
||||
|
||||
static inline msevent *lnode_msevent(gh_lnode_t *lnode) {
|
||||
return container_of(lnode, msevent, nodeq_io);
|
||||
static inline struct nevent *lnode_nevent(gh_lnode_t *lnode) {
|
||||
return container_of(lnode, struct nevent, nodeq_io);
|
||||
}
|
||||
|
||||
static inline msevent *lnode_msevent2(gh_lnode_t *lnode) {
|
||||
return container_of(lnode, msevent, nodeq_pcap);
|
||||
static inline struct nevent *lnode_nevent2(gh_lnode_t *lnode) {
|
||||
return container_of(lnode, struct nevent, nodeq_pcap);
|
||||
}
|
||||
|
||||
#endif /* NSOCK_INTERNAL_H */
|
||||
|
||||
@@ -86,16 +86,16 @@ nsock_iod nsi_new(nsock_pool nsockp, void *userdata) {
|
||||
* dup()ed, so you may close or otherwise manipulate your copy. The duped copy
|
||||
* will be destroyed when the nsi is destroyed. */
|
||||
nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {
|
||||
mspool *nsp = (mspool *)nsockp;
|
||||
struct npool *nsp = (struct npool *)nsockp;
|
||||
gh_lnode_t *lnode;
|
||||
msiod *nsi;
|
||||
struct niod *nsi;
|
||||
|
||||
lnode = gh_list_pop(&nsp->free_iods);
|
||||
if (!lnode) {
|
||||
nsi = (msiod *)safe_malloc(sizeof(msiod));
|
||||
nsi = (struct niod *)safe_malloc(sizeof(*nsi));
|
||||
memset(nsi, 0, sizeof(*nsi));
|
||||
} else {
|
||||
nsi = container_of(lnode, msiod, nodeq);
|
||||
nsi = container_of(lnode, struct niod, nodeq);
|
||||
}
|
||||
|
||||
if (sd == -1) {
|
||||
@@ -125,7 +125,7 @@ nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {
|
||||
nsi->write_count = 0;
|
||||
|
||||
nsi->userdata = userdata;
|
||||
nsi->nsp = (mspool *)nsockp;
|
||||
nsi->nsp = (struct npool *)nsockp;
|
||||
|
||||
nsi->_flags = 0;
|
||||
|
||||
@@ -151,7 +151,7 @@ nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {
|
||||
if (nsi->id == 0)
|
||||
nsi->id = nsp->next_iod_serial++;
|
||||
|
||||
/* The nsp keeps track of active msiods so it can delete them if it is deleted */
|
||||
/* The nsp keeps track of active iods so it can delete them if it is deleted */
|
||||
gh_list_append(&nsp->active_iods, &nsi->nodeq);
|
||||
|
||||
nsock_log_info(nsp, "nsi_new (IOD #%lu)", nsi->id);
|
||||
@@ -160,9 +160,9 @@ nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {
|
||||
}
|
||||
|
||||
/* Defined in nsock_core.c. */
|
||||
int socket_count_zero(msiod *iod, mspool *ms);
|
||||
int socket_count_zero(struct niod *iod, struct npool *ms);
|
||||
|
||||
/* If msiod_new returned success, you must free the iod when you are done with
|
||||
/* If nsi_new returned success, you must free the iod when you are done with
|
||||
* it to conserve memory (and in some cases, sockets). After this call,
|
||||
* nsockiod may no longer be used -- you need to create a new one with
|
||||
* nsi_new(). pending_response tells what to do with any events that are
|
||||
@@ -171,7 +171,7 @@ int socket_count_zero(msiod *iod, mspool *ms);
|
||||
* to the killed events), or NSOCK_PENDING_ERROR (print an error message and
|
||||
* quit the program) */
|
||||
void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
msiod *nsi = (msiod *)nsockiod;
|
||||
struct niod *nsi = (struct niod *)nsockiod;
|
||||
gh_lnode_t *evlist_ar[3];
|
||||
gh_list_t *corresp_list[3];
|
||||
int i;
|
||||
@@ -188,8 +188,8 @@ void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
nsock_log_info(nsi->nsp, "nsi_delete (IOD #%lu)", nsi->id);
|
||||
|
||||
if (nsi->events_pending > 0) {
|
||||
/* shit -- they killed the msiod while an event was still pending on it.
|
||||
* Maybe I should store the pending events in the msiod. On the other hand,
|
||||
/* shit -- they killed the struct niod while an event was still pending on it.
|
||||
* Maybe I should store the pending events in the iod. On the other hand,
|
||||
* this should be a pretty rare occurrence and so I'll save space and hassle
|
||||
* by just locating the events here by searching through the active events
|
||||
* list */
|
||||
@@ -208,16 +208,16 @@ void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
|
||||
for (i = 0; i < 3 && nsi->events_pending > 0; i++) {
|
||||
for (current = evlist_ar[i]; current != NULL; current = next) {
|
||||
msevent *nse;
|
||||
struct nevent *nse;
|
||||
|
||||
next = gh_lnode_next(current);
|
||||
nse = lnode_msevent(current);
|
||||
nse = lnode_nevent(current);
|
||||
|
||||
/* we're done with this list of events for the current IOD */
|
||||
if (nse->iod != nsi)
|
||||
break;
|
||||
|
||||
msevent_cancel(nsi->nsp, nse, corresp_list[i], current, pending_response == NSOCK_PENDING_NOTIFY);
|
||||
nevent_delete(nsi->nsp, nse, corresp_list[i], current, pending_response == NSOCK_PENDING_NOTIFY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,13 +295,13 @@ void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
* given nspool (unless you blow through billions of them). */
|
||||
unsigned long nsi_id(nsock_iod nsockiod) {
|
||||
assert(nsockiod);
|
||||
return ((msiod *)nsockiod)->id;
|
||||
return ((struct niod *)nsockiod)->id;
|
||||
}
|
||||
|
||||
/* Returns the SSL object inside an nsock_iod, or NULL if unset. */
|
||||
nsock_ssl nsi_getssl(nsock_iod nsockiod) {
|
||||
#if HAVE_OPENSSL
|
||||
return ((msiod *)nsockiod)->ssl;
|
||||
return ((struct niod *)nsockiod)->ssl;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
@@ -310,7 +310,7 @@ nsock_ssl nsi_getssl(nsock_iod nsockiod) {
|
||||
/* Returns the SSL_SESSION of an nsock_iod, and increments it's usage count. */
|
||||
nsock_ssl_session nsi_get1_ssl_session(nsock_iod nsockiod) {
|
||||
#if HAVE_OPENSSL
|
||||
return SSL_get1_session(((msiod *)nsockiod)->ssl);
|
||||
return SSL_get1_session(((struct niod *)nsockiod)->ssl);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
@@ -319,7 +319,7 @@ nsock_ssl_session nsi_get1_ssl_session(nsock_iod nsockiod) {
|
||||
/* Returns the SSL_SESSION without incrementing usage count. */
|
||||
nsock_ssl_session nsi_get0_ssl_session(nsock_iod nsockiod) {
|
||||
#if HAVE_OPENSSL
|
||||
return SSL_get0_session(((msiod *)nsockiod)->ssl);
|
||||
return SSL_get0_session(((struct niod *)nsockiod)->ssl);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
@@ -328,7 +328,7 @@ nsock_ssl_session nsi_get0_ssl_session(nsock_iod nsockiod) {
|
||||
/* sets the ssl session of an nsock_iod, increments usage count. The session
|
||||
* should not have been set yet (as no freeing is done) */
|
||||
#if HAVE_OPENSSL
|
||||
void nsi_set_ssl_session(msiod *iod, SSL_SESSION *sessid) {
|
||||
void nsi_set_ssl_session(struct niod *iod, SSL_SESSION *sessid) {
|
||||
if (sessid) {
|
||||
iod->ssl_session = sessid;
|
||||
/* No reference counting for the copy stored briefly in nsiod */
|
||||
@@ -336,30 +336,30 @@ void nsi_set_ssl_session(msiod *iod, SSL_SESSION *sessid) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Sometimes it is useful to store a pointer to information inside the msiod so
|
||||
/* Sometimes it is useful to store a pointer to information inside the struct niod so
|
||||
* you can retrieve it during a callback. */
|
||||
void nsi_setud(nsock_iod nsockiod, void *data) {
|
||||
assert(nsockiod);
|
||||
((msiod *)nsockiod)->userdata = data;
|
||||
((struct niod *)nsockiod)->userdata = data;
|
||||
}
|
||||
|
||||
/* And the function above wouldn't make much sense if we didn't have a way to
|
||||
* retrieve that data... */
|
||||
void *nsi_getud(nsock_iod nsockiod) {
|
||||
assert(nsockiod);
|
||||
return ((msiod *)nsockiod)->userdata;
|
||||
return ((struct niod *)nsockiod)->userdata;
|
||||
}
|
||||
|
||||
/* Returns 1 if an NSI is communicating via SSL, 0 otherwise. */
|
||||
int nsi_checkssl(nsock_iod nsockiod) {
|
||||
return (((msiod *)nsockiod)->ssl) ? 1 : 0;
|
||||
return (((struct niod *)nsockiod)->ssl) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* Returns the remote peer port (or -1 if unavailable). Note the return value
|
||||
* is a whole int so that -1 can be distinguished from 65535. Port is returned
|
||||
* in host byte order. */
|
||||
int nsi_peerport(nsock_iod nsockiod) {
|
||||
msiod *nsi = (msiod *)nsockiod;
|
||||
struct niod *nsi = (struct niod *)nsockiod;
|
||||
int fam;
|
||||
|
||||
if (nsi->peerlen <= 0)
|
||||
@@ -379,7 +379,7 @@ int nsi_peerport(nsock_iod nsockiod) {
|
||||
|
||||
/* Sets the local address to bind to before connect() */
|
||||
int nsi_set_localaddr(nsock_iod nsi, struct sockaddr_storage *ss, size_t sslen) {
|
||||
msiod *iod = (msiod *)nsi;
|
||||
struct niod *iod = (struct niod *)nsi;
|
||||
|
||||
assert(iod);
|
||||
|
||||
@@ -395,7 +395,7 @@ int nsi_set_localaddr(nsock_iod nsi, struct sockaddr_storage *ss, size_t sslen)
|
||||
* so you can free() yours if necessary. This copy is freed when the iod is
|
||||
* destroyed. */
|
||||
int nsi_set_ipoptions(nsock_iod nsi, void *opts, size_t optslen) {
|
||||
msiod *iod = (msiod *)nsi;
|
||||
struct niod *iod = (struct niod *)nsi;
|
||||
|
||||
assert(iod);
|
||||
|
||||
@@ -416,7 +416,7 @@ int nsi_set_ipoptions(nsock_iod nsi, void *opts, size_t optslen) {
|
||||
* create havok by closing the descriptor! If the descriptor you get back is
|
||||
* -1, the iod does not currently possess a valid descriptor */
|
||||
int nsi_getsd(nsock_iod nsockiod) {
|
||||
msiod *iod = (msiod *)nsockiod;
|
||||
struct niod *iod = (struct niod *)nsockiod;
|
||||
|
||||
assert(nsockiod);
|
||||
|
||||
@@ -430,16 +430,16 @@ int nsi_getsd(nsock_iod nsockiod) {
|
||||
|
||||
unsigned long nsi_get_read_count(nsock_iod nsockiod){
|
||||
assert(nsockiod);
|
||||
return ((msiod *)nsockiod)->read_count;
|
||||
return ((struct niod *)nsockiod)->read_count;
|
||||
}
|
||||
|
||||
unsigned long nsi_get_write_count(nsock_iod nsockiod){
|
||||
assert(nsockiod);
|
||||
return ((msiod *)nsockiod)->write_count;
|
||||
return ((struct niod *)nsockiod)->write_count;
|
||||
}
|
||||
|
||||
int nsi_set_hostname(nsock_iod nsi, const char *hostname) {
|
||||
msiod *iod = (msiod *)nsi;
|
||||
struct niod *iod = (struct niod *)nsi;
|
||||
|
||||
if (iod->hostname != NULL)
|
||||
free(iod->hostname);
|
||||
|
||||
@@ -71,20 +71,20 @@ extern struct timeval nsock_tod;
|
||||
|
||||
|
||||
void nsock_set_log_function(nsock_pool nsp, nsock_logger_t logger) {
|
||||
mspool *ms = (mspool *)nsp;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
|
||||
ms->logger = logger;
|
||||
nsock_log_debug(ms, "Registered external logging function: %p", logger);
|
||||
}
|
||||
|
||||
nsock_loglevel_t nsock_get_loglevel(nsock_pool nsp) {
|
||||
mspool *ms = (mspool *)nsp;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
|
||||
return ms->loglevel;
|
||||
}
|
||||
|
||||
void nsock_set_loglevel(nsock_pool nsp, nsock_loglevel_t loglevel) {
|
||||
mspool *ms = (mspool *)nsp;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
|
||||
ms->loglevel = loglevel;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ void __nsock_log_internal(nsock_pool nsp, nsock_loglevel_t loglevel,
|
||||
|
||||
rc = vasprintf(&rec.msg, format, args);
|
||||
if (rc >= 0) {
|
||||
mspool *ms = (mspool *)nsp;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
|
||||
ms->logger(nsp, &rec);
|
||||
free(rec.msg);
|
||||
|
||||
@@ -103,7 +103,7 @@ extern struct timeval nsock_tod;
|
||||
"You can probably use \"-PN -sT localhost\" though.\n\n"
|
||||
|
||||
|
||||
static int nsock_pcap_set_filter(mspool *nsp, pcap_t *pt, const char *device,
|
||||
static int nsock_pcap_set_filter(struct npool *nsp, pcap_t *pt, const char *device,
|
||||
const char *bpf) {
|
||||
struct bpf_program fcode;
|
||||
int rc;
|
||||
@@ -198,7 +198,7 @@ static int nsock_pcap_get_l3_offset(pcap_t *pt, int *dl) {
|
||||
return (offset);
|
||||
}
|
||||
|
||||
static int nsock_pcap_try_open(mspool *nsp, mspcap *mp, const char *dev,
|
||||
static int nsock_pcap_try_open(struct npool *nsp, mspcap *mp, const char *dev,
|
||||
int snaplen, int promisc, int timeout_ms,
|
||||
char *errbuf) {
|
||||
mp->pt = pcap_open_live(dev, snaplen, promisc, timeout_ms, errbuf);
|
||||
@@ -220,8 +220,8 @@ static int nsock_pcap_try_open(mspool *nsp, mspcap *mp, const char *dev,
|
||||
* if error occurred. */
|
||||
int nsock_pcap_open(nsock_pool nsp, nsock_iod nsiod, const char *pcap_device,
|
||||
int snaplen, int promisc, const char *bpf_fmt, ...) {
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
mspcap *mp = (mspcap *)nsi->pcap;
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
char bpf[4096];
|
||||
@@ -362,11 +362,11 @@ int nsock_pcap_open(nsock_pool nsp, nsock_iod nsiod, const char *pcap_device,
|
||||
nsock_event_id nsock_pcap_read_packet(nsock_pool nsp, nsock_iod nsiod,
|
||||
nsock_ev_handler handler,
|
||||
int timeout_msecs, void *userdata) {
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_PCAP_READ, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_PCAP_READ, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "Pcap read request from IOD #%li EID %li", nsi->id, nse->id);
|
||||
@@ -377,7 +377,7 @@ nsock_event_id nsock_pcap_read_packet(nsock_pool nsp, nsock_iod nsiod,
|
||||
}
|
||||
|
||||
/* Remember that pcap descriptor is in nonblocking state. */
|
||||
int do_actual_pcap_read(msevent *nse) {
|
||||
int do_actual_pcap_read(struct nevent *nse) {
|
||||
mspcap *mp = (mspcap *)nse->iod->pcap;
|
||||
nsock_pcap npp;
|
||||
nsock_pcap *n;
|
||||
@@ -437,8 +437,8 @@ int do_actual_pcap_read(msevent *nse) {
|
||||
void nse_readpcap(nsock_event nsev, const unsigned char **l2_data, size_t *l2_len,
|
||||
const unsigned char **l3_data, size_t *l3_len,
|
||||
size_t *packet_len, struct timeval *ts) {
|
||||
msevent *nse = (msevent *)nsev;
|
||||
msiod *iod = nse->iod;
|
||||
struct nevent *nse = (struct nevent *)nsev;
|
||||
struct niod *iod = nse->iod;
|
||||
mspcap *mp = (mspcap *)iod->pcap;
|
||||
nsock_pcap *n;
|
||||
size_t l2l;
|
||||
@@ -478,7 +478,7 @@ void nse_readpcap(nsock_event nsev, const unsigned char **l2_data, size_t *l2_le
|
||||
}
|
||||
|
||||
int nsi_pcap_linktype(nsock_iod nsiod) {
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
mspcap *mp = (mspcap *)nsi->pcap;
|
||||
|
||||
assert(mp);
|
||||
@@ -486,7 +486,7 @@ int nsi_pcap_linktype(nsock_iod nsiod) {
|
||||
}
|
||||
|
||||
int nsi_is_pcap(nsock_iod nsiod) {
|
||||
msiod *nsi = (msiod *)nsiod;
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
mspcap *mp = (mspcap *)nsi->pcap;
|
||||
|
||||
return (mp != NULL);
|
||||
|
||||
@@ -135,7 +135,7 @@
|
||||
typedef struct{
|
||||
pcap_t *pt;
|
||||
int pcap_desc;
|
||||
/* Like the corresponding member in msiod, when this reaches 0 we stop
|
||||
/* Like the corresponding member in iod, when this reaches 0 we stop
|
||||
* watching the socket for readability. */
|
||||
int readsd_count;
|
||||
int datalink;
|
||||
@@ -151,7 +151,7 @@ typedef struct{
|
||||
const unsigned char *packet; /* caplen bytes */
|
||||
} nsock_pcap;
|
||||
|
||||
int do_actual_pcap_read(msevent *nse);
|
||||
int do_actual_pcap_read(struct nevent *nse);
|
||||
|
||||
#endif /* HAVE_PCAP */
|
||||
#endif /* NSOCK_PCAP_H */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/***************************************************************************
|
||||
* nsock_pool.c -- This contains the functions that deal with creating, *
|
||||
* destroying, and otherwise manipulating nsock_pools (and their internal *
|
||||
* mspool representation). An nsock_pool aggregates and manages events *
|
||||
* struct npool representation). An nsock_pool aggregates and manages events *
|
||||
* and i/o descriptors *
|
||||
* *
|
||||
***********************IMPORTANT NSOCK LICENSE TERMS***********************
|
||||
@@ -92,7 +92,7 @@ static void nsock_library_initialize(void);
|
||||
|
||||
/* Every mst has an ID that is unique across the program execution */
|
||||
unsigned long nsp_getid(nsock_pool nsp) {
|
||||
mspool *mt = (mspool *)nsp;
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
return mt->id;
|
||||
}
|
||||
|
||||
@@ -100,21 +100,21 @@ unsigned long nsp_getid(nsock_pool nsp) {
|
||||
* valid if the status NSOCK_LOOP_ERROR was returned by nsock_loop() */
|
||||
|
||||
int nsp_geterrorcode(nsock_pool nsp) {
|
||||
mspool *mt = (mspool *)nsp;
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
return mt->errnum;
|
||||
}
|
||||
|
||||
/* Sometimes it is useful to store a pointer to information inside
|
||||
* the NSP so you can retrieve it during a callback. */
|
||||
void nsp_setud(nsock_pool nsp, void *data) {
|
||||
mspool *mt = (mspool *)nsp;
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
mt->userdata = data;
|
||||
}
|
||||
|
||||
/* And the define above wouldn't make much sense if we didn't have a way
|
||||
* to retrieve that data ... */
|
||||
void *nsp_getud(nsock_pool nsp) {
|
||||
mspool *mt = (mspool *)nsp;
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
return mt->userdata;
|
||||
}
|
||||
|
||||
@@ -122,22 +122,22 @@ void *nsp_getud(nsock_pool nsp) {
|
||||
* set in nsp_new(). Any non-zero (true) value sets SO_BROADCAST on all new
|
||||
* sockets (value of optval will be used directly in the setsockopt() call */
|
||||
void nsp_setbroadcast(nsock_pool nsp, int optval) {
|
||||
mspool *mt = (mspool *)nsp;
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
mt->broadcast = optval;
|
||||
}
|
||||
|
||||
/* Sets the name of the interface for new sockets to bind to. */
|
||||
void nsp_setdevice(nsock_pool nsp, const char *device) {
|
||||
mspool *mt = (mspool *)nsp;
|
||||
struct npool *mt = (struct npool *)nsp;
|
||||
mt->device = device;
|
||||
}
|
||||
|
||||
static int expirable_cmp(gh_hnode_t *n1, gh_hnode_t *n2) {
|
||||
msevent *nse1;
|
||||
msevent *nse2;
|
||||
struct nevent *nse1;
|
||||
struct nevent *nse2;
|
||||
|
||||
nse1 = container_of(n1, msevent, expire);
|
||||
nse2 = container_of(n2, msevent, expire);
|
||||
nse1 = container_of(n1, struct nevent, expire);
|
||||
nse2 = container_of(n2, struct nevent, expire);
|
||||
|
||||
return (TIMEVAL_BEFORE(nse1->timeout, nse2->timeout)) ? 1 : 0;
|
||||
}
|
||||
@@ -147,7 +147,7 @@ static int expirable_cmp(gh_hnode_t *n1, gh_hnode_t *n2) {
|
||||
* returned. If you do not wish to immediately associate any userdata, pass in
|
||||
* NULL. */
|
||||
nsock_pool nsp_new(void *userdata) {
|
||||
mspool *nsp;
|
||||
struct npool *nsp;
|
||||
|
||||
/* initialize the library in not already done */
|
||||
if (!nsocklib_initialized) {
|
||||
@@ -155,7 +155,7 @@ nsock_pool nsp_new(void *userdata) {
|
||||
nsocklib_initialized = 1;
|
||||
}
|
||||
|
||||
nsp = (mspool *)safe_malloc(sizeof(*nsp));
|
||||
nsp = (struct npool *)safe_malloc(sizeof(*nsp));
|
||||
memset(nsp, 0, sizeof(*nsp));
|
||||
|
||||
gettimeofday(&nsock_tod, NULL);
|
||||
@@ -206,9 +206,9 @@ nsock_pool nsp_new(void *userdata) {
|
||||
* longer be used. Any pending events are sent an NSE_STATUS_KILL callback and
|
||||
* all outstanding iods are deleted. */
|
||||
void nsp_delete(nsock_pool ms_pool) {
|
||||
mspool *nsp = (mspool *)ms_pool;
|
||||
msevent *nse;
|
||||
msiod *nsi;
|
||||
struct npool *nsp = (struct npool *)ms_pool;
|
||||
struct nevent *nse;
|
||||
struct niod *nsi;
|
||||
int i;
|
||||
gh_lnode_t *current, *next;
|
||||
gh_list_t *event_lists[] = {
|
||||
@@ -232,10 +232,10 @@ void nsp_delete(nsock_pool ms_pool) {
|
||||
|
||||
#if HAVE_PCAP
|
||||
if (event_lists[i] == &nsp->pcap_read_events)
|
||||
nse = lnode_msevent2(lnode);
|
||||
nse = lnode_nevent2(lnode);
|
||||
else
|
||||
#endif
|
||||
nse = lnode_msevent(lnode);
|
||||
nse = lnode_nevent(lnode);
|
||||
|
||||
assert(nse);
|
||||
|
||||
@@ -247,7 +247,7 @@ void nsp_delete(nsock_pool ms_pool) {
|
||||
nse->iod->events_pending--;
|
||||
assert(nse->iod->events_pending >= 0);
|
||||
}
|
||||
msevent_delete(nsp, nse);
|
||||
event_delete(nsp, nse);
|
||||
}
|
||||
gh_list_free(event_lists[i]);
|
||||
}
|
||||
@@ -257,25 +257,25 @@ void nsp_delete(nsock_pool ms_pool) {
|
||||
gh_hnode_t *hnode;
|
||||
|
||||
hnode = gh_heap_pop(&nsp->expirables);
|
||||
nse = container_of(hnode, msevent, expire);
|
||||
nse = container_of(hnode, struct nevent, expire);
|
||||
|
||||
if (nse->type == NSE_TYPE_TIMER) {
|
||||
nse->status = NSE_STATUS_KILL;
|
||||
nsock_trace_handler_callback(nsp, nse);
|
||||
nse->handler(nsp, nse, nse->userdata);
|
||||
msevent_delete(nsp, nse);
|
||||
event_delete(nsp, nse);
|
||||
gh_list_append(&nsp->free_events, &nse->nodeq_io);
|
||||
}
|
||||
}
|
||||
|
||||
gh_heap_free(&nsp->expirables);
|
||||
|
||||
/* foreach msiod */
|
||||
/* foreach struct niod */
|
||||
for (current = gh_list_first_elem(&nsp->active_iods);
|
||||
current != NULL;
|
||||
current = next) {
|
||||
next = gh_lnode_next(current);
|
||||
nsi = container_of(current, msiod, nodeq);
|
||||
nsi = container_of(current, struct niod, nodeq);
|
||||
|
||||
nsi_delete(nsi, NSOCK_PENDING_ERROR);
|
||||
|
||||
@@ -285,12 +285,12 @@ void nsp_delete(nsock_pool ms_pool) {
|
||||
|
||||
/* Now we free all the memory in the free iod list */
|
||||
while ((current = gh_list_pop(&nsp->free_iods))) {
|
||||
nsi = container_of(current, msiod, nodeq);
|
||||
nsi = container_of(current, struct niod, nodeq);
|
||||
free(nsi);
|
||||
}
|
||||
|
||||
while ((current = gh_list_pop(&nsp->free_events))) {
|
||||
nse = lnode_msevent(current);
|
||||
nse = lnode_nevent(current);
|
||||
free(nse);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ static const struct proxy_spec *ProxyBackends[] = {
|
||||
/* A proxy chain is a comma-separated list of proxy specification strings:
|
||||
* proto://[user:pass@]host[:port] */
|
||||
int nsock_proxychain_new(const char *proxystr, nsock_proxychain *chain, nsock_pool nspool) {
|
||||
mspool *nsp = (mspool *)nspool;
|
||||
struct npool *nsp = (struct npool *)nspool;
|
||||
struct proxy_chain *pxc, **pchain = (struct proxy_chain **)chain;
|
||||
|
||||
*pchain = NULL;
|
||||
@@ -139,7 +139,7 @@ void nsock_proxychain_delete(nsock_proxychain chain) {
|
||||
}
|
||||
|
||||
int nsp_set_proxychain(nsock_pool nspool, nsock_proxychain chain) {
|
||||
mspool *nsp = (mspool *)nspool;
|
||||
struct npool *nsp = (struct npool *)nspool;
|
||||
|
||||
if (nsp && nsp->px_chain) {
|
||||
nsock_log_error(nsp, "Invalid call. Existing proxychain on this nsock_pool");
|
||||
@@ -151,7 +151,7 @@ int nsp_set_proxychain(nsock_pool nspool, nsock_proxychain chain) {
|
||||
}
|
||||
|
||||
struct proxy_chain_context *proxy_chain_context_new(nsock_pool nspool) {
|
||||
mspool *nsp = (mspool *)nspool;
|
||||
struct npool *nsp = (struct npool *)nspool;
|
||||
struct proxy_chain_context *ctx;
|
||||
|
||||
ctx = (struct proxy_chain_context *)safe_malloc(sizeof(struct proxy_chain_context));
|
||||
@@ -413,8 +413,8 @@ void proxy_parser_delete(struct proxy_parser *parser) {
|
||||
}
|
||||
|
||||
void forward_event(nsock_pool nspool, nsock_event nsevent, void *udata) {
|
||||
mspool *nsp = (mspool *)nspool;
|
||||
msevent *nse = (msevent *)nsevent;
|
||||
struct npool *nsp = (struct npool *)nspool;
|
||||
struct nevent *nse = (struct nevent *)nsevent;
|
||||
enum nse_type cached_type;
|
||||
enum nse_status cached_status;
|
||||
|
||||
@@ -436,7 +436,7 @@ void forward_event(nsock_pool nspool, nsock_event nsevent, void *udata) {
|
||||
}
|
||||
|
||||
void nsock_proxy_ev_dispatch(nsock_pool nspool, nsock_event nsevent, void *udata) {
|
||||
msevent *nse = (msevent *)nsevent;
|
||||
struct nevent *nse = (struct nevent *)nsevent;
|
||||
|
||||
if (nse->status == NSE_STATUS_SUCCESS) {
|
||||
struct proxy_node *current;
|
||||
|
||||
@@ -69,11 +69,11 @@
|
||||
nsock_event_id nsock_readlines(nsock_pool nsp, nsock_iod ms_iod,
|
||||
nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, int nlines) {
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "Read request for %d lines from IOD #%li [%s] EID %li",
|
||||
@@ -92,11 +92,11 @@ nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod,
|
||||
nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, int nbytes) {
|
||||
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "Read request for %d bytes from IOD #%li [%s] EID %li",
|
||||
@@ -116,11 +116,11 @@ nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod,
|
||||
nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod,
|
||||
nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata) {
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
mspool *ms = (mspool *)nsp;
|
||||
msevent *nse;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct npool *ms = (struct npool *)nsp;
|
||||
struct nevent *nse;
|
||||
|
||||
nse = msevent_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(ms, NSE_TYPE_READ, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(ms, "Read request from IOD #%li [%s] (timeout: %dms) EID %li",
|
||||
|
||||
@@ -111,7 +111,7 @@ static SSL_CTX *ssl_init_common() {
|
||||
* ciphers but no server certificate verification is done. Returns the SSL_CTX
|
||||
* so you can set your own options. */
|
||||
nsock_ssl_ctx nsp_ssl_init(nsock_pool ms_pool) {
|
||||
mspool *ms = (mspool *)ms_pool;
|
||||
struct npool *ms = (struct npool *)ms_pool;
|
||||
char rndbuf[128];
|
||||
|
||||
if (ms->sslctx == NULL)
|
||||
@@ -153,7 +153,7 @@ nsock_ssl_ctx nsp_ssl_init(nsock_pool ms_pool) {
|
||||
* security. Insecure ciphers are used when they are faster and no certificate
|
||||
* verification is done. Returns the SSL_CTX so you can set your own options. */
|
||||
nsock_ssl_ctx nsp_ssl_init_max_speed(nsock_pool ms_pool) {
|
||||
mspool *ms = (mspool *)ms_pool;
|
||||
struct npool *ms = (struct npool *)ms_pool;
|
||||
char rndbuf[128];
|
||||
|
||||
if (ms->sslctx == NULL)
|
||||
@@ -180,7 +180,7 @@ nsock_ssl_ctx nsp_ssl_init_max_speed(nsock_pool ms_pool) {
|
||||
* SSL object is SSL_VERIFY_NONE, or if OpenSSL is disabled, this function
|
||||
* always returns true. */
|
||||
int nsi_ssl_post_connect_verify(const nsock_iod nsockiod) {
|
||||
msiod *iod = (msiod *)nsockiod;
|
||||
struct niod *iod = (struct niod *)nsockiod;
|
||||
|
||||
assert(iod->ssl != NULL);
|
||||
if (SSL_get_verify_mode(iod->ssl) != SSL_VERIFY_NONE) {
|
||||
|
||||
@@ -65,10 +65,10 @@ extern struct timeval nsock_tod;
|
||||
* course it can also return due to error, cancellation, etc. */
|
||||
nsock_event_id nsock_timer_create(nsock_pool ms_pool, nsock_ev_handler handler,
|
||||
int timeout_msecs, void *userdata) {
|
||||
mspool *nsp = (mspool *)ms_pool;
|
||||
msevent *nse;
|
||||
struct npool *nsp = (struct npool *)ms_pool;
|
||||
struct nevent *nse;
|
||||
|
||||
nse = msevent_new(nsp, NSE_TYPE_TIMER, NULL, timeout_msecs, handler, userdata);
|
||||
nse = event_new(nsp, NSE_TYPE_TIMER, NULL, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nsock_log_info(nsp, "Timer created - %dms from now. EID %li", timeout_msecs,
|
||||
|
||||
@@ -67,16 +67,16 @@
|
||||
|
||||
nsock_event_id nsock_sendto(nsock_pool ms_pool, nsock_iod ms_iod, nsock_ev_handler handler, int timeout_msecs,
|
||||
void *userdata, struct sockaddr *saddr, size_t sslen, unsigned short port, const char *data, int datalen) {
|
||||
mspool *nsp = (mspool *)ms_pool;
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
msevent *nse;
|
||||
struct npool *nsp = (struct npool *)ms_pool;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct nevent *nse;
|
||||
char displaystr[256];
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)saddr;
|
||||
#if HAVE_IPV6
|
||||
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)saddr;
|
||||
#endif
|
||||
|
||||
nse = msevent_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
if (saddr->sa_family == AF_INET) {
|
||||
@@ -129,12 +129,12 @@ nsock_event_id nsock_sendto(nsock_pool ms_pool, nsock_iod ms_iod, nsock_ev_handl
|
||||
* will figure out the length itself */
|
||||
nsock_event_id nsock_write(nsock_pool ms_pool, nsock_iod ms_iod,
|
||||
nsock_ev_handler handler, int timeout_msecs, void *userdata, const char *data, int datalen) {
|
||||
mspool *nsp = (mspool *)ms_pool;
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
msevent *nse;
|
||||
struct npool *nsp = (struct npool *)ms_pool;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct nevent *nse;
|
||||
char displaystr[256];
|
||||
|
||||
nse = msevent_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
nse->writeinfo.dest.ss_family = AF_UNSPEC;
|
||||
@@ -164,9 +164,9 @@ nsock_event_id nsock_write(nsock_pool ms_pool, nsock_iod ms_iod,
|
||||
/* Same as nsock_write except you can use a printf-style format and you can only use this for ASCII strings */
|
||||
nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod,
|
||||
nsock_ev_handler handler, int timeout_msecs, void *userdata, char *format, ...) {
|
||||
mspool *nsp = (mspool *)ms_pool;
|
||||
msiod *nsi = (msiod *)ms_iod;
|
||||
msevent *nse;
|
||||
struct npool *nsp = (struct npool *)ms_pool;
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct nevent *nse;
|
||||
char buf[4096];
|
||||
char *buf2 = NULL;
|
||||
int res, res2;
|
||||
@@ -176,7 +176,7 @@ nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod,
|
||||
va_list ap;
|
||||
va_start(ap,format);
|
||||
|
||||
nse = msevent_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
|
||||
nse = event_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
|
||||
assert(nse);
|
||||
|
||||
res = Vsnprintf(buf, sizeof(buf), format, ap);
|
||||
|
||||
@@ -111,7 +111,7 @@ static void proxy_http_node_delete(struct proxy_node *node) {
|
||||
free(node);
|
||||
}
|
||||
|
||||
static int handle_state_initial(mspool *nsp, msevent *nse, void *udata) {
|
||||
static int handle_state_initial(struct npool *nsp, struct nevent *nse, void *udata) {
|
||||
struct proxy_chain_context *px_ctx = nse->iod->px_ctx;
|
||||
struct sockaddr_storage *ss;
|
||||
size_t sslen;
|
||||
@@ -144,7 +144,7 @@ static int handle_state_initial(mspool *nsp, msevent *nse, void *udata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_state_tcp_connected(mspool *nsp, msevent *nse, void *udata) {
|
||||
static int handle_state_tcp_connected(struct npool *nsp, struct nevent *nse, void *udata) {
|
||||
struct proxy_chain_context *px_ctx = nse->iod->px_ctx;
|
||||
char *res;
|
||||
int reslen;
|
||||
@@ -173,8 +173,8 @@ static int handle_state_tcp_connected(mspool *nsp, msevent *nse, void *udata) {
|
||||
|
||||
static void proxy_http_handler(nsock_pool nspool, nsock_event nsevent, void *udata) {
|
||||
int rc = 0;
|
||||
mspool *nsp = (mspool *)nspool;
|
||||
msevent *nse = (msevent *)nsevent;
|
||||
struct npool *nsp = (struct npool *)nspool;
|
||||
struct nevent *nse = (struct nevent *)nsevent;
|
||||
|
||||
switch (nse->iod->px_ctx->px_state) {
|
||||
case PROXY_STATE_INITIAL:
|
||||
|
||||
@@ -142,7 +142,7 @@ static inline void socks4_data_init(struct socks4_data *socks4,
|
||||
socks4->address = sin->sin_addr.s_addr;
|
||||
}
|
||||
|
||||
static int handle_state_initial(mspool *nsp, msevent *nse, void *udata) {
|
||||
static int handle_state_initial(struct npool *nsp, struct nevent *nse, void *udata) {
|
||||
struct proxy_chain_context *px_ctx = nse->iod->px_ctx;
|
||||
struct sockaddr_storage *ss;
|
||||
size_t sslen;
|
||||
@@ -176,7 +176,7 @@ static int handle_state_initial(mspool *nsp, msevent *nse, void *udata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_state_tcp_connected(mspool *nsp, msevent *nse, void *udata) {
|
||||
static int handle_state_tcp_connected(struct npool *nsp, struct nevent *nse, void *udata) {
|
||||
struct proxy_chain_context *px_ctx = nse->iod->px_ctx;
|
||||
char *res;
|
||||
int reslen;
|
||||
@@ -205,8 +205,8 @@ static int handle_state_tcp_connected(mspool *nsp, msevent *nse, void *udata) {
|
||||
|
||||
static void proxy_socks4_handler(nsock_pool nspool, nsock_event nsevent, void *udata) {
|
||||
int rc = 0;
|
||||
mspool *nsp = (mspool *)nspool;
|
||||
msevent *nse = (msevent *)nsevent;
|
||||
struct npool *nsp = (struct npool *)nspool;
|
||||
struct nevent *nse = (struct nevent *)nsevent;
|
||||
|
||||
switch (nse->iod->px_ctx->px_state) {
|
||||
case PROXY_STATE_INITIAL:
|
||||
|
||||
Reference in New Issue
Block a user