Changeset

11252:ba335004ca60

net.unbound: Move libunbound initialization into a function Prepare for lazy-loading it.
author Kim Alvefur <zash@zash.se>
date Tue, 05 Jan 2021 21:36:04 +0100
parents 11251:520b09bbbad5
children 11253:919e7b962f0b
files net/unbound.lua
diffstat 1 files changed, 7 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/net/unbound.lua	Tue Jan 05 21:04:06 2021 +0100
+++ b/net/unbound.lua	Tue Jan 05 21:36:04 2021 +0100
@@ -54,9 +54,13 @@
 	end);
 end
 
-local unbound = libunbound.new(unbound_config);
+local unbound, server_conn;
 
-local server_conn = connect_server(unbound, net_server);
+local function initialize()
+	unbound = libunbound.new(unbound_config);
+	server_conn = connect_server(unbound, net_server);
+end
+initialize();
 
 local answer_mt = {
 	__tostring = function(self)
@@ -154,8 +158,7 @@
 local function purge()
 	for id in pairs(waiting_queries) do cancel(id); end
 	if server_conn then server_conn:close(); end
-	unbound = libunbound.new(unbound_config);
-	server_conn = connect_server(unbound, net_server);
+	initialize();
 	return true;
 end