diff --git a/src/lua/bsdsocket.lua b/src/lua/bsdsocket.lua index ccb579ba5de8d8e9d0045f604c1aec9b51ff1a1a..7795d8d93355cc3fe47d6c8a7e00b3416d210834 100644 --- a/src/lua/bsdsocket.lua +++ b/src/lua/bsdsocket.lua @@ -556,18 +556,24 @@ local function readline_check(self, eols, limit) if string.len(rbuf) == 0 then return nil end + + local shortest for i, eol in pairs(eols) do if string.len(rbuf) >= string.len(eol) then local data = string.match(rbuf, "^(.-" .. eol .. ")") if data ~= nil then if string.len(data) > limit then - return string.sub(data, 1, limit) + data = string.sub(data, 1, limit) + end + if shortest == nil then + shortest = data + elseif #shortest > #data then + shortest = data end - return data end end end - return nil + return shortest end local function readline(self, limit, eol, timeout) @@ -846,6 +852,22 @@ local function getaddrinfo(host, port, timeout, opts) return internal.getaddrinfo(host, port, timeout, ga_opts) end +local soname_mt = { + __tostring = function(si) + if si.host == nil and si.port == nil then + return '' + end + if si.host == nil then + return sprintf('%s:%s', '0', tostring(si.port)) + end + + if si.port == nil then + return sprintf('%s:%', tostring(si.host), 0) + end + return sprintf('%s:%s', tostring(si.host), tostring(si.port)) + end +} + socket_methods.name = function(self) local aka = internal.name(self.fh) if aka == nil then @@ -853,6 +875,7 @@ socket_methods.name = function(self) return nil end self._errno = nil + setmetatable(aka, soname_mt) return aka end @@ -863,6 +886,7 @@ socket_methods.peer = function(self) return nil end self._errno = nil + setmetatable(peer, soname_mt) return peer end diff --git a/src/lua/init.cc b/src/lua/init.cc index d15539dce897e9d08737f7abbbd786a148f9bf78..0c4b224838aa240565565eca7ffb1b8dd3e4d979 100644 --- a/src/lua/init.cc +++ b/src/lua/init.cc @@ -232,6 +232,8 @@ tarantool_lua_setpaths(struct lua_State *L) const char *home = getenv("HOME"); lua_getglobal(L, "package"); int top = lua_gettop(L); + lua_pushliteral(L, "./?.lua;"); + lua_pushliteral(L, "./?/init.lua;"); if (home != NULL) { lua_pushstring(L, home); lua_pushliteral(L, "/.luarocks/share/lua/5.1/?.lua;"); @@ -247,6 +249,7 @@ tarantool_lua_setpaths(struct lua_State *L) lua_concat(L, lua_gettop(L) - top); lua_setfield(L, top, "path"); + lua_pushliteral(L, "./?.so;"); if (home != NULL) { lua_pushstring(L, home); lua_pushliteral(L, "/.luarocks/lib/lua/5.1/?.so;"); diff --git a/src/lua/msgpackffi.lua b/src/lua/msgpackffi.lua index 3293d269880032abdc0da2b01443e8c07ff8c8d9..60ba70874aa5600ed838c76d028b379218f58533 100644 --- a/src/lua/msgpackffi.lua +++ b/src/lua/msgpackffi.lua @@ -5,6 +5,7 @@ local builtin = ffi.C local MAXNESTING = 16 local NULL = ffi.cast('void *', 0) +local uint8_ptr_t = ffi.typeof('uint8_t *') local uint16_ptr_t = ffi.typeof('uint16_t *') local uint32_ptr_t = ffi.typeof('uint32_t *') local uint64_ptr_t = ffi.typeof('uint64_t *') diff --git a/test/big/iterator.result b/test/big/iterator.result index 1ac42d9c72724e14e83121cc724451442a447587..f2dbdf1dcfd95da5eaeec6992a3dff36338ba9f2 100644 --- a/test/big/iterator.result +++ b/test/big/iterator.result @@ -891,7 +891,7 @@ space.index['primary']:pairs({}, {iterator = -666 }) -- Test cases for #123: box.index.count does not check arguments properly space.index['primary']:pairs(function() end, { iterator = box.index.EQ }) --- -- error: 'builtin/msgpackffi.lua:258: can not encode Lua type: ''function''' +- error: 'builtin/msgpackffi.lua:259: can not encode Lua type: ''function''' ... -- Check that iterators successfully invalidated when index deleted gen, param, state = space.index['i1']:pairs(nil, { iterator = box.index.GE }) @@ -941,18 +941,14 @@ gen, param, state = space.index.t1:pairs({}, {iterator = box.index.ALL}) print(gen(param, state)) --- ... -id = s.index.t1.id +id = space.index.t1.id --- -- error: '[string "id = s.index.t1.id "]:1: attempt to index field ''t1'' (a nil value)' ... -box.schema.index.drop(s.id, id) +box.schema.index.drop(space.id, id) --- -- error: Illegal parameters, index_id should be a number ... -box.schema.index.alter(s.id, s.index.t2.id, {id = id}) +box.schema.index.alter(space.id, space.index.t2.id, {id = id}) --- -- error: '[string "return box.schema.index.alter(s.id, s.index.t..."]:1: attempt to - index field ''t2'' (a nil value)' ... print(gen(param, state)) --- diff --git a/test/big/iterator.test.lua b/test/big/iterator.test.lua index 02cfccf994bcac0622c67d2df26f11d2c2ed0677..d98feee2b5327a801948c9bb2a46d2ad94d81444 100644 --- a/test/big/iterator.test.lua +++ b/test/big/iterator.test.lua @@ -186,9 +186,9 @@ box.space.test:insert{1} gen, param, state = space.index.t1:pairs({}, {iterator = box.index.ALL}) print(gen(param, state)) -id = s.index.t1.id -box.schema.index.drop(s.id, id) -box.schema.index.alter(s.id, s.index.t2.id, {id = id}) +id = space.index.t1.id +box.schema.index.drop(space.id, id) +box.schema.index.alter(space.id, space.index.t2.id, {id = id}) print(gen(param, state)) diff --git a/test/big/lua.result b/test/big/lua.result index f3c93cd1a55f619d6db16ae560bd582178058a8a..cea6b56c9de61895d69171656ad9e580b3d2f67c 100644 --- a/test/big/lua.result +++ b/test/big/lua.result @@ -574,7 +574,7 @@ space.index['i1']:count() -- Test cases for #123: box.index.count does not check arguments properly space.index['i1']:count(function() end) --- -- error: 'builtin/msgpackffi.lua:258: can not encode Lua type: ''function''' +- error: 'builtin/msgpackffi.lua:259: can not encode Lua type: ''function''' ... space:drop() --- diff --git a/test/box/bsdsocket.result b/test/box/bsdsocket.result index a1443a1f7c75967785d3aede83d33a1525b9dead..2bd743400646fa1f37113ac80c07234452c8be02 100644 --- a/test/box/bsdsocket.result +++ b/test/box/bsdsocket.result @@ -642,6 +642,14 @@ json.encode(sc:name()) --- - '{"host":"0.0.0.0","family":"AF_INET","type":"SOCK_STREAM","protocol":"tcp","port":0}' ... +sc:name() +--- +- host: 0.0.0.0 + family: AF_INET + type: SOCK_STREAM + protocol: tcp + port: 0 +... sc:nonblock(true) --- - true @@ -1207,3 +1215,48 @@ os.remove(path) --- - true ... +longstring = string.rep("abc", 65535) +--- +... +server = socket.tcp_server('unix/', path, function(s) s:write(longstring) end) +--- +... +client = socket.tcp_connect('unix/', path) +--- +... +client:read(#longstring) == longstring +--- +- true +... +client = socket.tcp_connect('unix/', path) +--- +... +client:read(#longstring + 1) == longstring +--- +- true +... +client = socket.tcp_connect('unix/', path) +--- +... +client:read(#longstring - 1) == string.sub(longstring, 1, #longstring - 1) +--- +- true +... +longstring = "Hello\r\n\r\nworld\n\n" +--- +... +client = socket.tcp_connect('unix/', path) +--- +... +client:read{ line = { "\n\n", "\r\n\r\n" } } +--- +- "Hello\r\n\r\n" +... +server:stop() +--- +- true +... +os.remove(path) +--- +- true +... diff --git a/test/box/bsdsocket.test.lua b/test/box/bsdsocket.test.lua index 1d51a54a7a2b01499f2bde878b73478597871901..8a78cea3edce78e81f6639e0c3bcc80daeefab1e 100644 --- a/test/box/bsdsocket.test.lua +++ b/test/box/bsdsocket.test.lua @@ -205,6 +205,7 @@ json.encode(socket.getaddrinfo('ya.ru', '80', sc = socket('AF_INET', 'SOCK_STREAM', 'tcp') json.encode(sc:name()) +sc:name() sc:nonblock(true) sc:close() @@ -390,17 +391,36 @@ os.remove(path) server = socket.tcp_server('unix/', path, function(s) s:write('Hello, world') end) - server ~= nil - fiber.sleep(.5) +client = socket.tcp_connect('unix/', path) +client ~= nil +client:read(123) +server:stop() +os.remove(path) + + +longstring = string.rep("abc", 65535) +server = socket.tcp_server('unix/', path, function(s) s:write(longstring) end) client = socket.tcp_connect('unix/', path) +client:read(#longstring) == longstring -client ~= nil +client = socket.tcp_connect('unix/', path) +client:read(#longstring + 1) == longstring -client:read(123) +client = socket.tcp_connect('unix/', path) +client:read(#longstring - 1) == string.sub(longstring, 1, #longstring - 1) -server:stop() +longstring = "Hello\r\n\r\nworld\n\n" + +client = socket.tcp_connect('unix/', path) +client:read{ line = { "\n\n", "\r\n\r\n" } } + + +server:stop() os.remove(path) + + + diff --git a/test/box/msgpack.result b/test/box/msgpack.result index 7d3d684d31046da475517c9c7fa77c30ba5e4597..e09b2b99fbe105248c9e45cbd70822338053dd48 100644 --- a/test/box/msgpack.result +++ b/test/box/msgpack.result @@ -672,5 +672,5 @@ offset ... a, offset = msgpackffi.decode_unchecked(dump, offset) --- -- error: 'builtin/msgpackffi.lua:457: offset = 9 is out of bounds [1..8]' +- error: 'builtin/msgpackffi.lua:458: offset = 9 is out of bounds [1..8]' ... diff --git a/test/lib/app_server.py b/test/lib/app_server.py index 22793a5c80a8b01188ed22b6f9cc13cd83a1c814..08ecf66dee858adc30fb1c506580c99cd663dd6b 100644 --- a/test/lib/app_server.py +++ b/test/lib/app_server.py @@ -11,8 +11,8 @@ from lib.tarantool_server import Test class AppTest(Test): def execute(self, server): - execs = [os.path.join(os.path.abspath(server.builddir), "test", self.name)] - proc = Popen(execs, stdout=PIPE, cwd=server.vardir) + execs = [] + proc = Popen([os.path.join(os.getcwd(), self.name)], stdout=PIPE, cwd=server.vardir) sys.stdout.write(proc.communicate()[0]) class AppServer(Server): @@ -60,8 +60,7 @@ class AppServer(Server): answer.append(test) return answer - test_suite.tests = [AppTest(k, test_suite.args, test_suite.ini) for - k in sorted(glob.glob(os.path.join(suite_path, "*.test.lua" )))] + test_suite.tests = [AppTest(k, test_suite.args, test_suite.ini) for k in sorted(glob.glob(os.path.join(suite_path, "*.test.lua" )))] test_suite.tests = sum(map((lambda x: patterned(x, test_suite.args.tests)), test_suite.tests), []) def print_log(self, lines):