From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 5D6F5452566 for ; Fri, 1 Nov 2019 17:39:36 +0300 (MSK) Date: Fri, 1 Nov 2019 17:39:29 +0300 From: Alexander Turenko Message-ID: <20191101143929.7gv53nqgscwpbayv@tkn_work_nb> References: <20190623203141.snnjgyqrntr6okp4@tkn_work_nb> <8C0820C4-7F5E-40A9-A634-E449E700D816@tarantool.org> <20190709080407.sv5quzrxpbnijwp4@tkn_work_nb> <20190723123954.dgtfsetqlmjhued3@tkn_work_nb> <704142F3-802F-4C1C-8FA2-6155BFF9A951@tarantool.org> <20190829004547.k24fktai33tlbl73@tkn_work_nb> <868EAF2C-A491-46C9-AD37-7512D6CAB213@tarantool.org> <20190906134509.egjpa2vxfdolkeme@tkn_work_nb> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Subject: Re: [Tarantool-patches] [server-dev] Re: [tarantool-patches] Re: [PATCH v2 1/2] lua: return getaddrinfo() errors List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Roman Khabibov Cc: tarantool-patches@freelists.org, tarantool-patches@dev.tarantool.org > commit 9810ccd869183de068939cdce5a157ad35916d36 > Author: Roman Khabibov > Date: Tue Jul 30 15:49:13 2019 +0300 > > lua: return getaddrinfo() errors > > Add getaddrinfo() errors into the several fuctions of socket. Now > getaddrinfo() can return a pair of values (nil and error message) > in case of error. > > Closes #4138 > > @TarantoolBot document > Title: socket_object:connect `socket_object:connect` is not valid Lua syntax. It is better to write it as socket_object:connect() or socket_object.connect. net.box API also was changed. > > Connect to a remote host using tcp_connect() within. If it is no > error, return a socket object. It is hard to understood w/o a context. Please, either describe API changes formally or give an example that will show the API change. > diff --git a/src/lua/socket.lua b/src/lua/socket.lua > index a334ad45b..e4815adbb 100644 > --- a/src/lua/socket.lua > +++ b/src/lua/socket.lua > @@ -1041,9 +1041,12 @@ local function tcp_connect(host, port, timeout) > end > local timeout = timeout or TIMEOUT_INFINITY > local stop = fiber.clock() + timeout > - local dns = getaddrinfo(host, port, timeout, { type = 'SOCK_STREAM', > + local dns, err = getaddrinfo(host, port, timeout, { type = 'SOCK_STREAM', > protocol = 'tcp' }) > - if dns == nil or #dns == 0 then > + if dns == nil then > + return nil, err > + end > + if #dns == 0 then > boxerrno(boxerrno.EINVAL) > return nil > end Cited to link from below. > @@ -1360,9 +1363,16 @@ local function lsocket_tcp_connect(self, host, port) > -- This function is broken by design > local ga_opts = { family = 'AF_INET', type = 'SOCK_STREAM' } > local timeout = deadline - fiber.clock() > - local dns = getaddrinfo(host, port, timeout, ga_opts) > + local dns, err = getaddrinfo(host, port, timeout, ga_opts) > if dns == nil or #dns == 0 then > - self._errno = boxerrno.EINVAL > + return nil, err > + end > + if dns == nil then > + boxerrno(self._errno) > + return nil, err > + end > + if #dns == 0 then > + boxerrno(self._errno) > return nil, socket_error(self) > end We'll never reach the last two if's bodies. However the similar fragment above in tcp_connect() was changed in the right way.