From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 9474D6EC58; Wed, 4 Aug 2021 02:07:46 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 9474D6EC58 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628032066; bh=445PnDQCQ5zxz5Gy7F2kGigM+b2wWwMjwcc3fqyHKSY=; h=To:References:Date:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fu2MAJ1eZOyHoKkRqblPxidKSRo1UbfGrRcQmYusBZ0zVAkeFiGs6LqjhH4d8w1Op UC6qAT0lMPcexk19r6kORWE3uVRuundB3RoTMQdD9l7wyqU8si5zR12b/Y0de5GE9u rIThlUxH2FD6UxuIWq6dRdj0ghvdvG8GIpyIA5Dc= Received: from smtpng1.i.mail.ru (smtpng1.i.mail.ru [94.100.181.251]) (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 928436EC58 for ; Wed, 4 Aug 2021 02:07:44 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 928436EC58 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mB3Vf-00062p-OR; Wed, 04 Aug 2021 02:07:44 +0300 To: Vladimir Davydov , tarantool-patches@dev.tarantool.org References: Message-ID: <746f0d18-d308-d9f4-b6b8-c9f2bbd6d896@tarantool.org> Date: Wed, 4 Aug 2021 01:07:42 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD941C43E597735A9C351B198F4576AC7B2770D7874BA03B4AE182A05F53808504042BCE21428FDA9F6DA95DD6888621BB2F97A1B0889DCBC75015F31200FF272CE X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE77633BACAB33B9508C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7AF18881564A951B9EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2633266303D4AF15918098BC579589A89CC7F00164DA146DAFE8445B8C89999728AA50765F790063783E00425F71A4181389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC81D471462564A2E19F6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BDCE939D40DBB93CA75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505E5D277D87C5CA069AFA5F0868FFB4021 X-C1DE0DAB: 0D63561A33F958A5F4E2B99C095763475B7E83A85466AF0DAF0327E9515CB71ED59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA751B940EDA0DFB0535410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34351729636A02D1DE48132B3FFD84A2918002A8EE3C6197565F90C8599ED8EC390A227D3D4CF7AE7F1D7E09C32AA3244C38F841EDF188F40043456BBB0AED3DC3A95CA90A1D8AC565729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojeDyvyeZJDJHIKLHB+Y2oRg== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D250CCC40B8112C6DB4AC302D30C8C8793841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH 17/20] net.box: rewrite console handlers in C X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thanks for the patch! See 3 comments below. > diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c > index 1a615797d485..85a45c54b979 100644 > --- a/src/box/lua/net_box.c > +++ b/src/box/lua/net_box.c > @@ -850,30 +850,25 @@ netbox_send_and_recv_iproto(lua_State *L) > > /* > * Sends and receives data over a console connection. > - * Takes socket fd, send_buf (ibuf), recv_buf (ibuf), timeout. > - * On success returns response (string). > - * On error returns nil, error. > + * Returns a pointer to a response string and its len. > + * On error returns NULL. > */ > -static int > -netbox_send_and_recv_console(lua_State *L) > +static const char * > +netbox_send_and_recv_console(int fd, struct ibuf *send_buf, > + struct ibuf *recv_buf, double timeout, > + size_t *response_len) 1. To be consistent with netbox_communicate() I would call the last argument 'size'. Up to you. <...> > + > +/* > + * Sets up console delimiter. Should be called before serving any requests. > + * Takes socket fd, send_buf (ibuf), recv_buf (ibuf), timeout. > + * Returns none on success, error on failure. > + */ > +static int > +netbox_console_setup(struct lua_State *L) > +{ > + static const char setup_delimiter_cmd[] = > + "require('console').delimiter('$EOF$')\n"; > + static const size_t setup_delimiter_cmd_len = > + sizeof(setup_delimiter_cmd) - 1; > + static const char ok_response[] = "---\n...\n"; > + static const size_t ok_response_len = sizeof(ok_response) - 1; 2. Why do you make them static? Wouldn't it be enough to just store them on the stack? Btw, the same question for netbox_registry_meta, netbox_request_meta, net_box_lib. Why should they be static? It seems Lua anyway copies them somewhere, so they don't need to stay valid for the entire process' lifetime. > + > +/* > + * Processes console requests in a loop until an error. > + * Takes request registry, socket fd, send_buf (ibuf), recv_buf (ibuf), timeout. > + * Returns the error that broke the loop. > + */ > +static int > +netbox_console_loop(struct lua_State *L) > +{ > + struct netbox_registry *registry = luaT_check_netbox_registry(L, 1); > + int fd = lua_tointeger(L, 2); > + struct ibuf *send_buf = (struct ibuf *) lua_topointer(L, 3); > + struct ibuf *recv_buf = (struct ibuf *) lua_topointer(L, 4); > + double timeout = (!lua_isnoneornil(L, 5) ? > + lua_tonumber(L, 5) : TIMEOUT_INFINITY); 3. You never pass timeout as not nil. It is always TIMEOUT_INFINITY. > + uint64_t sync = registry->next_sync; > + while (true) { > + size_t response_len; > + const char *response = netbox_send_and_recv_console( > + fd, send_buf, recv_buf, timeout, &response_len); > + if (response == NULL) { > + luaL_testcancel(L); > + luaT_pusherror(L, box_error_last()); > + return 1; > + } > + netbox_dispatch_response_console(L, registry, sync++, > + response, response_len); > + } > }