Comparison

plugins/mod_net_multiplex.lua @ 9465:876171084ea3

mod_net_multiplex: Silence luacheck warnings
author Kim Alvefur <zash@zash.se>
date Wed, 10 Oct 2018 21:56:47 +0200
parent 7807:caf26fc419e9
child 10465:09697a673015
comparison
equal deleted inserted replaced
9464:eacdafd07217 9465:876171084ea3
16 end 16 end
17 end 17 end
18 module:hook("service-added", function (event) add_service(event.service); end); 18 module:hook("service-added", function (event) add_service(event.service); end);
19 module:hook("service-removed", function (event) available_services[event.service] = nil; end); 19 module:hook("service-removed", function (event) available_services[event.service] = nil; end);
20 20
21 for service_name, services in pairs(portmanager.get_registered_services()) do 21 for _, services in pairs(portmanager.get_registered_services()) do
22 for _, service in ipairs(services) do 22 for _, service in ipairs(services) do
23 add_service(service); 23 add_service(service);
24 end 24 end
25 end 25 end
26 26
36 local buf = buffers[conn]; 36 local buf = buffers[conn];
37 buf = buf and buf..data or data; 37 buf = buf and buf..data or data;
38 for service, multiplex_pattern in pairs(available_services) do 38 for service, multiplex_pattern in pairs(available_services) do
39 if buf:match(multiplex_pattern) then 39 if buf:match(multiplex_pattern) then
40 module:log("debug", "Routing incoming connection to %s", service.name); 40 module:log("debug", "Routing incoming connection to %s", service.name);
41 local listener = service.listener; 41 local next_listener = service.listener;
42 conn:setlistener(listener); 42 conn:setlistener(next_listener);
43 local onconnect = listener.onconnect; 43 local onconnect = next_listener.onconnect;
44 if onconnect then onconnect(conn) end 44 if onconnect then onconnect(conn) end
45 return listener.onincoming(conn, buf); 45 return next_listener.onincoming(conn, buf);
46 end 46 end
47 end 47 end
48 if #buf > max_buffer_len then -- Give up 48 if #buf > max_buffer_len then -- Give up
49 conn:close(); 49 conn:close();
50 else 50 else
51 buffers[conn] = buf; 51 buffers[conn] = buf;
52 end 52 end
53 end 53 end
54 54
55 function listener.ondisconnect(conn, err) 55 function listener.ondisconnect(conn)
56 buffers[conn] = nil; -- warn if no buffer? 56 buffers[conn] = nil; -- warn if no buffer?
57 end 57 end
58 58
59 listener.ondetach = listener.ondisconnect; 59 listener.ondetach = listener.ondisconnect;
60 60