aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-18 14:32:47 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2009-03-18 14:32:47 +0000
commitd47911e89926ae860452f14159306f636677dd32 (patch)
tree0429fde883aee5da81cec0280b5c58a330b71e71 /main
parent1f818fd0f248e3b0c477efecc870f4b1fb1af3f5 (diff)
Merged revisions 182847 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ................ r182847 | russell | 2009-03-17 21:28:55 -0500 (Tue, 17 Mar 2009) | 52 lines 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/ ........ ................ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.1@182946 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/Makefile11
-rw-r--r--main/asterisk.c11
-rw-r--r--main/channel.c4
-rw-r--r--main/io.c3
-rw-r--r--main/poll.c23
-rw-r--r--main/utils.c4
6 files changed, 22 insertions, 34 deletions
diff --git a/main/Makefile b/main/Makefile
index 2e5e6bc65..5b9c83b71 100644
--- a/main/Makefile
+++ b/main/Makefile
@@ -28,7 +28,7 @@ OBJS= tcptls.o io.o sched.o logger.o frame.o loader.o config.o channel.o \
cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \
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
+ features.o taskprocessor.o timing.o datastore.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
@@ -42,15 +42,6 @@ OBJS+=say.o
AST_LIBS += $(SSL_LIB)
AST_LIBS += $(BKTR_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)),)
AST_LIBS+=-ldl
diff --git a/main/asterisk.c b/main/asterisk.c
index 358f68037..fe64ce8bb 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -117,6 +117,7 @@ int daemon(int, int); /* defined in libresolv of all places */
#include "asterisk/devicestate.h"
#include "asterisk/module.h"
#include "asterisk/dsp.h"
+#include "asterisk/poll-compat.h"
#include "asterisk/doxyref.h" /* Doxygen documentation */
@@ -1023,7 +1024,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));
@@ -1074,7 +1075,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)
@@ -1939,7 +1940,7 @@ static int ast_el_read_char(EditLine *editline, 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;
@@ -2521,7 +2522,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 buffer[512] = "", *curline = buffer, *nextline;
int not_written = 1;
@@ -2865,7 +2866,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 bfdcee894..9c3eeaf8f 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -2004,12 +2004,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 68b73d26c..8d51f4936 100644
--- a/main/io.c
+++ b/main/io.c
@@ -272,8 +272,9 @@ int ast_io_wait(struct io_context *ioc, int howlong)
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;
diff --git a/main/poll.c b/main/poll.c
index 823d0cbd4..bb93125a6 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
\*---------------------------------------------------------------------------*/
@@ -203,7 +206,7 @@ static struct timeval *map_timeout
return pResult;
}
-
+
static void map_select_results
#if __STDC__ > 0
(struct pollfd *pArray,
@@ -246,22 +249,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 */
@@ -295,3 +288,5 @@ int poll
return ready_descriptors;
}
+
+#endif /* AST_POLL_COMPAT */
diff --git a/main/utils.c b/main/utils.c
index 416025c62..954b9ff4e 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -1054,7 +1054,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);
}
static int ast_wait_for_output(int fd, int timeoutms)
@@ -1068,7 +1068,7 @@ static int ast_wait_for_output(int fd, int timeoutms)
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");