comparison plugins/mod_net_multiplex.lua @ 11024:1c7602c70d1f

mod_net_multiplex: Set read size/mode to that of the target listener Otherwise it would use the configured buffer size, or previously '*a'. Using the read size set by the listener seems more sensible.
author Kim Alvefur <zash@zash.se>
date Sun, 02 Aug 2020 00:24:54 +0200
parents a59b37b03eca
children 74b9e05af71e
comparison
equal deleted inserted replaced
11023:a59b37b03eca 11024:1c7602c70d1f
1 module:set_global(); 1 module:set_global();
2 2
3 local array = require "util.array"; 3 local array = require "util.array";
4 local max_buffer_len = module:get_option_number("multiplex_buffer_size", 1024); 4 local max_buffer_len = module:get_option_number("multiplex_buffer_size", 1024);
5 local default_mode = module:get_option_number("network_default_read_size", 4096);
5 6
6 local portmanager = require "core.portmanager"; 7 local portmanager = require "core.portmanager";
7 8
8 local available_services = {}; 9 local available_services = {};
9 local service_by_protocol = {}; 10 local service_by_protocol = {};
50 local service = service_by_protocol[selected_proto]; 51 local service = service_by_protocol[selected_proto];
51 if service then 52 if service then
52 module:log("debug", "Routing incoming connection to %s based on ALPN %q", service.name, selected_proto); 53 module:log("debug", "Routing incoming connection to %s based on ALPN %q", service.name, selected_proto);
53 local next_listener = service.listener; 54 local next_listener = service.listener;
54 conn:setlistener(next_listener); 55 conn:setlistener(next_listener);
56 conn:set_mode(next_listener.default_mode or default_mode);
55 local onconnect = next_listener.onconnect; 57 local onconnect = next_listener.onconnect;
56 if onconnect then return onconnect(conn) end 58 if onconnect then return onconnect(conn) end
57 end 59 end
58 end 60 end
59 end 61 end
65 for service, multiplex_pattern in pairs(available_services) do 67 for service, multiplex_pattern in pairs(available_services) do
66 if buf:match(multiplex_pattern) then 68 if buf:match(multiplex_pattern) then
67 module:log("debug", "Routing incoming connection to %s", service.name); 69 module:log("debug", "Routing incoming connection to %s", service.name);
68 local next_listener = service.listener; 70 local next_listener = service.listener;
69 conn:setlistener(next_listener); 71 conn:setlistener(next_listener);
72 conn:set_mode(next_listener.default_mode or default_mode);
70 local onconnect = next_listener.onconnect; 73 local onconnect = next_listener.onconnect;
71 if onconnect then onconnect(conn) end 74 if onconnect then onconnect(conn) end
72 return next_listener.onincoming(conn, buf); 75 return next_listener.onincoming(conn, buf);
73 end 76 end
74 end 77 end