-int do_adns_destroy_resolver(ClientData cd, Tcl_Interp *ip, void *res_v) {
- Resolver *res= res_v;
- tabledataid_disposing(res,&adnstcl_resolvers);
- if (res->ads) adns_finish(res->ads);
- asynch_sethandlers(res,1);
- TFREE(res);
- /* fixme what about outstanding queries */
- /* fixme what about the default resolver */
- /* fixme what if the tcl interpreter gets deleted */
+static Resolver *default_resolver(Tcl_Interp *ip) {
+ return Tcl_GetAssocData(ip,ASSOC_DEFAULTRES,0);
+}
+
+static void destroy_resolver(Tcl_Interp *ip, Resolver *res) {
+ void *query_v;
+ int logstring_len;
+ char *rstr;
+ adns_query aqu;
+
+ if (res == default_resolver(ip))
+ Tcl_DeleteAssocData(ip,ASSOC_DEFAULTRES);
+
+ if (res->errstring_accum) {
+ rstr= Tcl_GetStringFromObj(res->errstring_accum, &logstring_len);
+ assert(rstr);
+ if (logstring_len)
+ adnslogfn_flushmessage(res);
+ }
+
+ if (res->ads) {
+ /* although adns would throw these away for us, we need to
+ * destroy our own data too and only adns has a list of them */
+ for (;;) {
+ adns_forallqueries_begin(res->ads);
+ aqu= adns_forallqueries_next(res->ads, &query_v);
+ if (!aqu) break;
+ asynch_query_dispose(ip, query_v);
+ }
+ adns_finish(res->ads);
+ res->ads= 0;
+ }
+ asynch_cancelhandlers(res);
+ cht_scriptinv_cancel(&res->errcallback);
+ Tcl_EventuallyFree(res, Tcl_Free);
+}
+
+static void destroy_resolver_idtabcb(Tcl_Interp *ip, void *resolver_v) {
+ destroy_resolver(ip,resolver_v);
+}
+static void destroy_resolver_defcb(ClientData resolver_v, Tcl_Interp *ip) {
+ destroy_resolver(ip,resolver_v);
+}
+
+int cht_do_adns_destroy_resolver(ClientData cd, Tcl_Interp *ip, void *res_v) {
+ cht_tabledataid_disposing(ip,res_v,&adnstcl_resolvers);
+ destroy_resolver(ip,res_v);