<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi! Thanks for the patch!<div class="">Alexander asked me to do the 2nd review.</div><div class=""><br class=""></div><div class="">The patch LGTM.</div><div class=""><br class=""></div><div class="">Sorry for nitpicking, but looks like your changelog request has a typo in it:</div><div class="">> @ChangeLog<br class="">> - box.info.listen - new record in <a href="http://box.info" class="">box.info</a>, which shows a<br class="">> real port when bound to port 0. For example, if box.cfg<br class="">> 'listen' parameter was set to '127.0.0.1:0', box.info.listen<br class="">> will show '127.0.0.1:<real port > 0>' (gh-4620).</div><div class="">just <real port>, without 0>, right?</div><div class=""><br class=""><div class="">
<div dir="auto" style="caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0); letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div>--</div><div>Serge Petrenko</div><div><a href="mailto:sergepetrenko@tarantool.org" class="">sergepetrenko@tarantool.org</a></div><div class=""><br class=""></div></div><br class="Apple-interchange-newline"><br class="Apple-interchange-newline">
</div>
<div><br class=""><blockquote type="cite" class=""><div class="">13 нояб. 2019 г., в 01:03, Vladislav Shpilevoy <<a href="mailto:v.shpilevoy@tarantool.org" class="">v.shpilevoy@tarantool.org</a>> написал(а):</div><br class="Apple-interchange-newline"><div class=""><div class="">Box.cfg{listen = 0} automatically chooses a port. But it was<br class="">impossible to learn a real port the instance is bound to.<br class=""><br class="">An ability to see a real port may help to make test-run more<br class="">robust, because it won't depend on which ports are free, and<br class="">won't need to pre-choose them in advance.<br class=""><br class="">Now box.info.listen shows a real address, or nil when listen is<br class="">turned off. Also a real address is logged instead of the dummy<br class="">0-port one.<br class=""><br class="">Closes #4620<br class=""><br class="">@TarantoolBot document<br class="">Title: box.info.listen - real address<br class=""><br class="">New value in <a href="http://box.info" class="">box.info</a> - listen. It is a real address to which the<br class="">instance was bound. For example, if box.cfg.listen was set with<br class="">a zero port, box.info.listen will show a real port. The address<br class="">is stored as a string:<br class=""><br class=""> - unix/:<path> for UNIX domain sockets;<br class=""> - <ip>:<port> for IPv4;<br class=""> - [ip]:<port> for IPv6.<br class=""><br class="">If the instance does not listen anything, box.info.listen is nil.<br class="">---<br class="">Branch: <a href="https://github.com/tarantool/tarantool/tree/gerold103/gh-4620-show-listen-port" class="">https://github.com/tarantool/tarantool/tree/gerold103/gh-4620-show-listen-port</a><br class="">Issue: <a href="https://github.com/tarantool/tarantool/issues/4620" class="">https://github.com/tarantool/tarantool/issues/4620</a><br class=""><br class=""> src/box/<a href="http://iproto.cc" class="">iproto.cc</a> | 31 +++++++++++++++++++++++++++++--<br class=""> src/box/iproto.h | 7 +++++++<br class=""> src/box/lua/info.c | 9 +++++++++<br class=""> src/lib/core/evio.c | 8 ++++++++<br class=""> test/box/info.result | 1 +<br class=""> 5 files changed, 54 insertions(+), 2 deletions(-)<br class=""><br class="">diff --git a/src/box/<a href="http://iproto.cc" class="">iproto.cc</a> b/src/box/<a href="http://iproto.cc" class="">iproto.cc</a><br class="">index 34c8f469a..522c066be 100644<br class="">--- a/src/box/<a href="http://iproto.cc" class="">iproto.cc</a><br class="">+++ b/src/box/<a href="http://iproto.cc" class="">iproto.cc</a><br class="">@@ -129,6 +129,23 @@ unsigned iproto_readahead = 16320;<br class=""> /* The maximal number of iproto messages in fly. */<br class=""> static int iproto_msg_max = IPROTO_MSG_MAX_MIN;<br class=""><br class="">+/**<br class="">+ * Address the iproto listens for, stored in TX<br class="">+ * thread. Is kept in TX to be showed in <a href="http://box.info" class="">box.info</a>.<br class="">+ */<br class="">+static struct sockaddr_storage iproto_bound_address_storage;<br class="">+/** 0 means that no address is listened. */<br class="">+static socklen_t iproto_bound_address_len;<br class="">+<br class="">+const char *<br class="">+iproto_bound_address(void)<br class="">+{<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>if (iproto_bound_address_len == 0)<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>return NULL;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>return sio_strfaddr((struct sockaddr *) &iproto_bound_address_storage,<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span> iproto_bound_address_len);<br class="">+}<br class="">+<br class=""> /**<br class=""> * How big is a buffer which needs to be shrunk before<br class=""> * it is put back into buffer cache.<br class="">@@ -2081,8 +2098,14 @@ struct iproto_cfg_msg: public cbus_call_msg<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>/** Operation to execute in iproto thread. */<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>enum iproto_cfg_op op;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>union {<br class="">-<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>/** New URI to bind to. */<br class="">-<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>const char *uri;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>struct {<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>/** New URI to bind to. */<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>const char *uri;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>/** Result address. */<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>struct sockaddr_storage addr;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>/** Address length. */<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>socklen_t addrlen;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>};<br class=""><br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>/** New iproto max message count. */<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>int iproto_msg_max;<br class="">@@ -2118,6 +2141,8 @@ iproto_do_cfg_f(struct cbus_call_msg *m)<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span> (evio_service_bind(&binary, cfg_msg->uri) != 0 ||<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span> evio_service_listen(&binary) != 0))<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>diag_raise();<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>cfg_msg->addrlen = binary.addr_len;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>cfg_msg->addr = binary.addrstorage;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>break;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>default:<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>unreachable();<br class="">@@ -2143,6 +2168,8 @@ iproto_listen(const char *uri)<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>iproto_cfg_msg_create(&cfg_msg, IPROTO_CFG_LISTEN);<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>cfg_msg.uri = uri;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>iproto_do_cfg(&cfg_msg);<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>iproto_bound_address_storage = cfg_msg.addr;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>iproto_bound_address_len = cfg_msg.addrlen;<br class=""> }<br class=""><br class=""> size_t<br class="">diff --git a/src/box/iproto.h b/src/box/iproto.h<br class="">index edb24a7ed..201e09df5 100644<br class="">--- a/src/box/iproto.h<br class="">+++ b/src/box/iproto.h<br class="">@@ -80,6 +80,13 @@ iproto_request_count(void);<br class=""> void<br class=""> iproto_reset_stat(void);<br class=""><br class="">+/**<br class="">+ * String representation of the address served by<br class="">+ * iproto. To be showed in <a href="http://box.info" class="">box.info</a>.<br class="">+ */<br class="">+const char *<br class="">+iproto_bound_address(void);<br class="">+<br class=""> #if defined(__cplusplus)<br class=""> } /* extern "C" */<br class=""><br class="">diff --git a/src/box/lua/info.c b/src/box/lua/info.c<br class="">index 55382fd77..98579e8df 100644<br class="">--- a/src/box/lua/info.c<br class="">+++ b/src/box/lua/info.c<br class="">@@ -485,6 +485,14 @@ lbox_info_vinyl(struct lua_State *L)<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>return 1;<br class=""> }<br class=""><br class="">+static int<br class="">+lbox_info_listen(struct lua_State *L)<br class="">+{<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>/* NULL is ok, no need to check. */<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>lua_pushstring(L, iproto_bound_address());<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>return 1;<br class="">+}<br class="">+<br class=""> static const struct luaL_Reg lbox_info_dynamic_meta[] = {<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>{"id", lbox_info_id},<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>{"uuid", lbox_info_uuid},<br class="">@@ -500,6 +508,7 @@ static const struct luaL_Reg lbox_info_dynamic_meta[] = {<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>{"memory", lbox_info_memory},<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>{"gc", lbox_info_gc},<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>{"vinyl", lbox_info_vinyl},<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>{"listen", lbox_info_listen},<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>{NULL, NULL}<br class=""> };<br class=""><br class="">diff --git a/src/lib/core/evio.c b/src/lib/core/evio.c<br class="">index 2152c15e6..fc8f00e0e 100644<br class="">--- a/src/lib/core/evio.c<br class="">+++ b/src/lib/core/evio.c<br class="">@@ -269,6 +269,13 @@ evio_service_bind_addr(struct evio_service *service)<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>}<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>}<br class=""><br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>/*<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span> * After binding a result address may be different. For<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span> * example, if a port was 0.<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span> */<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>if (sio_getsockname(fd, &service->addr, &service->addr_len) != 0)<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>goto error;<br class="">+<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>say_info("%s: bound to %s", evio_service_name(service),<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span> sio_strfaddr(&service->addr, service->addr_len));<br class=""><br class="">@@ -400,6 +407,7 @@ evio_service_stop(struct evio_service *service)<br class=""><br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>if (ev_is_active(&service->ev)) {<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>ev_io_stop(service->loop, &service->ev);<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>service->addr_len = 0;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>}<br class=""><br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>if (service->ev.fd >= 0) {<br class="">diff --git a/test/box/info.result b/test/box/info.result<br class="">index af81f7add..4dc888616 100644<br class="">--- a/test/box/info.result<br class="">+++ b/test/box/info.result<br class="">@@ -77,6 +77,7 @@ t<br class=""> - - cluster<br class=""> - gc<br class=""> - id<br class="">+ - listen<br class=""> - lsn<br class=""> - memory<br class=""> - package<br class="">-- <br class="">2.21.0 (Apple Git-122.2)<br class=""><br class=""></div></div></blockquote></div><br class=""></div></body></html>