<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11626">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">manager: Send fewer packets<br><br>The functions that build manager message headers do so in a way that<br>results in a single messages being split across multiple packets. While<br>this doesn't matter to the remote end, it makes network captures noisier<br>and harder to follow, and also means additional system calls.<br><br>With this patch, we build up more of the message content into the TLS<br>buffer before flushing to the network. This change is completely<br>internal to the manager code and does not affect any of the existing<br>API's consumers.<br><br>Change-Id: I50128b0769060ca5272dbbb5e60242d131eaddf9<br>---<br>M main/manager.c<br>1 file changed, 64 insertions(+), 21 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/manager.c b/main/manager.c</span><br><span>index 0efb030..1df6765 100644</span><br><span>--- a/main/manager.c</span><br><span>+++ b/main/manager.c</span><br><span>@@ -3042,6 +3042,15 @@</span><br><span> /*! \brief initial allocated size for the astman_append_buf and astman_send_*_va */</span><br><span> #define ASTMAN_APPEND_BUF_INITSIZE 256</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void astman_flush(struct mansession *s, struct ast_str *buf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (s->f || s->session->f) {</span><br><span style="color: hsl(120, 100%, 40%);">+ send_string(s, ast_str_buffer(buf));</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verbose("fd == -1 in astman_append, should not happen\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * utility functions for creating AMI replies</span><br><span> */</span><br><span>@@ -3091,21 +3100,32 @@</span><br><span> static void astman_send_response_full(struct mansession *s, const struct message *m, char *resp, char *msg, char *listflag)</span><br><span> {</span><br><span> const char *id = astman_get_header(m, "ActionID");</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *buf;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- astman_append(s, "Response: %s\r\n", resp);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ast_strlen_zero(id)) {</span><br><span style="color: hsl(0, 100%, 40%);">- astman_append(s, "ActionID: %s\r\n", id);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (listflag) {</span><br><span style="color: hsl(0, 100%, 40%);">- astman_append(s, "EventList: %s\r\n", listflag); /* Start, complete, cancelled */</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">- if (msg == MSG_MOREDATA) {</span><br><span style="color: hsl(120, 100%, 40%);">+ buf = ast_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!buf) {</span><br><span> return;</span><br><span style="color: hsl(0, 100%, 40%);">- } else if (msg) {</span><br><span style="color: hsl(0, 100%, 40%);">- astman_append(s, "Message: %s\r\n\r\n", msg);</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- astman_append(s, "\r\n");</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_set(&buf, 0, "Response: %s\r\n", resp);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(id)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0, "ActionID: %s\r\n", id);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (listflag) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Start, complete, cancelled */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0, "EventList: %s\r\n", listflag);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (msg != MSG_MOREDATA) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (msg) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0, "Message: %s\r\n", msg);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0, "\r\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_flush(s, buf);</span><br><span> }</span><br><span> </span><br><span> void astman_send_response(struct mansession *s, const struct message *m, char *resp, char *msg)</span><br><span>@@ -3160,18 +3180,43 @@</span><br><span> astman_send_response_full(s, m, "Success", msg, listflag);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)</span><br><span style="color: hsl(120, 100%, 40%);">+static struct ast_str *astman_send_list_complete_start_common(struct mansession *s, const struct message *m, const char *event_name, int count)</span><br><span> {</span><br><span> const char *id = astman_get_header(m, "ActionID");</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *buf;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- astman_append(s, "Event: %s\r\n", event_name);</span><br><span style="color: hsl(0, 100%, 40%);">- if (!ast_strlen_zero(id)) {</span><br><span style="color: hsl(0, 100%, 40%);">- astman_append(s, "ActionID: %s\r\n", id);</span><br><span style="color: hsl(120, 100%, 40%);">+ buf = ast_str_thread_get(&astman_append_buf, ASTMAN_APPEND_BUF_INITSIZE);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!buf) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- astman_append(s,</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_set(&buf, 0, "Event: %s\r\n", event_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(id)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0, "ActionID: %s\r\n", id);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0,</span><br><span> "EventList: Complete\r\n"</span><br><span> "ListItems: %d\r\n",</span><br><span> count);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return buf;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void astman_send_list_complete(struct mansession *s, const struct message *m, const char *event_name, int count)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *buf = astman_send_list_complete_start_common(s, m, event_name, count);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (buf) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(&buf, 0, "\r\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_flush(s, buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void astman_send_list_complete_start(struct mansession *s, const struct message *m, const char *event_name, int count)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str *buf = astman_send_list_complete_start_common(s, m, event_name, count);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (buf) {</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_flush(s, buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> void astman_send_list_complete_end(struct mansession *s)</span><br><span>@@ -4483,8 +4528,7 @@</span><br><span> regfree(®exbuf);</span><br><span> ast_free(regex_string);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- astman_send_list_complete_start(s, m, "ChannelsHungupListComplete", channels_matched);</span><br><span style="color: hsl(0, 100%, 40%);">- astman_send_list_complete_end(s);</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_send_list_complete(s, m, "ChannelsHungupListComplete", channels_matched);</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span>@@ -6289,8 +6333,7 @@</span><br><span> }</span><br><span> ao2_iterator_destroy(&it_chans);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- astman_send_list_complete_start(s, m, "CoreShowChannelsComplete", numchans);</span><br><span style="color: hsl(0, 100%, 40%);">- astman_send_list_complete_end(s);</span><br><span style="color: hsl(120, 100%, 40%);">+ astman_send_list_complete(s, m, "CoreShowChannelsComplete", numchans);</span><br><span> </span><br><span> ao2_ref(channels, -1);</span><br><span> return 0;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11626">change 11626</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/11626"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I50128b0769060ca5272dbbb5e60242d131eaddf9 </div>
<div style="display:none"> Gerrit-Change-Number: 11626 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>