Index: channels/chan_dahdi.c =================================================================== --- channels/chan_dahdi.c (revision 189119) +++ channels/chan_dahdi.c (working copy) @@ -6510,7 +6510,7 @@ ast_setstate(chan, AST_STATE_RING); while (time(NULL) < start + 3) { res = ast_waitfor(chan, 1000); - if (res) { + if (res > 0) { f = ast_read(chan); if (!f) { ast_log(LOG_WARNING, "Whoa, hangup while waiting for first ring!\n"); Index: main/channel.c =================================================================== --- main/channel.c (revision 189119) +++ main/channel.c (working copy) @@ -1823,9 +1823,10 @@ { int oldms = ms; /* -1 if no timeout */ - ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms); - if ((ms < 0) && (oldms < 0)) - ms = 0; + c = ast_waitfor_nandfds(&c, 1, NULL, 0, NULL, NULL, &ms); + if (c && oldms < 0) { + ms = 1; + } return ms; } @@ -2039,12 +2040,6 @@ usleep(1); } - if (chan->fdno == -1) { - ast_log(LOG_ERROR, "ast_read() called with no recorded file descriptor.\n"); - f = &ast_null_frame; - goto done; - } - if (chan->masq) { if (ast_do_masquerade(chan)) ast_log(LOG_WARNING, "Failed to perform masquerade\n"); @@ -2059,6 +2054,12 @@ ast_deactivate_generator(chan); goto done; } + + if (chan->fdno == -1) { + ast_log(LOG_ERROR, "ast_read() called with no recorded file descriptor.\n"); + f = &ast_null_frame; + goto done; + } prestate = chan->_state; /* Read and ignore anything on the alertpipe, but read only @@ -4502,12 +4503,16 @@ return res; /* Give us some wiggle room */ - while (chan->generatordata && ast_waitfor(chan, 100) >= 0) { - struct ast_frame *f = ast_read(chan); - if (f) + while (chan->generatordata && (res = ast_waitfor(chan, 100)) >= 0) { + struct ast_frame *f; + if (!res) { + continue; + } + if ((f = ast_read(chan))) { ast_frfree(f); - else + } else { return -1; + } } return 0; } Index: res/res_agi.c =================================================================== --- res/res_agi.c (revision 189119) +++ res/res_agi.c (working copy) @@ -1004,6 +1004,9 @@ ast_dsp_free(sildet); return RESULT_FAILURE; } + if (res == 0) { + continue; + } f = ast_read(chan); if (!f) { fdprintf(agi->fd, "200 result=%d (hangup) endpos=%ld\n", -1, sample_offset);