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 87B3E6F3E0; Thu, 5 Aug 2021 14:53:24 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 87B3E6F3E0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1628164404; bh=6RCWp5cyTT1Bd58TYPUy7rmWv4n+DiTbVcLC3HHABhg=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=bu2LmrHkcwA3G6i1CKWADC6rYE1CjUvfgpkO9M8znpzXi6rIWsyNB4onFkCHlbGRj 0BUlJZSQBZmb1ak2zzL/On8AfuI6k3b95yNJtUt1y3+XC2vRNsmsooOTocmnfR7/wR nPhEacSjYZy3hvVO8F75a9at7EvmUdeUQF2UldKQ= 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 1B70D6F3E0 for ; Thu, 5 Aug 2021 14:53:23 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1B70D6F3E0 Received: by smtpng1.m.smailru.net with esmtpa (envelope-from ) id 1mBbwA-0001MO-AK; Thu, 05 Aug 2021 14:53:22 +0300 Date: Thu, 5 Aug 2021 14:53:21 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210805115321.ia23p5sfd26kfojw@esperanza> References: <746f0d18-d308-d9f4-b6b8-c9f2bbd6d896@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <746f0d18-d308-d9f4-b6b8-c9f2bbd6d896@tarantool.org> X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F6525B29142351271182A05F538085040596FE4B86533417C16C9FD9FB9205A5FBB3A5C5837F5DF57D6F96E2D2517D16A X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE702C8878A98595F58EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637328FC23D015AFE6E8638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8FD1ED6E692C6993F7600CBAA2ABE95CC117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCAA867293B0326636D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8BAA867293B0326636D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B65D56369A3576CBA5089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458834459D11680B505526C2837A3779343EE2F8E5BE77953AA X-C1DE0DAB: 0D63561A33F958A5593D3DCA8A9108C4201072622D951A0B69BFB0943E587EDAD59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA7501A9DF589746230F410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D346840168BCAD8054EF91E99A4B570C1EF09E5E2349DE133E1400A520414B91A231DD445764FE069971D7E09C32AA3244C37F52206BCD89588E6D58089ABEB4AA755E75C8D0ED9F6EEFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojh4v93/7HD3W6N+/3EyGaKw== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D026368963B4C897EF15C0E1CA576F4D5274CEFED1673C562683ABF942079399BFB559BB5D741EB966A65DFF43FF7BE03240331F90058701C67EA787935ED9F1B 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: Vladimir Davydov via Tarantool-patches Reply-To: Vladimir Davydov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Wed, Aug 04, 2021 at 01:07:42AM +0200, Vladislav Shpilevoy wrote: > > +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. Let's leave response_len to emphasize that response is a string. > > +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? No reason. Fixed. > 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. I honestly don't know, but we always define them as static: ~/src/tarantool$ git grep 'luaL_Reg.*{' src | wc -l 60 ~/src/tarantool$ git grep 'luaL_Reg.*{' src | grep -c -v static 0 Maybe because we are afraid of running out of stack? I woulnd't bother anyway. > > +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. Fixed in a separate patch: https://lists.tarantool.org/pipermail/tarantool-patches/2021-August/025208.html Incremental diff: -- diff --git a/src/box/lua/net_box.c b/src/box/lua/net_box.c index eec5e5bcc519..d41a8d654a8b 100644 --- a/src/box/lua/net_box.c +++ b/src/box/lua/net_box.c @@ -1762,12 +1762,11 @@ netbox_dispatch_response_console(struct lua_State *L, static int netbox_console_setup(struct lua_State *L) { - static const char setup_delimiter_cmd[] = + 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; + const size_t setup_delimiter_cmd_len = strlen(setup_delimiter_cmd); + const char *ok_response = "---\n...\n"; + const size_t ok_response_len = strlen(ok_response); int fd = lua_tointeger(L, 1); struct ibuf *send_buf = (struct ibuf *)lua_topointer(L, 2); struct ibuf *recv_buf = (struct ibuf *)lua_topointer(L, 3); @@ -1782,7 +1781,8 @@ netbox_console_setup(struct lua_State *L) luaL_testcancel(L); goto error; } - if (strncmp(response, ok_response, ok_response_len) != 0) { + if (response_len != ok_response_len || + strncmp(response, ok_response, ok_response_len) != 0) { box_error_raise(ER_NO_CONNECTION, "Unexpected response"); goto error; }