Mercurial > prosody-hg
comparison net/server_epoll.lua @ 7658:e14a124c4d73
net.server_epoll: Make minimum poll wait time configurable
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 04 Sep 2016 17:17:22 +0200 |
| parents | 252823632401 |
| children | ae24deae6488 |
comparison
equal
deleted
inserted
replaced
| 7657:252823632401 | 7658:e14a124c4d73 |
|---|---|
| 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 max_wait = 86400; |
| 38 min_wait = 1e-06; | |
| 38 }}; | 39 }}; |
| 39 local cfg = default_config.__index; | 40 local cfg = default_config.__index; |
| 40 | 41 |
| 41 local fds = createtable(10, 0); -- FD -> conn | 42 local fds = createtable(10, 0); -- FD -> conn |
| 42 | 43 |
| 66 return at(gettime() + timeout, f); | 67 return at(gettime() + timeout, f); |
| 67 end | 68 end |
| 68 | 69 |
| 69 -- Run callbacks of expired timers | 70 -- Run callbacks of expired timers |
| 70 -- Return time until next timeout | 71 -- Return time until next timeout |
| 71 local function runtimers(next_delay) | 72 local function runtimers(next_delay, min_wait) |
| 72 -- Any timers at all? | 73 -- Any timers at all? |
| 73 if not timers[1] then | 74 if not timers[1] then |
| 74 return next_delay; | 75 return next_delay; |
| 75 end | 76 end |
| 76 | 77 |
| 102 resort_timers = true; | 103 resort_timers = true; |
| 103 else | 104 else |
| 104 t_remove(timers, i); | 105 t_remove(timers, i); |
| 105 end | 106 end |
| 106 end | 107 end |
| 107 if resort_timers or next_delay < 1e-6 then | 108 |
| 109 if resort_timers or next_delay < min_wait then | |
| 108 -- Timers may be added from within a timer callback. | 110 -- Timers may be added from within a timer callback. |
| 109 -- Those would not be considered for next_delay, | 111 -- Those would not be considered for next_delay, |
| 110 -- and we might sleep for too long, so instead | 112 -- and we might sleep for too long, so instead |
| 111 -- we return a shorter timeout so we can | 113 -- we return a shorter timeout so we can |
| 112 -- properly sort all new timers. | 114 -- properly sort all new timers. |
| 113 next_delay = 1e-6; | 115 next_delay = min_wait; |
| 114 end | 116 end |
| 117 | |
| 115 return next_delay; | 118 return next_delay; |
| 116 end | 119 end |
| 117 | 120 |
| 118 -- Socket handler interface | 121 -- Socket handler interface |
| 119 | 122 |
| 600 end | 603 end |
| 601 | 604 |
| 602 -- Main loop | 605 -- Main loop |
| 603 local function loop() | 606 local function loop() |
| 604 repeat | 607 repeat |
| 605 local t = runtimers(cfg.max_wait); | 608 local t = runtimers(cfg.max_wait, cfg.min_wait); |
| 606 local fd, r, w = epoll.wait(t); | 609 local fd, r, w = epoll.wait(t); |
| 607 if fd then | 610 if fd then |
| 608 local conn = fds[fd]; | 611 local conn = fds[fd]; |
| 609 if conn then | 612 if conn then |
| 610 if r then | 613 if r then |
