aboutsummaryrefslogtreecommitdiffstats
path: root/net/server_epoll.lua
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
commit5c48dbda51bac9bf58dff9be6bc19524734ac42a (patch)
tree38c96768beb5cab7179be5545399ffc4405e788b /net/server_epoll.lua
parent715cc27ea2fca89c7999bb0499c6a9e624c282d7 (diff)
downloadprosody-5c48dbda51bac9bf58dff9be6bc19524734ac42a.tar.gz
prosody-5c48dbda51bac9bf58dff9be6bc19524734ac42a.zip
server_epoll: Add native support for per socket bandwith limits
Diffstat (limited to 'net/server_epoll.lua')
-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);