[asterisk-commits] russell: branch 1.4 r182810 - in /branches/1.4: ./ apps/ channels/ include/as...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Mar 17 21:09:19 CDT 2009
Author: russell
Date: Tue Mar 17 21:09:13 2009
New Revision: 182810
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=182810
Log:
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:
branches/1.4/apps/app_mp3.c
branches/1.4/apps/app_nbscat.c
branches/1.4/channels/chan_alsa.c
branches/1.4/channels/chan_skinny.c
branches/1.4/configure
branches/1.4/configure.ac
branches/1.4/include/asterisk/autoconfig.h.in
branches/1.4/include/asterisk/channel.h
branches/1.4/include/asterisk/io.h
branches/1.4/include/asterisk/poll-compat.h
branches/1.4/main/Makefile
branches/1.4/main/asterisk.c
branches/1.4/main/channel.c
branches/1.4/main/io.c
branches/1.4/main/manager.c
branches/1.4/main/poll.c
branches/1.4/main/utils.c
branches/1.4/res/res_agi.c
Modified: branches/1.4/apps/app_mp3.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/apps/app_mp3.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/apps/app_mp3.c (original)
+++ branches/1.4/apps/app_mp3.c Tue Mar 17 21:09:13 2009
@@ -131,7 +131,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: branches/1.4/apps/app_nbscat.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/apps/app_nbscat.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/apps/app_nbscat.c (original)
+++ branches/1.4/apps/app_nbscat.c Tue Mar 17 21:09:13 2009
@@ -123,7 +123,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: branches/1.4/channels/chan_alsa.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/channels/chan_alsa.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/channels/chan_alsa.c (original)
+++ branches/1.4/channels/chan_alsa.c Tue Mar 17 21:09:13 2009
@@ -62,6 +62,7 @@
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/musiconhold.h"
+#include "asterisk/poll-compat.h"
#include "busy_tone.h"
#include "ring_tone.h"
Modified: branches/1.4/channels/chan_skinny.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/channels/chan_skinny.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/channels/chan_skinny.c (original)
+++ branches/1.4/channels/chan_skinny.c Tue Mar 17 21:09:13 2009
@@ -4441,7 +4441,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: branches/1.4/configure.ac
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/configure.ac?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/configure.ac (original)
+++ branches/1.4/configure.ac Tue Mar 17 21:09:13 2009
@@ -24,6 +24,9 @@
ac_default_prefix=/usr/local
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
@@ -225,6 +228,10 @@
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
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_HEADER([sys/poll.h],
+ [],
+ AC_DEFINE([AST_POLL_COMPAT], 1, [Define to 1 if internal poll should be used.]))
AC_SYS_LARGEFILE
Modified: branches/1.4/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/include/asterisk/autoconfig.h.in?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/include/asterisk/autoconfig.h.in (original)
+++ branches/1.4/include/asterisk/autoconfig.h.in Tue Mar 17 21:09:13 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: branches/1.4/include/asterisk/channel.h
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/include/asterisk/channel.h?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/include/asterisk/channel.h (original)
+++ branches/1.4/include/asterisk/channel.h Tue Mar 17 21:09:13 2009
@@ -90,11 +90,8 @@
#include "asterisk/abstract_jb.h"
#include <unistd.h>
-#ifdef POLLCOMPAT
+
#include "asterisk/poll-compat.h"
-#else
-#include <sys/poll.h>
-#endif
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
Modified: branches/1.4/include/asterisk/io.h
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/include/asterisk/io.h?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/include/asterisk/io.h (original)
+++ branches/1.4/include/asterisk/io.h Tue Mar 17 21:09:13 2009
@@ -23,11 +23,7 @@
#ifndef _ASTERISK_IO_H
#define _ASTERISK_IO_H
-#ifdef POLLCOMPAT
#include "asterisk/poll-compat.h"
-#else
-#include <sys/poll.h> /* For POLL* constants */
-#endif
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
Modified: branches/1.4/include/asterisk/poll-compat.h
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/include/asterisk/poll-compat.h?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/include/asterisk/poll-compat.h (original)
+++ branches/1.4/include/asterisk/poll-compat.h Tue Mar 17 21:09:13 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: branches/1.4/main/Makefile
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/Makefile?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/main/Makefile (original)
+++ branches/1.4/main/Makefile Tue Mar 17 21:09:13 2009
@@ -27,7 +27,7 @@
netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \
strcompat.o threadstorage.o dial.o astobj2.o global_datastores.o \
- audiohook.o
+ audiohook.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
@@ -37,16 +37,6 @@
# At the moment say.o is an optional component which can be overridden
# by a module.
OBJS+=say.o
-
-ifneq ($(findstring darwin,$(OSARCH)),)
- OBJS+=poll.o
- ASTCFLAGS+=-DPOLLCOMPAT
-else
- ifeq ($(wildcard /usr/include/sys/poll.h),)
- OBJS+=poll.o
- ASTCFLAGS+=-DPOLLCOMPAT
- endif
-endif
ifneq ($(findstring $(OSARCH), linux-gnu uclinux linux-uclibc linux-gnueabi ),)
ifneq ($(findstring LOADABLE_MODULES,$(MENUSELECT_CFLAGS)),)
Modified: branches/1.4/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/asterisk.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/main/asterisk.c (original)
+++ branches/1.4/main/asterisk.c Tue Mar 17 21:09:13 2009
@@ -123,6 +123,7 @@
#include "asterisk/linkedlists.h"
#include "asterisk/devicestate.h"
#include "asterisk/module.h"
+#include "asterisk/poll-compat.h"
#include "asterisk/doxyref.h" /* Doxygen documentation */
@@ -955,7 +956,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));
@@ -1006,7 +1007,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)
@@ -1784,7 +1785,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;
@@ -2379,7 +2380,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 buf[512] = "", *curline = buf, *nextline;
int not_written = 1;
@@ -2668,7 +2669,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: branches/1.4/main/channel.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/channel.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/main/channel.c (original)
+++ branches/1.4/main/channel.c Tue Mar 17 21:09:13 2009
@@ -1754,12 +1754,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: branches/1.4/main/io.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/io.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/main/io.c (original)
+++ branches/1.4/main/io.c Tue Mar 17 21:09:13 2009
@@ -263,7 +263,7 @@
int x;
int origcnt;
DEBUG(ast_log(LOG_DEBUG, "ast_io_wait()\n"));
- res = poll(ioc->fds, ioc->fdcnt, howlong);
+ res = ast_poll(ioc->fds, ioc->fdcnt, howlong);
if (res > 0) {
/*
* At least one event
Modified: branches/1.4/main/manager.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/manager.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/main/manager.c (original)
+++ branches/1.4/main/manager.c Tue Mar 17 21:09:13 2009
@@ -2287,7 +2287,7 @@
s->waiting_thread = pthread_self();
ast_mutex_unlock(&s->__lock);
- res = poll(fds, 1, -1);
+ res = ast_poll(fds, 1, -1);
ast_mutex_lock(&s->__lock);
s->waiting_thread = AST_PTHREADT_NULL;
@@ -2431,7 +2431,7 @@
pfds[0].events = POLLIN;
/* Wait for something to happen, but timeout every few seconds so
we can ditch any old manager sessions */
- if (poll(pfds, 1, 5000) < 1)
+ if (ast_poll(pfds, 1, 5000) < 1)
continue;
as = accept(asock, (struct sockaddr *)&sin, &sinlen);
if (as < 0) {
Modified: branches/1.4/main/poll.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/poll.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/main/poll.c (original)
+++ branches/1.4/main/poll.c Tue Mar 17 21:09:13 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
\*---------------------------------------------------------------------------*/
@@ -209,7 +212,7 @@
return pResult;
}
-
+
static void map_select_results
#if __STDC__ > 0
(struct pollfd *pArray,
@@ -251,22 +254,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 */
@@ -304,3 +297,5 @@
return ready_descriptors;
}
+
+#endif /* AST_POLL_COMPAT */
Modified: branches/1.4/main/utils.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/main/utils.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/main/utils.c (original)
+++ branches/1.4/main/utils.c Tue Mar 17 21:09:13 2009
@@ -916,7 +916,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);
}
int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
@@ -932,7 +932,7 @@
};
/* 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: branches/1.4/res/res_agi.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.4/res/res_agi.c?view=diff&rev=182810&r1=182809&r2=182810
==============================================================================
--- branches/1.4/res/res_agi.c (original)
+++ branches/1.4/res/res_agi.c Tue Mar 17 21:09:13 2009
@@ -221,7 +221,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",
@@ -2269,7 +2269,7 @@
}
pthread_testcancel();
/* Wait for 60 seconds, without engaging in a busy loop. */
- poll(NULL, 0, 60000);
+ ast_poll(NULL, 0, 60000);
}
return NULL;
}
More information about the asterisk-commits
mailing list