Comparison

mod_component_client/mod_component_client.lua @ 1214:a234ad611633

mod_component_client: Add config option component_client.keepalive_interval (default is one hour: 3600).
author Waqas Hussain <waqas20@gmail.com>
date Thu, 24 Oct 2013 11:52:58 -0400
parent 1210:be5334e3f6ca
child 1216:81a3bf8aba90
comparison
equal deleted inserted replaced
1213:544f5a4a8428 1214:a234ad611633
35 local config = module:get_option("component_client", {}); 35 local config = module:get_option("component_client", {});
36 local server_host = config.host or "localhost"; 36 local server_host = config.host or "localhost";
37 local server_port = config.port or 5347; 37 local server_port = config.port or 5347;
38 local server_secret = config.secret or error("client_component.secret not provided"); 38 local server_secret = config.secret or error("client_component.secret not provided");
39 local exit_on_disconnect = config.exit_on_disconnect; 39 local exit_on_disconnect = config.exit_on_disconnect;
40 local keepalive_interval = config.keepalive_interval or 3600;
40 41
41 local __conn; 42 local __conn;
42 43
43 local listener = {}; 44 local listener = {};
44 local session; 45 local session;
216 if exit_on_disconnect then 217 if exit_on_disconnect then
217 prosody.shutdown("Shutdown by component_client disconnect"); 218 prosody.shutdown("Shutdown by component_client disconnect");
218 end 219 end
219 end 220 end
220 221
222 -- send whitespace keep-alive one an hour
223 if keepalive_interval ~= 0 then
224 module:add_timer(keepalive_interval, function()
225 if __conn then
226 __conn:write(" ");
227 end
228 return keepalive_interval;
229 end);
230 end
231
221 function connect() 232 function connect()
222 ------------------------ 233 ------------------------
223 -- Taken from net.http 234 -- Taken from net.http
224 local conn = socket.tcp ( ) 235 local conn = socket.tcp ( )
225 conn:settimeout ( 10 ) 236 conn:settimeout ( 10 )