diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-04-25 20:42:45 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-04-25 20:42:45 +0000 |
commit | 4ab2b33bfff1628f3c21fbbd43e2db5c568862c5 (patch) | |
tree | 0520b52676690d8c020be12e27ae76e465d192fc /manager.c | |
parent | 5641552590431c923e5eda43d356379a5aa67d8f (diff) |
Properly migrate from select to poll for core asterisk.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2760 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'manager.c')
-rwxr-xr-x | manager.c | 20 |
1 files changed, 9 insertions, 11 deletions
@@ -25,6 +25,7 @@ #include <signal.h> #include <errno.h> #include <unistd.h> +#include <sys/poll.h> #include <asterisk/channel.h> #include <asterisk/file.h> #include <asterisk/manager.h> @@ -68,8 +69,7 @@ int ast_carefulwrite(int fd, char *s, int len, int timeoutms) /* Try to write string, but wait no more than ms milliseconds before timing out */ int res=0; - struct timeval tv; - fd_set fds; + struct pollfd fds[1]; while(len) { res = write(fd, s, len); if ((res < 0) && (errno != EAGAIN)) { @@ -78,12 +78,10 @@ int ast_carefulwrite(int fd, char *s, int len, int timeoutms) if (res < 0) res = 0; len -= res; s += res; - tv.tv_sec = timeoutms / 1000; - tv.tv_usec = timeoutms % 1000; - FD_ZERO(&fds); - FD_SET(fd, &fds); + fds[0].fd = fd; + fds[0].events = POLLOUT; /* Wait until writable again */ - res = select(fd + 1, NULL, &fds, NULL, &tv); + res = poll(fds, 1, timeoutms); if (res < 1) return -1; } @@ -715,7 +713,7 @@ static int get_input(struct mansession *s, char *output) /* output must have at least sizeof(s->inbuf) space */ int res; int x; - fd_set fds; + struct pollfd fds[1]; for (x=1;x<s->inlen;x++) { if ((s->inbuf[x] == '\n') && (s->inbuf[x-1] == '\r')) { /* Copy output data up to and including \r\n */ @@ -732,9 +730,9 @@ static int get_input(struct mansession *s, char *output) ast_log(LOG_WARNING, "Dumping long line with no return from %s: %s\n", inet_ntoa(s->sin.sin_addr), s->inbuf); s->inlen = 0; } - FD_ZERO(&fds); - FD_SET(s->fd, &fds); - res = ast_select(s->fd + 1, &fds, NULL, NULL, NULL); + fds[0].fd = s->fd; + fds[0].events = POLLIN; + res = poll(fds, 1, -1); if (res < 0) { ast_log(LOG_WARNING, "Select returned error: %s\n", strerror(errno)); } else if (res > 0) { |