diff options
author | Tilghman Lesher <tilghman@meg.abyt.es> | 2010-09-02 05:02:54 +0000 |
---|---|---|
committer | Tilghman Lesher <tilghman@meg.abyt.es> | 2010-09-02 05:02:54 +0000 |
commit | 5eae9f44f74f9869e46e416a2d5d092834043483 (patch) | |
tree | afc6eb9b08ef4ba9f7e0ad1bb4a59b13d5269d90 /res/res_pktccops.c | |
parent | c28c620936e31ec5a63147ae20d82d621541ae90 (diff) |
Merged revisions 284597 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
................
r284597 | tilghman | 2010-09-02 00:00:34 -0500 (Thu, 02 Sep 2010) | 29 lines
Merged revisions 284593,284595 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.6.2
................
r284593 | tilghman | 2010-09-01 17:59:50 -0500 (Wed, 01 Sep 2010) | 18 lines
Merged revisions 284478 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r284478 | tilghman | 2010-09-01 13:49:11 -0500 (Wed, 01 Sep 2010) | 11 lines
Ensure that all areas that previously used select(2) now use poll(2), with implementations that need poll(2) implemented with select(2) safe against 1024-bit overflows.
This is a followup to the fix for the pthread timer in 1.6.2 and beyond, fixing
a potential crash bug in all supported releases.
(closes issue #17678)
Reported by: russell
Branch: https://origsvn.digium.com/svn/asterisk/team/tilghman/ast_select
Review: https://reviewboard.asterisk.org/r/824/
........
................
r284595 | tilghman | 2010-09-01 22:57:43 -0500 (Wed, 01 Sep 2010) | 2 lines
Failed to rerun bootstrap.sh after last commit
................
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@284598 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pktccops.c')
-rw-r--r-- | res/res_pktccops.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/res/res_pktccops.c b/res/res_pktccops.c index 8069e723d..33ecc3817 100644 --- a/res/res_pktccops.c +++ b/res/res_pktccops.c @@ -703,9 +703,8 @@ static void *do_pktccops(void *data) int res, nfds, len; struct copsmsg *recmsg, *sendmsg; struct copsmsg recmsgb, sendmsgb; - fd_set rfds; - struct timeval tv; - struct pktcobj *pobject; + struct pollfd *pfds = NULL, *tmp; + struct pktcobj *pobject; struct cops_cmts *cmts; struct cops_gate *gate; char *sobjp; @@ -719,9 +718,8 @@ static void *do_pktccops(void *data) ast_debug(3, "COPS: thread started\n"); for (;;) { - tv.tv_sec = 1; - tv.tv_usec = 0; - FD_ZERO(&rfds); + ast_free(pfds); + pfds = NULL; nfds = 0; AST_LIST_LOCK(&cmts_list); AST_LIST_TRAVERSE(&cmts_list, cmts, list) { @@ -735,15 +733,27 @@ static void *do_pktccops(void *data) } } if (cmts->sfd > 0) { - FD_SET(cmts->sfd, &rfds); - if (cmts->sfd > nfds) nfds = cmts->sfd; + if (!(tmp = ast_realloc(pfds, (nfds + 1) * sizeof(*pfds)))) { + continue; + } + pfds = tmp; + pfds[nfds].fd = cmts->sfd; + pfds[nfds].events = POLLIN; + pfds[nfds].revents = 0; + nfds++; } else { cmts->sfd = cops_connect(cmts->host, cmts->port); if (cmts->sfd > 0) { cmts->state = 1; if (cmts->sfd > 0) { - FD_SET(cmts->sfd, &rfds); - if (cmts->sfd > nfds) nfds = cmts->sfd; + if (!(tmp = ast_realloc(pfds, (nfds + 1) * sizeof(*pfds)))) { + continue; + } + pfds = tmp; + pfds[nfds].fd = cmts->sfd; + pfds[nfds].events = POLLIN; + pfds[nfds].revents = 0; + nfds++; } } } @@ -781,10 +791,11 @@ static void *do_pktccops(void *data) if (pktcreload == 2) { pktcreload = 0; } - if ((res = select(nfds + 1, &rfds, NULL, NULL, &tv))) { + if ((res = ast_poll(pfds, nfds, 1000))) { AST_LIST_LOCK(&cmts_list); AST_LIST_TRAVERSE(&cmts_list, cmts, list) { - if (FD_ISSET(cmts->sfd, &rfds)) { + int idx; + if ((idx = ast_poll_fd_index(pfds, nfds, cmts->sfd)) > -1 && (pfds[idx].revents & POLLIN)) { len = cops_getmsg(cmts->sfd, recmsg); if (len > 0) { ast_debug(3, "COPS: got from %s:\n Header: versflag=0x%.2x opcode=%i clienttype=0x%.4x msglength=%i\n", |