Comparison

net/server_epoll.lua @ 7623:a1c040a5754f

net.server_epoll: Make maximum wait time configurable
author Kim Alvefur <zash@zash.se>
date Mon, 22 Aug 2016 17:12:58 +0200
parent 7606:f40f1d9b7872
child 7624:23fb3a084956
comparison
equal deleted inserted replaced
7622:96e6df712359 7623:a1c040a5754f
32 tcp_backlog = 128; 32 tcp_backlog = 128;
33 accept_retry_interval = 10; 33 accept_retry_interval = 10;
34 read_retry_delay = 1e-06; 34 read_retry_delay = 1e-06;
35 connect_timeout = 20; 35 connect_timeout = 20;
36 handshake_timeout = 60; 36 handshake_timeout = 60;
37 max_wait = 86400;
37 }; 38 };
38 39
39 local fds = createtable(10, 0); -- FD -> conn 40 local fds = createtable(10, 0); -- FD -> conn
40 local timers = {}; 41 local timers = {};
41 42
61 return at(gettime() + timeout, f); 62 return at(gettime() + timeout, f);
62 end 63 end
63 64
64 -- Run callbacks of expired timers 65 -- Run callbacks of expired timers
65 -- Return time until next timeout 66 -- Return time until next timeout
66 local function runtimers() 67 local function runtimers(next_delay)
67 if resort_timers then 68 if resort_timers then
68 -- Sort earliest timers to the end 69 -- Sort earliest timers to the end
69 t_sort(timers, function (a, b) return a[1] > b[1]; end); 70 t_sort(timers, function (a, b) return a[1] > b[1]; end);
70 resort_timers = false; 71 resort_timers = false;
71 end 72 end
77 else 78 else
78 break; 79 break;
79 end 80 end
80 end 81 end
81 --]] 82 --]]
82
83 local next_delay = 86400;
84 83
85 -- Iterate from the end and remove completed timers 84 -- Iterate from the end and remove completed timers
86 for i = #timers, 1, -1 do 85 for i = #timers, 1, -1 do
87 local timer = timers[i]; 86 local timer = timers[i];
88 local t, f = timer[1], timer[2]; 87 local t, f = timer[1], timer[2];
577 quitting = "quitting"; 576 quitting = "quitting";
578 end 577 end
579 578
580 local function loop() 579 local function loop()
581 repeat 580 repeat
582 local t = runtimers(); 581 local t = runtimers(cfg.max_wait);
583 local fd, r, w = epoll.wait(t); 582 local fd, r, w = epoll.wait(t);
584 if fd then 583 if fd then
585 local conn = fds[fd]; 584 local conn = fds[fd];
586 if conn then 585 if conn then
587 if r then 586 if r then