[svn-commits] russell: trunk r182847 - in /trunk: ./ apps/ channels/ include/asterisk/ main...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 17 21:29:13 CDT 2009


Author: russell
Date: Tue Mar 17 21:28:55 2009
New Revision: 182847

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=182847
Log:
Merged revisions 182810 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r182810 | russell | 2009-03-17 21:09:13 -0500 (Tue, 17 Mar 2009) | 44 lines

Fix cases where the internal poll() was not being used when it needed to be.

We have seen a number of problems caused by poll() not working properly on 
Mac OSX.  If you search around, you'll find a number of references to using 
select() instead of poll() to work around these issues.  In Asterisk, we've 
had poll.c which implements poll() using select() internally.  However, we 
were still getting reports of problems.

vadim investigated a bit and realized that at least on his system, even 
though we were compiling in poll.o, the system poll() was still being used.  
So, the primary purpose of this patch is to ensure that we're using the 
internal poll() when we want it to be used.

The changes are:

1) Remove logic for when internal poll should be used from the Makefile.  
   Instead, put it in the configure script.  The logic in the configure 
   script is the same as it was in the Makefile.  Ideally, we would have 
   a functionality test for the problem, but that's not actually possible, 
   since we would have to be able to run an application on the _target_ 
   system to test poll() behavior.

2) Always include poll.o in the build, but it will be empty if AST_POLL_COMPAT
   is not defined.

3) Change uses of poll() throughout the source tree to ast_poll().  I feel 
   that it is good practice to give the API call a new name when we are 
   changing its behavior and not using the system version directly in all cases.
   So, normally, ast_poll() is just redefined to poll().  On systems where 
   AST_POLL_COMPAT is defined, ast_poll() is redefined to ast_internal_poll().

4) Change poll() in main/poll.c to be ast_internal_poll().

It's worth noting that any code that still uses poll() directly will work fine 
(if they worked fine before).  So, for example, out of tree modules that are 
using poll() will not stop working or anything.  However, for modules to work 
properly on Mac OSX, ast_poll() needs to be used.

