Software /
code /
prosody
Changeset
10098:dda1c7ccb209
server_epoll: Add native support for per socket bandwith limits
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 18 Dec 2016 17:39:16 +0000 |
parents | 10097:1f45d316b222 |
children | 10099:7e3196e0263e |
files | net/server_epoll.lua |
diffstat | 1 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/net/server_epoll.lua Sun Jul 28 16:43:47 2019 +0200 +++ b/net/server_epoll.lua Sun Dec 18 17:39:16 2016 +0000 @@ -377,6 +377,14 @@ end end if not self.conn then return; end + if self._limit and (data or partial) then + local cost = self._limit * #(data or partial); + if cost > cfg.min_wait then + self:setreadtimeout(false); + self:pausefor(cost); + return; + end + end if self._wantread and self.conn:dirty() then self:setreadtimeout(false); self:pausefor(cfg.read_retry_delay); @@ -609,6 +617,7 @@ -- Pause connection for some time function interface:pausefor(t) + self:debug("Pause for %fs", t); if self._pausefor then self._pausefor:close(); end @@ -623,6 +632,14 @@ end); end +function interface:setlimit(Bps) + if Bps > 0 then + self._limit = 1/Bps; + else + self._limit = nil; + end +end + function interface:pause_writes() self._write_lock = true; self:setwritetimeout(false);