Mercurial > prosody-hg
comparison net/server_event.lua @ 5018:eb8211b65e96
net.server_event: Replace usage of string.len() with # operator
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 26 Jul 2012 16:46:18 +0100 |
| parents | 2f8f388de516 |
| children | 8a207a7e52d3 |
comparison
equal
deleted
inserted
replaced
| 5017:a6bae9d72c8f | 5018:eb8211b65e96 |
|---|---|
| 113 do | 113 do |
| 114 interface_mt = {}; interface_mt.__index = interface_mt; | 114 interface_mt = {}; interface_mt.__index = interface_mt; |
| 115 | 115 |
| 116 local addevent = base.addevent | 116 local addevent = base.addevent |
| 117 local coroutine_wrap, coroutine_yield = coroutine.wrap,coroutine.yield | 117 local coroutine_wrap, coroutine_yield = coroutine.wrap,coroutine.yield |
| 118 local string_len = string.len | |
| 119 | 118 |
| 120 -- Private methods | 119 -- Private methods |
| 121 function interface_mt:_position(new_position) | 120 function interface_mt:_position(new_position) |
| 122 self.position = new_position or self.position | 121 self.position = new_position or self.position |
| 123 return self.position; | 122 return self.position; |
| 308 -- Public methods | 307 -- Public methods |
| 309 function interface_mt:write(data) | 308 function interface_mt:write(data) |
| 310 if self.nowriting then return nil, "locked" end | 309 if self.nowriting then return nil, "locked" end |
| 311 --vdebug( "try to send data to client, id/data:", self.id, data ) | 310 --vdebug( "try to send data to client, id/data:", self.id, data ) |
| 312 data = tostring( data ) | 311 data = tostring( data ) |
| 313 local len = string_len( data ) | 312 local len = #data |
| 314 local total = len + self.writebufferlen | 313 local total = len + self.writebufferlen |
| 315 if total > cfg.MAX_SEND_LENGTH then -- check buffer length | 314 if total > cfg.MAX_SEND_LENGTH then -- check buffer length |
| 316 local err = "send buffer exceeded" | 315 local err = "send buffer exceeded" |
| 317 debug( "error:", err ) -- to much, check your app | 316 debug( "error:", err ) -- to much, check your app |
| 318 return nil, err | 317 return nil, err |
