diff --git a/src/lua/bsdsocket.cc b/src/lua/bsdsocket.cc index 6f0cff9ca94a876b26214b724ee7c8f854c1f89a..8fb9e8ab3ea2987bcf1a69b323a9866f61a1e857 100644 --- a/src/lua/bsdsocket.cc +++ b/src/lua/bsdsocket.cc @@ -533,6 +533,11 @@ lbox_bsdsocket_push_family(struct lua_State *L, int family) static int lbox_bsdsocket_push_protocol(struct lua_State *L, int protonumber) { + if (protonumber == 0) { + lua_pushinteger(L, 0); + return 1; + } + struct protoent *p = getprotobynumber(protonumber); if (p) { lua_pushstring(L, p->p_name); diff --git a/src/lua/bsdsocket.lua b/src/lua/bsdsocket.lua index 797220e80fe83aaf30c6ca55fc016a1d74e7cd52..d753cc7531a1eef71c40e8e8efc0e5f0efedac16 100644 --- a/src/lua/bsdsocket.lua +++ b/src/lua/bsdsocket.lua @@ -963,7 +963,7 @@ end local function tcp_connect(host, port, timeout) if host == 'unix/' then - return tcp_connect_remote({ host = host, port = port, protocol = 'ip', + return tcp_connect_remote({ host = host, port = port, protocol = 0, family = 'PF_UNIX', type = 'SOCK_STREAM' }, timeout) end local timeout = timeout or TIMEOUT_INFINITY diff --git a/test/box/bsdsocket.result b/test/box/bsdsocket.result index 6e32dc74f344577663d77a1a4d86adaa7b30b3ea..929b9920b6e1837a948610f8d18db6d1b4ebe42e 100644 --- a/test/box/bsdsocket.result +++ b/test/box/bsdsocket.result @@ -445,7 +445,7 @@ lua sc:close() --- - true ... -lua s = box.socket('PF_UNIX', 'SOCK_STREAM', 'ip') +lua s = box.socket('PF_UNIX', 'SOCK_STREAM', 0) --- ... lua s:setsockopt('SOL_SOCKET', 'SO_REUSEADDR', true) @@ -480,7 +480,7 @@ lua s:listen(1234) --- - true ... -lua sc = box.socket('PF_UNIX', 'SOCK_STREAM', 'ip') +lua sc = box.socket('PF_UNIX', 'SOCK_STREAM', 0) --- ... lua sc:nonblock(true) @@ -784,7 +784,7 @@ lua box.socket.tcp_connect('127.0.0.1', 35490), box.errno() == box.errno.ECONNRE - nil - true ... -lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 'ip') +lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 0) --- ... lua s:bind('unix/', '/tmp/tarantool-test-socket') @@ -807,10 +807,6 @@ lua sc ~= nil --- - true ... -lua errno == 0 ---- - - true -... lua sc:close() --- - true @@ -886,7 +882,7 @@ lua s:error() lua path = '/tmp/tarantool-test-socket' --- ... -lua s = box.socket('PF_UNIX', 'SOCK_STREAM', 'ip') +lua s = box.socket('PF_UNIX', 'SOCK_STREAM', 0) --- ... lua s:setsockopt('SOL_SOCKET', 'SO_REUSEADDR', true) @@ -1188,7 +1184,7 @@ lua server:close() --- - true ... -lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 'ip') +lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 0) --- ... lua s:bind('unix/', '/tmp/tarantool-test-socket') diff --git a/test/box/bsdsocket.test b/test/box/bsdsocket.test index 17a1c3729526fef712ac039251a1eb12b6245636..03f25ceb09ac43968ff496b0c4a4fb7d048bc067 100644 --- a/test/box/bsdsocket.test +++ b/test/box/bsdsocket.test @@ -135,7 +135,7 @@ exec admin "lua sa:read(100, 1)" exec admin "lua sa:close()" exec admin "lua sc:close()" -exec admin "lua s = box.socket('PF_UNIX', 'SOCK_STREAM', 'ip')" +exec admin "lua s = box.socket('PF_UNIX', 'SOCK_STREAM', 0)" exec admin "lua s:setsockopt('SOL_SOCKET', 'SO_REUSEADDR', true)" exec admin "lua s ~= nil" exec admin "lua s:nonblock()" @@ -147,7 +147,7 @@ exec admin "lua s:bind('unix/', '/tmp/tarantool-test-socket')" exec admin "lua string.match(tostring(s), 'fd %d+, aka unix/:/tmp/tarantool%-test%-socket') ~= nil" exec admin "lua s:listen(1234)" -exec admin "lua sc = box.socket('PF_UNIX', 'SOCK_STREAM', 'ip')" +exec admin "lua sc = box.socket('PF_UNIX', 'SOCK_STREAM', 0)" exec admin "lua sc:nonblock(true)" exec admin "lua sc:sysconnect('unix/', '/tmp/tarantool-test-socket')" exec admin "lua sc:error()" @@ -252,13 +252,12 @@ exec admin "lua box.socket.tcp_connect('127.0.0.1', {}), box.errno() == box.errn # AF_UNIX path = '/tmp/tarantool-test-socket' -exec admin "lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 'ip')" +exec admin "lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 0)" exec admin "lua s:bind('unix/', '{}')".format(path) exec admin "lua box.socket.tcp_connect('unix/', '{}'), box.errno() == box.errno.ECONNREFUSED".format(path) exec admin "lua s:listen()" exec admin "lua sc, errno = box.socket.tcp_connect('unix/', '{}'), box.errno()".format(path) exec admin "lua sc ~= nil" -exec admin "lua errno == 0" exec admin "lua sc:close()" exec admin "lua s:close()" exec admin "lua box.socket.tcp_connect('unix/', '{}'), box.errno() == box.errno.ECONNREFUSED".format(path) @@ -288,7 +287,7 @@ path = '/tmp/tarantool-test-socket' if os.path.exists(path): os.unlink(path) exec admin "lua path = '%s'" % path -exec admin "lua s = box.socket('PF_UNIX', 'SOCK_STREAM', 'ip')" +exec admin "lua s = box.socket('PF_UNIX', 'SOCK_STREAM', 0)" exec admin "lua s:setsockopt('SOL_SOCKET', 'SO_REUSEADDR', true)" exec admin "lua s:error()" exec admin "lua s:bind('unix/', path)" @@ -383,7 +382,7 @@ exec admin 'lua client:close()' exec admin 'lua server:close()' # Test that socket is closed on GC -exec admin "lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 'ip')" +exec admin "lua s = box.socket('AF_UNIX', 'SOCK_STREAM', 0)" exec admin "lua s:bind('unix/', '{}')".format(path) exec admin "lua s:listen()" exec admin "lua s = nil"