Comparison

mod_websocket/mod_websocket.lua @ 1025:b56a9aa171b3

mod_websocket: Fix length calculation
author Florian Zeitz <florob@babelmonkeys.de>
date Thu, 30 May 2013 22:48:19 +0200
parent 969:8eba9d4809d2
child 1026:e254cf49e14d
comparison
equal deleted inserted replaced
1024:d7655e634c30 1025:b56a9aa171b3
105 result = result .. string.char(length); 105 result = result .. string.char(length);
106 elseif length <= 0xFFFF then -- 2-byte length 106 elseif length <= 0xFFFF then -- 2-byte length
107 result = result .. string.char(126); 107 result = result .. string.char(126);
108 result = result .. string.char(rshift(length, 8)) .. string.char(length%0x100); 108 result = result .. string.char(rshift(length, 8)) .. string.char(length%0x100);
109 else -- 8-byte length 109 else -- 8-byte length
110 local length_bytes = {};
110 result = result .. string.char(127); 111 result = result .. string.char(127);
111 for i = 7, 0, -1 do 112 for i = 8, 1, -1 do
112 result = result .. string.char(rshift(length, 8*i) % 0x100); 113 length_bytes[i] = string.char(length % 0x100);
113 end 114 length = rshift(length, 8);
115 end
116 result = result .. table.concat(length_bytes, "");
114 end 117 end
115 118
116 result = result .. data; 119 result = result .. data;
117 120
118 return result; 121 return result;