aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2013-01-06 04:55:53 +0500
committerWaqas Hussain <waqas20@gmail.com>2013-01-06 04:55:53 +0500
commite5537b580ca4ed18aed65b3db419695ec5befd5b (patch)
treee4d002016c7278c449d35650e590b4a87718b108
parent7dfcd3b6d48a94c2004353bd26da730d29a7509b (diff)
downloadprosody-e5537b580ca4ed18aed65b3db419695ec5befd5b.tar.gz
prosody-e5537b580ca4ed18aed65b3db419695ec5befd5b.zip
net.server_event: Optimize socket write buffers (don't do buf=buf..newdata).
-rw-r--r--net/server_event.lua14
1 files changed, 9 insertions, 5 deletions
diff --git a/net/server_event.lua b/net/server_event.lua
index e69530ff..08926939 100644
--- a/net/server_event.lua
+++ b/net/server_event.lua
@@ -40,6 +40,9 @@ local tostring = use "tostring"
local coroutine = use "coroutine"
local setmetatable = use "setmetatable"
+local t_insert = table.insert
+local t_concat = table.concat
+
local ssl = use "ssl"
local socket = use "socket" or require "socket"
@@ -309,7 +312,7 @@ do
debug( "error:", err ) -- to much, check your app
return nil, err
end
- self.writebuffer = self.writebuffer .. data -- new buffer
+ t_insert(self.writebuffer, data) -- new buffer
self.writebufferlen = total
if not self.eventwrite then -- register new write event
--vdebug( "register new write event" )
@@ -466,7 +469,7 @@ do
type = "client";
conn = client;
currenttime = socket_gettime( ); -- safe the origin
- writebuffer = ""; -- writebuffer
+ writebuffer = {}; -- writebuffer
writebufferlen = 0; -- length of writebuffer
send = client.send; -- caching table lookups
receive = client.receive;
@@ -520,10 +523,11 @@ do
interface.eventwritetimeout = false
end
end
- local succ, err, byte = interface.conn:send( interface.writebuffer, 1, interface.writebufferlen )
+ interface.writebuffer = { t_concat(interface.writebuffer) }
+ local succ, err, byte = interface.conn:send( interface.writebuffer[1], 1, interface.writebufferlen )
--vdebug( "write data:", interface.writebuffer, "error:", err, "part:", byte )
if succ then -- writing succesful
- interface.writebuffer = ""
+ interface.writebuffer[1] = nil
interface.writebufferlen = 0
interface:ondrain();
if interface.fatalerror then
@@ -539,7 +543,7 @@ do
return -1
elseif byte and (err == "timeout" or err == "wantwrite") then -- want write again
--vdebug( "writebuffer is not empty:", err )
- interface.writebuffer = string_sub( interface.writebuffer, byte + 1, interface.writebufferlen ) -- new buffer
+ interface.writebuffer[1] = string_sub( interface.writebuffer[1], byte + 1, interface.writebufferlen ) -- new buffer
interface.writebufferlen = interface.writebufferlen - byte
if "wantread" == err then -- happens only with luasec
local callback = function( )