bugfix: don't use string.format to concat binary string

This commit is contained in:
Cloud Wu
2014-07-25 21:10:11 +08:00
parent 19e6462376
commit a56b6aa425
3 changed files with 15 additions and 17 deletions

View File

@@ -8,10 +8,9 @@ local fd = assert(socket.connect("127.0.0.1", 8888))
local function send_package(fd, pack)
local size = #pack
local package = string.format("%c%c%s",
bit32.extract(size,8,8),
bit32.extract(size,0,8),
pack)
local package = string.char(bit32.extract(size,8,8)) ..
string.char(bit32.extract(size,0,8))..
pack
socket.send(fd, package)
end

View File

@@ -93,15 +93,13 @@ print("login ok, subid=", subid)
local function send_request(v, session)
local size = #v + 4
local package = string.format("%c%c%s%c%c%c%c",
bit32.extract(size,8,8),
bit32.extract(size,0,8),
v,
bit32.extract(session,24,8),
bit32.extract(session,16,8),
bit32.extract(session,8,8),
bit32.extract(session,0,8)
)
local package = string.char(bit32.extract(size,8,8))..
string.char(bit32.extract(size,0,8))..
v..
string.char(bit32.extract(session,24,8))..
string.char(bit32.extract(session,16,8))..
string.char(bit32.extract(session,8,8))..
string.char(bit32.extract(session,0,8))
socket.send(fd, package)
return v, session
@@ -135,10 +133,9 @@ local readpackage = unpack_f(unpack_package)
local function send_package(fd, pack)
local size = #pack
local package = string.format("%c%c%s",
bit32.extract(size,8,8),
bit32.extract(size,0,8),
pack)
local package = string.char(bit32.extract(size,8,8))..
string.char(bit32.extract(size,0,8))..
pack
socket.send(fd, package)
end

View File

@@ -3,6 +3,8 @@ local socket = require "socket"
local httpd = require "http.httpd"
local sockethelper = require "http.sockethelper"
local urllib = require "http.url"
local table = table
local string = string
local mode = ...