diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst index dceab01d7..7fe609fc9 100644 --- a/doc/lua-api/index.rst +++ b/doc/lua-api/index.rst @@ -1769,7 +1769,7 @@ Socket class "abns@", and finaly a filedescriotr can be passed with the prefix "fd@". The prefix "ipv4@", "ipv6@" and "unix@" are also supported. The port can be passed int the string. The syntax "127.0.0.1:1234" is valid. in this case, the - parameter *port* is ignored. + parameter *port* must not be set. .. js:function:: Socket.connect_ssl(socket, address, port) diff --git a/src/hlua.c b/src/hlua.c index 3b4fc3b54..3d5a81cac 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -2333,9 +2333,22 @@ __LJMP static int hlua_socket_connect(struct lua_State *L) WILL_LJMP(luaL_error(L, "connect: cannot use socket on other thread")); ip = MAY_LJMP(luaL_checkstring(L, 2)); - if (lua_gettop(L) >= 3) + if (lua_gettop(L) >= 3) { + luaL_Buffer b; port = MAY_LJMP(luaL_checkinteger(L, 3)); + /* Force the ip to end with a colon, to support IPv6 addresses + * that are not enclosed within square brackets. + */ + if (port > 0) { + luaL_buffinit(L, &b); + luaL_addstring(&b, ip); + luaL_addchar(&b, ':'); + luaL_pushresult(&b); + ip = lua_tolstring(L, lua_gettop(L), NULL); + } + } + /* check for connection break. If some data where read, return it. */ peer = xref_get_peer_and_lock(&socket->xref); if (!peer) {