diff --git a/src/lua/bsdsocket.lua b/src/lua/bsdsocket.lua index b88c0cf56179c5167a18b775879001ceeef5cdf5..67d5f9f60106ca47f2f6894aa96b3e1af588361f 100644 --- a/src/lua/bsdsocket.lua +++ b/src/lua/bsdsocket.lua @@ -826,7 +826,7 @@ local function getaddrinfo(host, port, timeout, opts) if opts.type ~= nil then local itype = get_ivalue(internal.SO_TYPE, opts.type) if itype == nil then - self._errno = box.errno.EINVAL + box.errno(box.errno.EINVAL) return nil end ga_opts.type = itype @@ -835,7 +835,7 @@ local function getaddrinfo(host, port, timeout, opts) if opts.family ~= nil then local ifamily = get_ivalue(internal.DOMAIN, opts.family) if ifamily == nil then - self._errno = box.errno.EINVAL + box.errno(box.errno.EINVAL) return nil end ga_opts.family = ifamily @@ -844,7 +844,7 @@ local function getaddrinfo(host, port, timeout, opts) if opts.protocol ~= nil then local p = ffi.C.getprotobyname(opts.protocol) if p == nil then - self._errno = box.errno(box.errno.EINVAL) + box.errno(box.errno.EINVAL) return nil end ga_opts.protocol = p.p_proto @@ -854,20 +854,14 @@ local function getaddrinfo(host, port, timeout, opts) ga_opts.flags = get_iflags(internal.AI_FLAGS, opts.flags) if ga_opts.flags == nil then - self._errno = box.errno() + box.errno(box.errno.EINVAL) return nil end end end - local r = internal.getaddrinfo(host, port, timeout, ga_opts) - if r == nil then - self._errno = box.errno() - else - self._errno = nil - end - return r + return internal.getaddrinfo(host, port, timeout, ga_opts) end local soname_mt = { diff --git a/test/box/bsdsocket.result b/test/box/bsdsocket.result index 144966a65f22feefc86b80caedd52d2ae9b5f03f..9f0b5a15c4cb434bba7c7dbee7151cd665a85d0b 100644 --- a/test/box/bsdsocket.result +++ b/test/box/bsdsocket.result @@ -1187,3 +1187,19 @@ lua box.cjson.encode{ box.socket.tcp_connect('test:test@localhost:3303') == nil, --- - [true,"Invalid argument"] ... +lua box.socket.getaddrinfo('host', 'port', { type = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL +--- + - true +... +lua box.socket.getaddrinfo('host', 'port', { family = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL +--- + - true +... +lua box.socket.getaddrinfo('host', 'port', { protocol = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL +--- + - true +... +lua box.socket.getaddrinfo('host', 'port', { flags = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL +--- + - true +... diff --git a/test/box/bsdsocket.test b/test/box/bsdsocket.test index 194f7e5edf76023e56dc546bc1bb997ac99ed433..72907dbbf9d9220d05ce2d2892601e1301adff87 100644 --- a/test/box/bsdsocket.test +++ b/test/box/bsdsocket.test @@ -388,3 +388,9 @@ if os.path.exists(path): exec admin "lua box.cjson.encode{ box.socket.tcp_connect('test:test@localhost:3303') == nil, box.errno.strerror() }" + + +exec admin "lua box.socket.getaddrinfo('host', 'port', { type = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL" +exec admin "lua box.socket.getaddrinfo('host', 'port', { family = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL" +exec admin "lua box.socket.getaddrinfo('host', 'port', { protocol = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL" +exec admin "lua box.socket.getaddrinfo('host', 'port', { flags = 'WRONG' }) == nil and box.errno() == box.errno.EINVAL"