aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-12-18 17:39:16 +0000
committerKim Alvefur <zash@zash.se>2016-12-18 17:39:16 +0000
commit97b80c860af1dd2913f457243f64276a8136b165 (patch)
tree38c96768beb5cab7179be5545399ffc4405e788b /net
parent412505d3c9c5c93c9d55c1a51cb0a4ed8c9e25fd (diff)
downloadprosody-97b80c860af1dd2913f457243f64276a8136b165.tar.gz
prosody-97b80c860af1dd2913f457243f64276a8136b165.zip
server_epoll: Add native support for per socket bandwith limits
Diffstat (limited to 'net')
-rw-r--r--net/server_epoll.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index ccf46928..49ad48ea 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -377,6 +377,14 @@ function interface:onreadable()
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 @@ end
-- 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 @@ function interface:pausefor(t)
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);