aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-18 02:09:13 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-18 02:09:13 +0000
commit91586477bbe6336c9debddf804edb8d02db71ab6 (patch)
tree1a985d7fb6aab02b48d7176a698f2268f15f44a4 /main
parentab574c1a269daa27014b5f5eb315ec1332d9a13c (diff)
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/ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@182810 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/Makefile12
-rw-r--r--main/asterisk.c11
-rw-r--r--main/channel.c4
-rw-r--r--main/io.c2
-rw-r--r--main/manager.c4
-rw-r--r--main/poll.c23
-rw-r--r--main/utils.c4
7 files changed, 23 insertions, 37 deletions
diff --git a/main/Makefile b/main/Makefile
index 0b83191e0..38d49f34c 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -27,7 +27,7 @@ OBJS= io.o sched.o logger.o frame.o loader.o config.o channel.o \
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
@@ -38,16 +38,6 @@ OBJS+=stdtime/localtime.o
# 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)),)
AST_LIBS+=-ldl
diff --git a/main/asterisk.c b/main/asterisk.c
index 9d4c92cb0..2cabfc272 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -123,6 +123,7 @@ int daemon(int, int); /* defined in libresolv of all places */
#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 @@ static void *netconsole(void *vconsole)
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 @@ static void *listener(void *unused)
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 @@ static int ast_el_read_char(EditLine *el, char *cp)
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 @@ static void ast_remotecontrol(char *data)
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 @@ static void *monitor_sig_flags(void *unused)
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);
diff --git a/main/channel.c b/main/channel.c
index 475942163..5d3eb9b35 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -1754,12 +1754,12 @@ struct ast_channel *ast_waitfor_nandfds(struct ast_channel **c, int n, int *fds,
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);
diff --git a/main/io.c b/main/io.c
index ced692180..7947cdedc 100644
--- a/main/io.c
+++ b/main/io.c
@@ -263,7 +263,7 @@ int ast_io_wait(struct io_context *ioc, int howlong)
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
diff --git a/main/manager.c b/main/manager.c
index 8b795a86f..e88af7f98 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -2287,7 +2287,7 @@ static int get_input(struct mansession *s, char *output)
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 @@ static void *accept_thread(void *ignore)
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) {
diff --git a/main/poll.c b/main/poll.c
index c053ba015..aba6e593e 100644
--- a/main/poll.c
+++ b/main/poll.c
@@ -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 @@ static struct timeval *map_timeout
return pResult;
}
-
+
static void map_select_results
#if __STDC__ > 0
(struct pollfd *pArray,
@@ -251,22 +254,12 @@ static void map_select_results
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 @@ int poll
return ready_descriptors;
}
+
+#endif /* AST_POLL_COMPAT */
diff --git a/main/utils.c b/main/utils.c
index 0b96d8b88..6ff44dd48 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -916,7 +916,7 @@ int ast_wait_for_input(int fd, int ms)
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 @@ int ast_carefulwrite(int fd, char *s, int len, int timeoutms)
};
/* 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");