<p>Joshua C. Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10756">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua C. Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">utils: Wrap socket() and pipe() to reduce syscalls<br><br>Some platforms provide an implementation of socket() and pipe2() that allow the<br>caller to specify that the resulting file descriptors should be non-blocking.<br><br>Using these allows us to potentially elide 3 calls into 1 by avoiding extraneous<br>calls to fcntl() to set the O_NONBLOCK flag afterwards.<br><br>In passing, change ast_alertpipe_init() to use pipe2() directly instead of the<br>wrapper if it is available.<br><br>Change-Id: I3ebe654fb549587537161506c6c950f4ab298bb0<br>---<br>M configure<br>M configure.ac<br>M include/asterisk/autoconfig.h.in<br>M include/asterisk/utils.h<br>M main/alertpipe.c<br>M main/utils.c<br>6 files changed, 175 insertions(+), 8 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configure b/configure</span><br><span>index abab645..e739e40 100755</span><br><span>--- a/configure</span><br><span>+++ b/configure</span><br><span>@@ -1345,6 +1345,7 @@</span><br><span> docdir</span><br><span> oldincludedir</span><br><span> includedir</span><br><span style="color: hsl(120, 100%, 40%);">+runstatedir</span><br><span> localstatedir</span><br><span> sharedstatedir</span><br><span> sysconfdir</span><br><span>@@ -1532,6 +1533,7 @@</span><br><span> sysconfdir='${prefix}/etc'</span><br><span> sharedstatedir='${prefix}/com'</span><br><span> localstatedir='${prefix}/var'</span><br><span style="color: hsl(120, 100%, 40%);">+runstatedir='${localstatedir}/run'</span><br><span> includedir='${prefix}/include'</span><br><span> oldincludedir='/usr/include'</span><br><span> docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'</span><br><span>@@ -1784,6 +1786,15 @@</span><br><span>   | -silent | --silent | --silen | --sile | --sil)</span><br><span>     silent=yes ;;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+  -runstatedir | --runstatedir | --runstatedi | --runstated \</span><br><span style="color: hsl(120, 100%, 40%);">+  | --runstate | --runstat | --runsta | --runst | --runs \</span><br><span style="color: hsl(120, 100%, 40%);">+  | --run | --ru | --r)</span><br><span style="color: hsl(120, 100%, 40%);">+    ac_prev=runstatedir ;;</span><br><span style="color: hsl(120, 100%, 40%);">+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \</span><br><span style="color: hsl(120, 100%, 40%);">+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \</span><br><span style="color: hsl(120, 100%, 40%);">+  | --run=* | --ru=* | --r=*)</span><br><span style="color: hsl(120, 100%, 40%);">+    runstatedir=$ac_optarg ;;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)</span><br><span>     ac_prev=sbindir ;;</span><br><span>   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \</span><br><span>@@ -1921,7 +1932,7 @@</span><br><span> for ac_var in        exec_prefix prefix bindir sbindir libexecdir datarootdir \</span><br><span>           datadir sysconfdir sharedstatedir localstatedir includedir \</span><br><span>                 oldincludedir docdir infodir htmldir dvidir pdfdir psdir \</span><br><span style="color: hsl(0, 100%, 40%);">-              libdir localedir mandir</span><br><span style="color: hsl(120, 100%, 40%);">+               libdir localedir mandir runstatedir</span><br><span> do</span><br><span>   eval ac_val=\$$ac_var</span><br><span>   # Remove trailing slashes.</span><br><span>@@ -2074,6 +2085,7 @@</span><br><span>   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]</span><br><span>   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]</span><br><span>   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]</span><br><span style="color: hsl(120, 100%, 40%);">+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]</span><br><span>   --libdir=DIR            object code libraries [EPREFIX/lib]</span><br><span>   --includedir=DIR        C header files [PREFIX/include]</span><br><span>   --oldincludedir=DIR     C header files for non-gcc [/usr/include]</span><br><span>@@ -14906,7 +14918,7 @@</span><br><span>     We can't simply define LARGE_OFF_T to be 9223372036854775807,</span><br><span>     since some C++ compilers masquerading as C compilers</span><br><span>     incorrectly reject 9223372036854775807.  */</span><br><span style="color: hsl(0, 100%, 40%);">-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))</span><br><span style="color: hsl(120, 100%, 40%);">+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))</span><br><span>   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721</span><br><span>                     && LARGE_OFF_T % 2147483647 == 1)</span><br><span>                   ? 1 : -1];</span><br><span>@@ -14952,7 +14964,7 @@</span><br><span>     We can't simply define LARGE_OFF_T to be 9223372036854775807,</span><br><span>     since some C++ compilers masquerading as C compilers</span><br><span>     incorrectly reject 9223372036854775807.  */</span><br><span style="color: hsl(0, 100%, 40%);">-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))</span><br><span style="color: hsl(120, 100%, 40%);">+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))</span><br><span>   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721</span><br><span>                     && LARGE_OFF_T % 2147483647 == 1)</span><br><span>                   ? 1 : -1];</span><br><span>@@ -14976,7 +14988,7 @@</span><br><span>     We can't simply define LARGE_OFF_T to be 9223372036854775807,</span><br><span>     since some C++ compilers masquerading as C compilers</span><br><span>     incorrectly reject 9223372036854775807.  */</span><br><span style="color: hsl(0, 100%, 40%);">-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))</span><br><span style="color: hsl(120, 100%, 40%);">+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))</span><br><span>   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721</span><br><span>                     && LARGE_OFF_T % 2147483647 == 1)</span><br><span>                   ? 1 : -1];</span><br><span>@@ -15021,7 +15033,7 @@</span><br><span>     We can't simply define LARGE_OFF_T to be 9223372036854775807,</span><br><span>     since some C++ compilers masquerading as C compilers</span><br><span>     incorrectly reject 9223372036854775807.  */</span><br><span style="color: hsl(0, 100%, 40%);">-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))</span><br><span style="color: hsl(120, 100%, 40%);">+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))</span><br><span>   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721</span><br><span>                     && LARGE_OFF_T % 2147483647 == 1)</span><br><span>                   ? 1 : -1];</span><br><span>@@ -15045,7 +15057,7 @@</span><br><span>     We can't simply define LARGE_OFF_T to be 9223372036854775807,</span><br><span>     since some C++ compilers masquerading as C compilers</span><br><span>     incorrectly reject 9223372036854775807.  */</span><br><span style="color: hsl(0, 100%, 40%);">-#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))</span><br><span style="color: hsl(120, 100%, 40%);">+#define LARGE_OFF_T ((((off_t) 1 << 31) << 31) - 1 + (((off_t) 1 << 31) << 31))</span><br><span>   int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721</span><br><span>                     && LARGE_OFF_T % 2147483647 == 1)</span><br><span>                   ? 1 : -1];</span><br><span>@@ -16345,6 +16357,8 @@</span><br><span>     if (*(data + i) != *(data3 + i))</span><br><span>       return 14;</span><br><span>   close (fd);</span><br><span style="color: hsl(120, 100%, 40%);">+  free (data);</span><br><span style="color: hsl(120, 100%, 40%);">+  free (data3);</span><br><span>   return 0;</span><br><span> }</span><br><span> _ACEOF</span><br><span>@@ -16885,7 +16899,7 @@</span><br><span> done</span><br><span> </span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-for ac_func in asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl malloc_trim</span><br><span style="color: hsl(120, 100%, 40%);">+for ac_func in asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale pipe2 ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl malloc_trim</span><br><span> do :</span><br><span>   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`</span><br><span> ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"</span><br><span>@@ -17962,6 +17976,51 @@</span><br><span> fi</span><br><span> </span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if socket() accepts SOCK_NONBLOCK" >&5</span><br><span style="color: hsl(120, 100%, 40%);">+$as_echo_n "checking if socket() accepts SOCK_NONBLOCK... " >&6; }</span><br><span style="color: hsl(120, 100%, 40%);">+if test "$cross_compiling" = yes; then :</span><br><span style="color: hsl(120, 100%, 40%);">+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: cross-compile" >&5</span><br><span style="color: hsl(120, 100%, 40%);">+$as_echo "cross-compile" >&6; }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+else</span><br><span style="color: hsl(120, 100%, 40%);">+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext</span><br><span style="color: hsl(120, 100%, 40%);">+/* end confdefs.h.  */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   #ifdef HAVE_SYS_TYPES_H</span><br><span style="color: hsl(120, 100%, 40%);">+       # include <sys/types.h></span><br><span style="color: hsl(120, 100%, 40%);">+ #endif</span><br><span style="color: hsl(120, 100%, 40%);">+        #ifdef HAVE_SYS_SOCKET_H</span><br><span style="color: hsl(120, 100%, 40%);">+      # include <sys/socket.h></span><br><span style="color: hsl(120, 100%, 40%);">+        #endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int</span><br><span style="color: hsl(120, 100%, 40%);">+main ()</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 (socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+            return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+          }</span><br><span style="color: hsl(120, 100%, 40%);">+     return 0;</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%);">+  return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+_ACEOF</span><br><span style="color: hsl(120, 100%, 40%);">+if ac_fn_c_try_run "$LINENO"; then :</span><br><span style="color: hsl(120, 100%, 40%);">+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5</span><br><span style="color: hsl(120, 100%, 40%);">+$as_echo "yes" >&6; }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+$as_echo "#define HAVE_SOCK_NONBLOCK 1" >>confdefs.h</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+else</span><br><span style="color: hsl(120, 100%, 40%);">+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5</span><br><span style="color: hsl(120, 100%, 40%);">+$as_echo "no" >&6; }</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \</span><br><span style="color: hsl(120, 100%, 40%);">+  conftest.$ac_objext conftest.beam conftest.$ac_ext</span><br><span style="color: hsl(120, 100%, 40%);">+fi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we can increase the maximum select-able file descriptor" >&5</span><br><span> $as_echo_n "checking if we can increase the maximum select-able file descriptor... " >&6; }</span><br><span> if test "$cross_compiling" = yes; then :</span><br><span>diff --git a/configure.ac b/configure.ac</span><br><span>index aa70fe0..5383747 100644</span><br><span>--- a/configure.ac</span><br><span>+++ b/configure.ac</span><br><span>@@ -786,7 +786,7 @@</span><br><span> AC_FUNC_STRTOD</span><br><span> AC_FUNC_UTIME_NULL</span><br><span> AC_FUNC_VPRINTF</span><br><span style="color: hsl(0, 100%, 40%);">-AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl malloc_trim])</span><br><span style="color: hsl(120, 100%, 40%);">+AC_CHECK_FUNCS([asprintf atexit closefrom dup2 eaccess endpwent euidaccess ffsll ftruncate getcwd gethostbyname gethostname getloadavg gettimeofday glob ioperm inet_ntoa isascii memchr memmove memset mkdir mkdtemp munmap newlocale pipe2 ppoll putenv re_comp regcomp select setenv socket strcasecmp strcasestr strchr strcspn strdup strerror strlcat strlcpy strncasecmp strndup strnlen strrchr strsep strspn strstr strtod strtol strtold strtoq unsetenv uselocale utime vasprintf getpeereid sysctl swapctl malloc_trim])</span><br><span> </span><br><span> AC_MSG_CHECKING(for htonll)</span><br><span> AC_LINK_IFELSE(</span><br><span>@@ -1126,6 +1126,27 @@</span><br><span>         AC_MSG_RESULT(unknown)</span><br><span> )</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+AC_MSG_CHECKING([if socket() accepts SOCK_NONBLOCK])</span><br><span style="color: hsl(120, 100%, 40%);">+AC_RUN_IFELSE(</span><br><span style="color: hsl(120, 100%, 40%);">+[AC_LANG_PROGRAM([</span><br><span style="color: hsl(120, 100%, 40%);">+     #ifdef HAVE_SYS_TYPES_H</span><br><span style="color: hsl(120, 100%, 40%);">+       # include <sys/types.h></span><br><span style="color: hsl(120, 100%, 40%);">+ #endif</span><br><span style="color: hsl(120, 100%, 40%);">+        #ifdef HAVE_SYS_SOCKET_H</span><br><span style="color: hsl(120, 100%, 40%);">+      # include <sys/socket.h></span><br><span style="color: hsl(120, 100%, 40%);">+        #endif</span><br><span style="color: hsl(120, 100%, 40%);">+        ], [</span><br><span style="color: hsl(120, 100%, 40%);">+     if (socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+            return 1;</span><br><span style="color: hsl(120, 100%, 40%);">+          }</span><br><span style="color: hsl(120, 100%, 40%);">+     return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+  ])],</span><br><span style="color: hsl(120, 100%, 40%);">+  AC_MSG_RESULT(yes)</span><br><span style="color: hsl(120, 100%, 40%);">+    AC_DEFINE([HAVE_SOCK_NONBLOCK], 1, [Define to 1 if your socket() implementation can accept SOCK_NONBLOCK.]),</span><br><span style="color: hsl(120, 100%, 40%);">+  AC_MSG_RESULT(no),</span><br><span style="color: hsl(120, 100%, 40%);">+    AC_MSG_RESULT(cross-compile)</span><br><span style="color: hsl(120, 100%, 40%);">+)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> AC_MSG_CHECKING(if we can increase the maximum select-able file descriptor)</span><br><span> AC_RUN_IFELSE(</span><br><span> [AC_LANG_PROGRAM([</span><br><span>diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in</span><br><span>index 6bbd7f5..46e92df 100644</span><br><span>--- a/include/asterisk/autoconfig.h.in</span><br><span>+++ b/include/asterisk/autoconfig.h.in</span><br><span>@@ -609,6 +609,9 @@</span><br><span> /* Define to indicate presence of the pg_encoding_to_char API. */</span><br><span> #undef HAVE_PGSQL_pg_encoding_to_char</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Define to 1 if you have the `pipe2' function. */</span><br><span style="color: hsl(120, 100%, 40%);">+#undef HAVE_PIPE2</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Define if your system has the PJPROJECT libraries. */</span><br><span> #undef HAVE_PJPROJECT</span><br><span> </span><br><span>@@ -884,6 +887,9 @@</span><br><span> /* Define to 1 if you have the `socket' function. */</span><br><span> #undef HAVE_SOCKET</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/* Define to 1 if your socket() implementation can accept SOCK_NONBLOCK. */</span><br><span style="color: hsl(120, 100%, 40%);">+#undef HAVE_SOCK_NONBLOCK</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /* Define to 1 if your system has soxmix application. */</span><br><span> #undef HAVE_SOXMIX</span><br><span> </span><br><span>diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h</span><br><span>index f459b31..c0cce98 100644</span><br><span>--- a/include/asterisk/utils.h</span><br><span>+++ b/include/asterisk/utils.h</span><br><span>@@ -914,6 +914,40 @@</span><br><span>         const char *file, int lineno, const char *function);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Create a non-blocking socket</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.25</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Wrapper around socket(2) that sets the O_NONBLOCK flag on the resulting</span><br><span style="color: hsl(120, 100%, 40%);">+ * socket.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \details</span><br><span style="color: hsl(120, 100%, 40%);">+ * For parameter and return information, see the man page for</span><br><span style="color: hsl(120, 100%, 40%);">+ * socket(2).</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_SOCK_NONBLOCK</span><br><span style="color: hsl(120, 100%, 40%);">+# define ast_socket_nonblock(domain, type, protocol) socket((domain), (type) | SOCK_NONBLOCK, (protocol))</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_socket_nonblock(int domain, int type, int protocol);</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</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%);">+ * \brief Create a non-blocking pipe</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.25</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Wrapper around pipe(2) that sets the O_NONBLOCK flag on the resulting</span><br><span style="color: hsl(120, 100%, 40%);">+ * file descriptors.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \details</span><br><span style="color: hsl(120, 100%, 40%);">+ * For parameter and return information, see the man page for</span><br><span style="color: hsl(120, 100%, 40%);">+ * pipe(2).</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_PIPE2</span><br><span style="color: hsl(120, 100%, 40%);">+# define ast_pipe_nonblock(filedes) pipe2((filedes), O_NONBLOCK)</span><br><span style="color: hsl(120, 100%, 40%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_pipe_nonblock(int filedes[2]);</span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span>  * \brief Set the current thread's user interface status.</span><br><span>  *</span><br><span>  * \param is_user_interface Non-zero to mark the thread as a user interface.</span><br><span>diff --git a/main/alertpipe.c b/main/alertpipe.c</span><br><span>index 7932a73..9ff399d 100644</span><br><span>--- a/main/alertpipe.c</span><br><span>+++ b/main/alertpipe.c</span><br><span>@@ -51,6 +51,15 @@</span><br><span> </span><br><span> #endif</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#ifdef HAVE_PIPE2</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if (pipe2(alert_pipe, O_NONBLOCK)) {</span><br><span style="color: hsl(120, 100%, 40%);">+          ast_log(LOG_WARNING, "Failed to create alert pipe: %s\n", strerror(errno));</span><br><span style="color: hsl(120, 100%, 40%);">+         return -1;</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%);">+#else</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>         if (pipe(alert_pipe)) {</span><br><span>              ast_log(LOG_WARNING, "Failed to create alert pipe: %s\n", strerror(errno));</span><br><span>                return -1;</span><br><span>@@ -62,6 +71,8 @@</span><br><span>               }</span><br><span>    }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#endif</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>      return 0;</span><br><span> }</span><br><span> </span><br><span>diff --git a/main/utils.c b/main/utils.c</span><br><span>index a062763..e0b8a6e 100644</span><br><span>--- a/main/utils.c</span><br><span>+++ b/main/utils.c</span><br><span>@@ -2750,6 +2750,42 @@</span><br><span>     return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef HAVE_SOCK_NONBLOCK</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_socket_nonblock(int domain, int type, int protocol)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+        int s = socket(domain, type, protocol);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (s < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+               return -1;</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 (ast_fd_set_flags(s, O_NONBLOCK)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                close(s);</span><br><span style="color: hsl(120, 100%, 40%);">+             return -1;</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%);">+   return s;</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 style="color: hsl(120, 100%, 40%);">+#ifndef HAVE_PIPE2</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_pipe_nonblock(int filedes[2])</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  int p = pipe(filedes);</span><br><span style="color: hsl(120, 100%, 40%);">+        if (p < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+               return -1;</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 (ast_fd_set_flags(filedes[0], O_NONBLOCK)</span><br><span style="color: hsl(120, 100%, 40%);">+     || ast_fd_set_flags(filedes[1], O_NONBLOCK)) {</span><br><span style="color: hsl(120, 100%, 40%);">+             close(filedes[0]);</span><br><span style="color: hsl(120, 100%, 40%);">+            close(filedes[1]);</span><br><span style="color: hsl(120, 100%, 40%);">+            return -1;</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%);">+   return 0;</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> /*!</span><br><span>  * \brief A thread local indicating whether the current thread is a user interface.</span><br><span>  */</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10756">change 10756</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/10756"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I3ebe654fb549587537161506c6c950f4ab298bb0 </div>
<div style="display:none"> Gerrit-Change-Number: 10756 </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: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua C. Colp <jcolp@digium.com> </div>