<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10796">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Benjamin Keith Ford: Looks good to me, but someone else must approve
Joshua C. Colp: Looks good to me, but someone else must approve
Matthew Fredrickson: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Use non-blocking socket() and pipe() wrappers<br><br>Change-Id: I050ceffe5a133d5add2dab46687209813d58f597<br>---<br>M main/tcptls.c<br>M main/udptl.c<br>M res/res_agi.c<br>M res/res_rtp_asterisk.c<br>M res/res_timing_pthread.c<br>5 files changed, 12 insertions(+), 27 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/tcptls.c b/main/tcptls.c</span><br><span>index c5ab0b6..d32b91f 100644</span><br><span>--- a/main/tcptls.c</span><br><span>+++ b/main/tcptls.c</span><br><span>@@ -1277,7 +1277,7 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- desc->accept_fd = socket(ast_sockaddr_is_ipv6(&desc->local_address) ?</span><br><span style="color: hsl(120, 100%, 40%);">+ desc->accept_fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(&desc->local_address) ?</span><br><span> AF_INET6 : AF_INET, SOCK_STREAM, 0);</span><br><span> if (desc->accept_fd < 0) {</span><br><span> ast_log(LOG_ERROR, "Unable to allocate socket for %s: %s\n", desc->name, strerror(errno));</span><br><span>@@ -1296,7 +1296,6 @@</span><br><span> ast_log(LOG_ERROR, "Unable to listen for %s!\n", desc->name);</span><br><span> goto error;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_fd_set_flags(desc->accept_fd, O_NONBLOCK);</span><br><span> if (ast_pthread_create_background(&desc->master, NULL, desc->accept_fn, desc)) {</span><br><span> ast_log(LOG_ERROR, "Unable to launch thread for %s on %s: %s\n",</span><br><span> desc->name,</span><br><span>diff --git a/main/udptl.c b/main/udptl.c</span><br><span>index 83989f7..59fccf4 100644</span><br><span>--- a/main/udptl.c</span><br><span>+++ b/main/udptl.c</span><br><span>@@ -1038,13 +1038,12 @@</span><br><span> udptl->tx[i].buf_len = -1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if ((udptl->fd = socket(ast_sockaddr_is_ipv6(addr) ?</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((udptl->fd = ast_socket_nonblock(ast_sockaddr_is_ipv6(addr) ?</span><br><span> AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) {</span><br><span> ast_free(udptl);</span><br><span> ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));</span><br><span> return NULL;</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- ast_fd_set_flags(udptl->fd, O_NONBLOCK);</span><br><span> </span><br><span> #ifdef SO_NO_CHECK</span><br><span> if (cfg->general->nochecksums)</span><br><span>diff --git a/res/res_agi.c b/res/res_agi.c</span><br><span>index f19303f..270c269 100644</span><br><span>--- a/res/res_agi.c</span><br><span>+++ b/res/res_agi.c</span><br><span>@@ -2073,16 +2073,11 @@</span><br><span> ast_sockaddr_set_port(&addrs[i], AGI_PORT);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if ((s = socket(addrs[i].ss.ss_family, SOCK_STREAM, IPPROTO_TCP)) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((s = ast_socket_nonblock(addrs[i].ss.ss_family, SOCK_STREAM, IPPROTO_TCP)) < 0) {</span><br><span> ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));</span><br><span> continue;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_fd_set_flags(s, O_NONBLOCK)) {</span><br><span style="color: hsl(0, 100%, 40%);">- close(s);</span><br><span style="color: hsl(0, 100%, 40%);">- continue;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> if (ast_connect(s, &addrs[i]) && errno == EINPROGRESS) {</span><br><span> </span><br><span> if (handle_connection(agiurl, addrs[i], s)) {</span><br><span>diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c</span><br><span>index 4586ca6..d94dd16 100644</span><br><span>--- a/res/res_rtp_asterisk.c</span><br><span>+++ b/res/res_rtp_asterisk.c</span><br><span>@@ -2792,22 +2792,19 @@</span><br><span> </span><br><span> static int create_new_socket(const char *type, int af)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- int sock = socket(af, SOCK_DGRAM, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ int sock = ast_socket_nonblock(af, SOCK_DGRAM, 0);</span><br><span> </span><br><span> if (sock < 0) {</span><br><span style="color: hsl(0, 100%, 40%);">- if (!type) {</span><br><span style="color: hsl(0, 100%, 40%);">- type = "RTP/RTCP";</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span> ast_log(LOG_WARNING, "Unable to allocate %s socket: %s\n", type, strerror(errno));</span><br><span style="color: hsl(0, 100%, 40%);">- } else {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_fd_set_flags(sock, O_NONBLOCK);</span><br><span style="color: hsl(0, 100%, 40%);">-#ifdef SO_NO_CHECK</span><br><span style="color: hsl(0, 100%, 40%);">- if (nochecksums) {</span><br><span style="color: hsl(0, 100%, 40%);">- setsockopt(sock, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-#endif</span><br><span style="color: hsl(120, 100%, 40%);">+ return sock;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef SO_NO_CHECK</span><br><span style="color: hsl(120, 100%, 40%);">+ if (nochecksums) {</span><br><span style="color: hsl(120, 100%, 40%);">+ setsockopt(sock, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> return sock;</span><br><span> }</span><br><span> </span><br><span>diff --git a/res/res_timing_pthread.c b/res/res_timing_pthread.c</span><br><span>index eee0749..cefe6a7 100644</span><br><span>--- a/res/res_timing_pthread.c</span><br><span>+++ b/res/res_timing_pthread.c</span><br><span>@@ -116,7 +116,6 @@</span><br><span> static void *pthread_timer_open(void)</span><br><span> {</span><br><span> struct pthread_timer *timer;</span><br><span style="color: hsl(0, 100%, 40%);">- int i;</span><br><span> </span><br><span> if (!(timer = ao2_alloc(sizeof(*timer), pthread_timer_destructor))) {</span><br><span> errno = ENOMEM;</span><br><span>@@ -126,15 +125,11 @@</span><br><span> timer->pipe[PIPE_READ] = timer->pipe[PIPE_WRITE] = -1;</span><br><span> timer->state = TIMER_STATE_IDLE;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (pipe(timer->pipe)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_pipe_nonblock(timer->pipe)) {</span><br><span> ao2_ref(timer, -1);</span><br><span> return NULL;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- for (i = 0; i < ARRAY_LEN(timer->pipe); ++i) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_fd_set_flags(timer->pipe[i], O_NONBLOCK);</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> ao2_lock(pthread_timers);</span><br><span> if (!ao2_container_count(pthread_timers)) {</span><br><span> ast_mutex_lock(&timing_thread.lock);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10796">change 10796</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/10796"/><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-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I050ceffe5a133d5add2dab46687209813d58f597 </div>
<div style="display:none"> Gerrit-Change-Number: 10796 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua C. Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Matthew Fredrickson <creslin@digium.com> </div>