(closes issue #13404)
Reported by: agalbraith
Tested by: russell, vadim

http://reviewboard.digium.com/r/198/

........

Modified:
    trunk/   (props changed)
    trunk/apps/app_mp3.c
    trunk/apps/app_nbscat.c
    trunk/channels/chan_alsa.c
    trunk/channels/chan_skinny.c
    trunk/configure
    trunk/configure.ac
    trunk/include/asterisk/autoconfig.h.in
    trunk/include/asterisk/channel.h
    trunk/include/asterisk/io.h
    trunk/include/asterisk/poll-compat.h
    trunk/main/Makefile
    trunk/main/asterisk.c
    trunk/main/channel.c
    trunk/main/io.c
    trunk/main/poll.c
    trunk/main/utils.c
    trunk/res/res_agi.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/apps/app_mp3.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/apps/app_mp3.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/apps/app_mp3.c (original)
+++ trunk/apps/app_mp3.c Tue Mar 17 21:28:55 2009
@@ -108,7 +108,7 @@
 	struct pollfd fds[1];
 	fds[0].fd = fd;
 	fds[0].events = POLLIN;
-	res = poll(fds, 1, timeout);
+	res = ast_poll(fds, 1, timeout);
 	if (res < 1) {
 		ast_log(LOG_NOTICE, "Poll timed out/errored out with %d\n", res);
 		return -1;

Modified: trunk/apps/app_nbscat.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/apps/app_nbscat.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/apps/app_nbscat.c (original)
+++ trunk/apps/app_nbscat.c Tue Mar 17 21:28:55 2009
@@ -96,7 +96,7 @@
 	struct pollfd fds[1];
 	fds[0].fd = fd;
 	fds[0].events = POLLIN;
-	res = poll(fds, 1, 2000);
+	res = ast_poll(fds, 1, 2000);
 	if (res < 1) {
 		ast_log(LOG_NOTICE, "Selected timed out/errored out with %d\n", res);
 		return -1;

Modified: trunk/channels/chan_alsa.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/channels/chan_alsa.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/channels/chan_alsa.c (original)
+++ trunk/channels/chan_alsa.c Tue Mar 17 21:28:55 2009
@@ -55,6 +55,7 @@
 #include "asterisk/stringfields.h"
 #include "asterisk/abstract_jb.h"
 #include "asterisk/musiconhold.h"
+#include "asterisk/poll-compat.h"
 
 /*! Global jitterbuffer configuration - by default, jb is disabled */
 static struct ast_jb_conf default_jbconf = {

Modified: trunk/channels/chan_skinny.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/channels/chan_skinny.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Tue Mar 17 21:28:55 2009
@@ -6248,7 +6248,7 @@
 	fds[0].fd = s->fd;
 	fds[0].events = POLLIN;
 	fds[0].revents = 0;
-	res = poll(fds, 1, (keep_alive * 1100)); /* If nothing has happen, client is dead */
+	res = ast_poll(fds, 1, (keep_alive * 1100)); /* If nothing has happen, client is dead */
 						 /* we add 10% to the keep_alive to deal */
 						 /* with network delays, etc */
 	if (res < 0) {

Modified: trunk/configure.ac
URL: http://svn.digium.com/svn-view/asterisk/trunk/configure.ac?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Tue Mar 17 21:28:55 2009
@@ -43,6 +43,9 @@
      fi
      CPPFLAGS=-I/usr/local/include
      LDFLAGS=-L/usr/local/lib
+     ;;
+     darwin*)
+     AC_DEFINE([AST_POLL_COMPAT], 1, [Define to 1 if internal poll should be used.])
      ;;
      *)
      ac_default_prefix=/usr
@@ -303,6 +306,10 @@
 AC_CHECK_HEADERS([arpa/inet.h fcntl.h inttypes.h libintl.h limits.h locale.h malloc.h netdb.h netinet/in.h stddef.h stdint.h stdlib.h string.h strings.h sys/file.h sys/ioctl.h sys/param.h sys/socket.h sys/time.h syslog.h termios.h unistd.h utime.h arpa/nameser.h sys/io.h])
 
 AC_CHECK_HEADERS([winsock.h winsock2.h])
+
+AC_CHECK_HEADER([sys/poll.h],
+	 [],
+     AC_DEFINE([AST_POLL_COMPAT], 1, [Define to 1 if internal poll should be used.]))
 
 AC_SYS_LARGEFILE
 

Modified: trunk/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/svn-view/asterisk/trunk/include/asterisk/autoconfig.h.in?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/include/asterisk/autoconfig.h.in (original)
+++ trunk/include/asterisk/autoconfig.h.in Tue Mar 17 21:28:55 2009
@@ -6,6 +6,9 @@
 #include "asterisk/buildopts.h"
 
 
+
+/* Define to 1 if internal poll should be used. */
+#undef AST_POLL_COMPAT
 
 /* Define to 1 if the `closedir' function returns void instead of `int'. */
 #undef CLOSEDIR_VOID

Modified: trunk/include/asterisk/channel.h
URL: http://svn.digium.com/svn-view/asterisk/trunk/include/asterisk/channel.h?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/include/asterisk/channel.h (original)
+++ trunk/include/asterisk/channel.h Tue Mar 17 21:28:55 2009
@@ -125,11 +125,7 @@
 
 #include "asterisk/abstract_jb.h"
 
-#ifdef HAVE_SYS_POLL_H
-#include <sys/poll.h>
-#else
 #include "asterisk/poll-compat.h"
-#endif
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {

Modified: trunk/include/asterisk/io.h
URL: http://svn.digium.com/svn-view/asterisk/trunk/include/asterisk/io.h?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/include/asterisk/io.h (original)
+++ trunk/include/asterisk/io.h Tue Mar 17 21:28:55 2009
@@ -23,11 +23,7 @@
 #ifndef _ASTERISK_IO_H
 #define _ASTERISK_IO_H
 
-#ifdef HAVE_SYS_POLL_H
-#include <sys/poll.h>		/* For POLL* constants */
-#else
 #include "asterisk/poll-compat.h"
-#endif
 
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {

Modified: trunk/include/asterisk/poll-compat.h
URL: http://svn.digium.com/svn-view/asterisk/trunk/include/asterisk/poll-compat.h?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/include/asterisk/poll-compat.h (original)
+++ trunk/include/asterisk/poll-compat.h Tue Mar 17 21:28:55 2009
@@ -76,8 +76,16 @@
 	original.
 \*---------------------------------------------------------------------------*/
 
-#ifndef _POLL_EMUL_H_
-#define _POLL_EMUL_H_
+#ifndef __AST_POLL_COMPAT_H
+#define __AST_POLL_COMPAT_H
+
+#ifndef AST_POLL_COMPAT
+
+#include <sys/poll.h>
+
+#define ast_poll(a, b, c) poll(a, b, c)
+
+#else /* AST_POLL_COMPAT */
 
 #define POLLIN		0x01
 #define POLLPRI		0x02
@@ -86,26 +94,24 @@
 #define POLLHUP		0x10
 #define POLLNVAL	0x20
 
-struct pollfd
-{
+struct pollfd {
     int     fd;
     short   events;
     short   revents;
 };
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
 
-#if (__STDC__ > 0) || defined(__cplusplus)
-extern int poll (struct pollfd *pArray, unsigned long n_fds, int timeout);
-#else
-extern int poll();
-#endif
+#define ast_poll(a, b, c) ast_internal_poll(a, b, c)
+
+int ast_internal_poll(struct pollfd *pArray, unsigned long n_fds, int timeout);
 
 #ifdef __cplusplus
 }
 #endif
 
-#endif /* _POLL_EMUL_H_ */
+#endif /* AST_POLL_COMPAT */
+
+#endif /* __AST_POLL_COMPAT_H */

Modified: trunk/main/Makefile
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/Makefile?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/main/Makefile (original)
+++ trunk/main/Makefile Tue Mar 17 21:28:55 2009
@@ -29,7 +29,7 @@
 	strcompat.o threadstorage.o dial.o event.o adsistub.o audiohook.o \
 	astobj2.o hashtab.o global_datastores.o version.o \
 	features.o taskprocessor.o timing.o datastore.o xml.o xmldoc.o \
-	strings.o bridging.o
+	strings.o bridging.o poll.o
 
 # we need to link in the objects statically, not as a library, because
 # otherwise modules will not have them available if none of the static
@@ -43,14 +43,6 @@
 AST_LIBS += $(OPENSSL_LIB)
 AST_LIBS += $(BKTR_LIB)
 AST_LIBS += $(LIBXML2_LIB) 
-
-ifeq ($(POLL_AVAILABLE),)
-  OBJS+=poll.o
-else
-  ifneq ($(findstring darwin,$(OSARCH)),)
-    OBJS+=poll.o
-  endif
-endif
 
 ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc linux-gnueabi ),)
   ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/asterisk.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Tue Mar 17 21:28:55 2009
@@ -137,6 +137,7 @@
 #include "asterisk/dsp.h"
 #include "asterisk/buildinfo.h"
 #include "asterisk/xmldoc.h"
+#include "asterisk/poll-compat.h"
 
 #include "asterisk/doxyref.h"		/* Doxygen documentation */
 
@@ -1213,7 +1214,7 @@
 		fds[1].events = POLLIN;
 		fds[1].revents = 0;
 
-		res = poll(fds, 2, -1);
+		res = ast_poll(fds, 2, -1);
 		if (res < 0) {
 			if (errno != EINTR)
 				ast_log(LOG_WARNING, "poll returned < 0: %s\n", strerror(errno));
@@ -1266,7 +1267,7 @@
 			return NULL;
 		fds[0].fd = ast_socket;
 		fds[0].events = POLLIN;
-		s = poll(fds, 1, -1);
+		s = ast_poll(fds, 1, -1);
 		pthread_testcancel();
 		if (s < 0) {
 			if (errno != EINTR)
@@ -2081,7 +2082,7 @@
 			fds[1].events = POLLIN;
 			max++;
 		}
-		res = poll(fds, max, -1);
+		res = ast_poll(fds, max, -1);
 		if (res < 0) {
 			if (sig_flags.need_quit)
 				break;
@@ -2649,7 +2650,7 @@
 		fds.fd = ast_consock;
 		fds.events = POLLIN;
 		fds.revents = 0;
-		while (poll(&fds, 1, 500) > 0) {
+		while (ast_poll(&fds, 1, 500) > 0) {
 			char buffer[512] = "", *curline = buffer, *nextline;
 			int not_written = 1;
 
@@ -3013,7 +3014,7 @@
 	for (;;) {
 		struct pollfd p = { sig_alert_pipe[0], POLLIN, 0 };
 		int a;
-		poll(&p, 1, -1);
+		ast_poll(&p, 1, -1);
 		if (sig_flags.need_reload) {
 			sig_flags.need_reload = 0;
 			ast_module_reload(NULL);

Modified: trunk/main/channel.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/channel.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Tue Mar 17 21:28:55 2009
@@ -2029,12 +2029,12 @@
 			int kbrms = rms;
 			if (kbrms > 600000)
 				kbrms = 600000;
-			res = poll(pfds, max, kbrms);
+			res = ast_poll(pfds, max, kbrms);
 			if (!res)
 				rms -= kbrms;
 		} while (!res && (rms > 0));
 	} else {
-		res = poll(pfds, max, rms);
+		res = ast_poll(pfds, max, rms);
 	}
 	for (x = 0; x < n; x++)
 		ast_clear_flag(c[x], AST_FLAG_BLOCKING);

Modified: trunk/main/io.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/io.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/main/io.c (original)
+++ trunk/main/io.c Tue Mar 17 21:28:55 2009
@@ -272,8 +272,9 @@
 
 	DEBUG(ast_debug(1, "ast_io_wait()\n"));
 
-	if ((res = poll(ioc->fds, ioc->fdcnt, howlong)) <= 0)
+	if ((res = ast_poll(ioc->fds, ioc->fdcnt, howlong)) <= 0) {
 		return res;
+	}
 
 	/* At least one event tripped */
 	origcnt = ioc->fdcnt;

Modified: trunk/main/poll.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/poll.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/main/poll.c (original)
+++ trunk/main/poll.c Tue Mar 17 21:28:55 2009
@@ -71,6 +71,8 @@
 				 Includes
 \*---------------------------------------------------------------------------*/
 
+#include "asterisk.h"
+
 #include <unistd.h>			     /* standard Unix definitions */
 #include <sys/types.h>                       /* system types */
 #include <sys/time.h>                        /* time definitions */
@@ -79,6 +81,8 @@
 
 #include "asterisk/poll-compat.h"                            /* this package */
 
+#ifdef AST_POLL_COMPAT
+
 /*---------------------------------------------------------------------------*\
 				  Macros
 \*---------------------------------------------------------------------------*/
@@ -87,7 +91,6 @@
 #define MAX(a,b)	((a) > (b) ? (a) : (b))
 #endif
 
-
 /*---------------------------------------------------------------------------*\
 			     Private Functions
 \*---------------------------------------------------------------------------*/
@@ -203,7 +206,7 @@
 
 	return pResult;
 }
-
+
 static void map_select_results
 #if __STDC__ > 0
 			 (struct pollfd *pArray,
@@ -246,22 +249,12 @@
 
 	return;
 }
-
+
 /*---------------------------------------------------------------------------*\
 			     Public Functions
 \*---------------------------------------------------------------------------*/
 
-int poll
-
-#if __STDC__ > 0
-	(struct pollfd *pArray, unsigned long n_fds, int timeout)
-#else
-	(pArray, n_fds, timeout)
-	 struct	       pollfd *pArray;
-	 unsigned long n_fds;
-	 int	       timeout;
-#endif
-
+int ast_internal_poll(struct pollfd *pArray, unsigned long n_fds, int timeout)
 {
 	fd_set  read_descs;                          /* input file descs */
 	fd_set  write_descs;                         /* output file descs */
@@ -295,3 +288,5 @@
 
 	return ready_descriptors;
 }
+
+#endif /* AST_POLL_COMPAT */

Modified: trunk/main/utils.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/utils.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Tue Mar 17 21:28:55 2009
@@ -1054,7 +1054,7 @@
 	memset(pfd, 0, sizeof(pfd));
 	pfd[0].fd = fd;
 	pfd[0].events = POLLIN|POLLPRI;
-	return poll(pfd, 1, ms);
+	return ast_poll(pfd, 1, ms);
 }
 
 static int ast_wait_for_output(int fd, int timeoutms)
@@ -1068,7 +1068,7 @@
 	int elapsed = 0;
 
 	/* poll() until the fd is writable without blocking */
-	while ((res = poll(&pfd, 1, timeoutms - elapsed)) <= 0) {
+	while ((res = ast_poll(&pfd, 1, timeoutms - elapsed)) <= 0) {
 		if (res == 0) {
 			/* timed out. */
 			ast_log(LOG_NOTICE, "Timed out trying to write\n");

Modified: trunk/res/res_agi.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/res/res_agi.c?view=diff&rev=182847&r1=182846&r2=182847
==============================================================================
--- trunk/res/res_agi.c (original)
+++ trunk/res/res_agi.c Tue Mar 17 21:28:55 2009
@@ -814,7 +814,7 @@
 
 	pfds[0].fd = s;
 	pfds[0].events = POLLOUT;
-	while ((res = poll(pfds, 1, MAX_AGI_CONNECT)) != 1) {
+	while ((res = ast_poll(pfds, 1, MAX_AGI_CONNECT)) != 1) {
 		if (errno != EINTR) {
 			if (!res) {
 				ast_log(LOG_WARNING, "FastAGI connection to '%s' timed out after MAX_AGI_CONNECT (%d) milliseconds.\n",




More information about the svn-commits mailing list