From: Vladislav Shpilevoy via Tarantool-patches <tarantool-patches@dev.tarantool.org> To: Vladimir Davydov <vdavydov@tarantool.org>, tarantool-patches@dev.tarantool.org Subject: Re: [Tarantool-patches] [PATCH 17/20] net.box: rewrite console handlers in C Date: Wed, 4 Aug 2021 01:07:42 +0200 [thread overview] Message-ID: <746f0d18-d308-d9f4-b6b8-c9f2bbd6d896@tarantool.org> (raw) In-Reply-To: <c48b13b50aea34d6199abfaa40970ab7fd1a3236.1627024646.git.vdavydov@tarantool.org> 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); > + } > }
next prev parent reply other threads:[~2021-08-03 23:07 UTC|newest] Thread overview: 80+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-23 11:07 [Tarantool-patches] [PATCH 00/20] Rewrite performance critical parts of net.box " Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 01/20] net.box: fix console connection breakage when request is discarded Vladimir Davydov via Tarantool-patches 2021-07-28 22:49 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 10:40 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 02/20] net.box: wake up wait_result callers " Vladimir Davydov via Tarantool-patches 2021-07-29 10:47 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 03/20] net.box: do not check worker_fiber in request:result, is_ready Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 04/20] net.box: remove decode_push from method_decoder table Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 05/20] net.box: use decode_tuple instead of decode_get Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 06/20] net.box: rename request.ctx to request.format Vladimir Davydov via Tarantool-patches 2021-07-28 22:49 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 10:54 ` Vladimir Davydov via Tarantool-patches 2021-07-29 22:39 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-30 8:15 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 07/20] net.box: use integer id instead of method name Vladimir Davydov via Tarantool-patches 2021-07-28 22:50 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 11:30 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 08/20] net.box: remove useless encode optimization Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 09/20] net.box: rewrite request encoder in C Vladimir Davydov via Tarantool-patches 2021-07-28 22:51 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 14:08 ` Vladimir Davydov via Tarantool-patches 2021-07-29 14:10 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 10/20] lua/utils: make char ptr Lua CTIDs public Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 11/20] net.box: rewrite response decoder in C Vladimir Davydov via Tarantool-patches 2021-07-27 14:07 ` Cyrill Gorcunov via Tarantool-patches 2021-07-27 14:14 ` Vladimir Davydov via Tarantool-patches 2021-07-29 22:39 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-30 8:44 ` Vladimir Davydov via Tarantool-patches 2021-07-30 22:12 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-02 7:36 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 12/20] net.box: rewrite error " Vladimir Davydov via Tarantool-patches 2021-07-30 22:13 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-02 8:00 ` Vladimir Davydov via Tarantool-patches 2021-08-02 21:47 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 13/20] net.box: rewrite send_and_recv_{iproto, console} " Vladimir Davydov via Tarantool-patches 2021-08-02 21:49 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-03 15:44 ` Vladimir Davydov via Tarantool-patches 2021-08-03 23:06 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 13:56 ` Vladimir Davydov via Tarantool-patches 2021-08-04 21:18 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 8:37 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 14/20] net.box: rename netbox_{prepare, encode}_request to {begin, end} Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 15/20] net.box: rewrite request implementation in C Vladimir Davydov via Tarantool-patches 2021-08-02 21:54 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 12:30 ` Vladimir Davydov via Tarantool-patches 2021-08-04 15:35 ` Vladimir Davydov via Tarantool-patches 2021-08-04 16:14 ` Vladimir Davydov via Tarantool-patches 2021-08-04 21:20 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 12:46 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 16/20] net.box: store next_request_id in C code Vladimir Davydov via Tarantool-patches 2021-08-03 23:06 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 16:25 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 17/20] net.box: rewrite console handlers in C Vladimir Davydov via Tarantool-patches 2021-08-03 23:07 ` Vladislav Shpilevoy via Tarantool-patches [this message] 2021-08-05 11:53 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 18/20] net.box: rewrite iproto " Vladimir Davydov via Tarantool-patches 2021-08-03 23:08 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 11:54 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 19/20] net.box: merge new_id, new_request and encode_method Vladimir Davydov via Tarantool-patches 2021-08-03 23:08 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 11:55 ` Vladimir Davydov via Tarantool-patches 2021-07-23 11:07 ` [Tarantool-patches] [PATCH 20/20] net.box: do not create request object in Lua for sync requests Vladimir Davydov via Tarantool-patches 2021-08-03 23:09 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-05 12:23 ` Vladimir Davydov via Tarantool-patches 2021-07-23 12:48 ` [Tarantool-patches] [PATCH 00/20] Rewrite performance critical parts of net.box in C Vladimir Davydov via Tarantool-patches 2021-07-26 7:26 ` Kirill Yukhin via Tarantool-patches 2021-07-27 9:59 ` Vladimir Davydov via Tarantool-patches 2021-07-28 22:51 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-29 11:33 ` Vladimir Davydov via Tarantool-patches 2021-07-29 15:23 ` Vladimir Davydov via Tarantool-patches 2021-07-29 22:38 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-30 10:04 ` Vladimir Davydov via Tarantool-patches 2021-07-29 22:40 ` Vladislav Shpilevoy via Tarantool-patches 2021-07-30 8:16 ` Vladimir Davydov via Tarantool-patches 2021-08-03 23:05 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-04 12:40 ` Vladimir Davydov via Tarantool-patches 2021-08-05 20:59 ` Vladislav Shpilevoy via Tarantool-patches 2021-08-09 11:22 ` Igor Munkin via Tarantool-patches 2021-08-09 11:48 ` Vitaliia Ioffe via Tarantool-patches 2021-08-09 13:56 ` Vladimir Davydov via Tarantool-patches
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=746f0d18-d308-d9f4-b6b8-c9f2bbd6d896@tarantool.org \ --to=tarantool-patches@dev.tarantool.org \ --cc=v.shpilevoy@tarantool.org \ --cc=vdavydov@tarantool.org \ --subject='Re: [Tarantool-patches] [PATCH 17/20] net.box: rewrite console handlers in C' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox