]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Make it easier to detect an improper call to ast_read().
authorRussell Bryant <russell@russellbryant.com>
Tue, 3 Mar 2009 13:53:52 +0000 (13:53 +0000)
committerRussell Bryant <russell@russellbryant.com>
Tue, 3 Mar 2009 13:53:52 +0000 (13:53 +0000)
When you call ast_waitfor() on a channel, the index into the channel fds array
that holds the file descriptor that poll() determines has input available is
stored in fdno.  This patch clears out this value after a call to ast_read()
and also reports errors if ast_read() is called without an fdno set.

From a discussion on the asterisk-dev list.

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@179608 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/channel.c

index ef74d653cad4acfff784fa754b784b7ebbb13aa2..8275456d41ae7b78276b87ba3ca1d657839e7835 100644 (file)
@@ -2039,6 +2039,12 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
                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");
@@ -2055,6 +2061,12 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
        }
        prestate = chan->_state;
 
+       /* 
+        * Reset the recorded file descriptor that triggered this read so that we can
+        * easily detect when ast_read() is called without properly using ast_waitfor().
+        */
+       chan->fdno = -1;
+
        /* Read and ignore anything on the alertpipe, but read only
           one sizeof(blah) per frame that we send from it */
        if (chan->alertpipe[0] > -1) {