static LRESULT CALLBACK windowProcedure(HWND window_handle, UINT message, WPARAM w_param, LPARAM l_param) { switch (message) { case KTL_WM_THREAD_CALLBACK: while (call_one()) ; return 0; } return ::DefWindowProc(window_handle, message, w_param, l_param); }
static int call_modgroup(int component, modgroup *g, REQUEST *request, int default_result) { int myresult = default_result; int priority = 0; /* default result has lowest priority */ modcallable *p; /* * Catch people who have issues. */ if (!g->children) { DEBUG2(" WARNING! Asked to process empty group. Returning %s.", lrad_int2str(rcode_table, myresult, "??")); return default_result; } /* Loop over the children */ for (p = g->children; p; p = p->next) { if (!call_one(component, p, request, &priority, &myresult)) { break; } } return myresult; }
/* * For more than 2 modules with redundancy + load balancing * across all of them, layering the "redundant" and * "load-balance" groups gets too complicated. As a result, we * implement a special function to do this. */ static int call_modredundantloadbalance(int component, modgroup *g, REQUEST *request, int default_result) { int count = 1; int myresult = default_result; int priority = 0; /* default result has lowest priority */ modcallable *p, *child = NULL; /* * Catch people who have issues. */ if (!g->children) { DEBUG2(" WARNING! Asked to process empty redundant-load-balance group. Returning %s.", lrad_int2str(rcode_table, default_result, "??")); return default_result; } /* * Pick a random child. */ /* Loop over the children */ for(p = g->children; p; p = p->next) { if (!child) { child = p; count = 1; continue; } /* * Keep track of how many load balancing servers * we've gone through. */ count++; /* * See the "camel book" for why this works. * * If (rand(0..n) < 1), pick the current realm. * We add a scale factor of 65536, to avoid * floating point. */ if ((count * (lrad_rand() & 0xffff)) < (uint32_t) 0x10000) { child = p; } } rad_assert(child != NULL); /* * Call the chosen child, with fail-over to the next one * if it is down. */ p = child; do { /* * Call the chosen entry. If we're done, then * stop. */ if (!call_one(component, p, request, &priority, &myresult)) { break; } /* * Go to the next one, and wrap around to the beginning if * we reach the end. */ p = p->next; if (!p) p = g->children; } while (p != child); /* * And return whatever was decided. */ return myresult; }