int cert_updater_init(ProxyContext * const proxy_context) { CertUpdater *cert_updater = &proxy_context->cert_updater; int ar_options_mask; memset(cert_updater, 0, sizeof *cert_updater); if (ares_library_init(ARES_LIB_INIT_ALL) != ARES_SUCCESS) { return -1; } assert(proxy_context->event_loop != NULL); cert_updater->has_cert_timer = 0; cert_updater->query_retry_step = 0U; ar_options_mask = ARES_OPT_SERVERS; cert_updater->ar_options.nservers = 1; cert_updater->ar_options.servers = &((struct sockaddr_in *) &proxy_context->resolver_addr)->sin_addr; if (proxy_context->tcp_only) { ar_options_mask |= ARES_OPT_FLAGS | ARES_OPT_TCP_PORT; cert_updater->ar_options.flags = ARES_FLAG_USEVC; cert_updater->ar_options.tcp_port = htons(proxy_context->resolver_port); } if (uv_ares_init_options(proxy_context->event_loop, &cert_updater->ar_channel, &cert_updater->ar_options, ar_options_mask) != ARES_SUCCESS) { return -1; } return 0; }
static void prep_tcploopback() { /* for test, use echo server - TCP port TEST_PORT on loopback */ struct sockaddr_in test_server = uv_ip4_addr("127.0.0.1", 0); int rc = 0; optmask = 0; optmask = ARES_OPT_SERVERS | ARES_OPT_TCP_PORT | ARES_OPT_FLAGS; options.servers = &test_server.sin_addr; options.nservers = 1; options.tcp_port = htons(TEST_PORT_2); options.flags = ARES_FLAG_USEVC; rc = uv_ares_init_options(loop, &channel, &options, optmask); ASSERT(rc == ARES_SUCCESS); }
static int DNSResolver_tp_init(DNSResolver *self, PyObject *args, PyObject *kwargs) { int r, optmask; struct ares_options options; Loop *loop; PyObject *servers = NULL; static char *kwlist[] = {"loop", "servers", NULL}; if (self->channel) { PyErr_SetString(PyExc_DNSError, "Object already initialized"); return -1; } if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!|O:__init__", kwlist, &LoopType, &loop, &servers)) { return -1; } Py_INCREF(loop); self->loop = loop; r = ares_library_init(ARES_LIB_INIT_ALL); if (r != 0) { PyErr_SetString(PyExc_DNSError, "error initializing c-ares library"); return -1; } optmask = ARES_OPT_FLAGS; options.flags = ARES_FLAG_USEVC; r = uv_ares_init_options(UV_LOOP(self), &self->channel, &options, optmask); if (r) { PyErr_SetString(PyExc_DNSError, "error c-ares library options"); return -1; } if (servers) { return set_dns_servers(self, servers); } return 0; }
static void prep_tcploopback() { int rc = 0; /* for test, use echo server - TCP port TEST_PORT on loopback */ testsrv.S_un.S_un_b.s_b1 = 127; testsrv.S_un.S_un_b.s_b2 = 0; testsrv.S_un.S_un_b.s_b3 = 0; testsrv.S_un.S_un_b.s_b4 = 1; optmask = ARES_OPT_SERVERS | ARES_OPT_TCP_PORT | ARES_OPT_FLAGS; options.servers = &testsrv; options.nservers = 1; options.tcp_port = htons(TEST_PORT); options.flags = ARES_FLAG_USEVC; rc = uv_ares_init_options(&channel, &options, optmask); ASSERT(rc == ARES_SUCCESS); }
int luvit_init(lua_State *L, uv_loop_t* loop, int argc, char *argv[]) { int index, rc; ares_channel channel; struct ares_options options; luvit__suck_in_symbols(); memset(&options, 0, sizeof(options)); rc = ares_library_init(ARES_LIB_INIT_ALL); assert(rc == ARES_SUCCESS); // Pull up the preload table lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); lua_remove(L, -2); // Register yajl lua_pushcfunction(L, luaopen_yajl); lua_setfield(L, -2, "yajl"); // Register os lua_pushcfunction(L, luaopen_os_binding); lua_setfield(L, -2, "os_binding"); // Register http_parser lua_pushcfunction(L, luaopen_http_parser); lua_setfield(L, -2, "http_parser"); // Register uv lua_pushcfunction(L, luaopen_uv); lua_setfield(L, -2, "uv"); // Register env lua_pushcfunction(L, luaopen_env); lua_setfield(L, -2, "env"); // Register constants lua_pushcfunction(L, luaopen_constants); lua_setfield(L, -2, "constants"); // We're done with preload, put it away lua_pop(L, 1); // Get argv lua_createtable (L, argc, 0); for (index = 0; index < argc; index++) { lua_pushstring (L, argv[index]); lua_rawseti(L, -2, index); } lua_setglobal(L, "argv"); lua_pushcfunction(L, luvit_exit); lua_setglobal(L, "exit_process"); lua_pushcfunction(L, luvit_print_stderr); lua_setglobal(L, "print_stderr"); lua_pushcfunction(L, luvit_getcwd); lua_setglobal(L, "getcwd"); lua_pushstring(L, LUVIT_VERSION); lua_setglobal(L, "VERSION"); lua_pushstring(L, UV_VERSION); lua_setglobal(L, "UV_VERSION"); lua_pushstring(L, LUAJIT_VERSION); lua_setglobal(L, "LUAJIT_VERSION"); lua_pushstring(L, HTTP_VERSION); lua_setglobal(L, "HTTP_VERSION"); lua_pushstring(L, YAJL_VERSIONISH); lua_setglobal(L, "YAJL_VERSION"); // Hold a reference to the main thread in the registry assert(lua_pushthread(L) == 1); lua_setfield(L, LUA_REGISTRYINDEX, "main_thread"); // Store the loop within the registry luv_set_loop(L, loop); // Store the ARES Channel uv_ares_init_options(luv_get_loop(L), &channel, &options, 0); luv_set_ares_channel(L, &channel); return 0; }