@@ -14214,9 +14214,7 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat
14214
14214
{
14215
14215
struct iax2_dpcache * dp = NULL ;
14216
14216
struct timeval now = ast_tvnow ();
14217
- int x , com [2 ], timeout , old = 0 , outfd , doabort , callno ;
14218
- struct ast_channel * c = NULL ;
14219
- struct ast_frame * f = NULL ;
14217
+ int x , com [2 ], timeout , doabort , callno ;
14220
14218
14221
14219
AST_LIST_TRAVERSE_SAFE_BEGIN (& dpcache , dp , cache_list ) {
14222
14220
if (ast_tvcmp (now , dp -> expiry ) > 0 ) {
@@ -14263,8 +14261,8 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat
14263
14261
14264
14262
/* By here we must have a dp */
14265
14263
if (dp -> flags & CACHE_FLAG_PENDING ) {
14266
- struct timeval start ;
14267
- int ms ;
14264
+ int res ;
14265
+ struct pollfd pfd ;
14268
14266
/* Okay, here it starts to get nasty. We need a pipe now to wait
14269
14267
for a reply to come back so long as it's pending */
14270
14268
for (x = 0 ; x < ARRAY_LEN (dp -> waiters ); x ++ ) {
@@ -14285,35 +14283,31 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat
14285
14283
timeout = iaxdefaulttimeout * 1000 ;
14286
14284
/* Temporarily unlock */
14287
14285
AST_LIST_UNLOCK (& dpcache );
14288
- /* Defer any dtmf */
14289
- if (chan )
14290
- old = ast_channel_defer_dtmf (chan );
14291
14286
doabort = 0 ;
14292
- start = ast_tvnow ();
14293
- while ((ms = ast_remaining_ms (start , timeout ))) {
14294
- c = ast_waitfor_nandfds (& chan , chan ? 1 : 0 , & com [0 ], 1 , NULL , & outfd , & ms );
14295
- if (outfd > -1 )
14296
- break ;
14297
- if (!c )
14298
- continue ;
14299
- if (!(f = ast_read (c ))) {
14300
- doabort = 1 ;
14301
- break ;
14302
- }
14303
- ast_frfree (f );
14304
- }
14305
- if (!ms ) {
14287
+
14288
+ /* chan is in autoservice here, so do NOT service it here! */
14289
+ pfd .fd = com [0 ];
14290
+ pfd .events = POLLIN ;
14291
+ pfd .revents = 0 ;
14292
+ /* Wait for pipe activity... if the channel hangs up, we'll catch it on the way out. */
14293
+ res = ast_poll (& pfd , 1 , timeout );
14294
+ if (res < 0 ) {
14295
+ ast_log (LOG_WARNING , "poll returned < 0: %s\n" , strerror (errno ));
14296
+ return NULL ;
14297
+ } else if (!pfd .revents ) {
14306
14298
ast_log (LOG_WARNING , "Timeout waiting for %s exten %s\n" , data , exten );
14307
14299
}
14300
+
14301
+ if (ast_check_hangup (chan )) {
14302
+ doabort = 1 ;
14303
+ }
14304
+
14308
14305
AST_LIST_LOCK (& dpcache );
14309
14306
dp -> waiters [x ] = -1 ;
14310
14307
close (com [1 ]);
14311
14308
close (com [0 ]);
14312
14309
if (doabort ) {
14313
- /* Don't interpret anything, just abort. Not sure what th epoint
14314
- of undeferring dtmf on a hung up channel is but hey whatever */
14315
- if (!old && chan )
14316
- ast_channel_undefer_dtmf (chan );
14310
+ /* Don't interpret anything, just abort. */
14317
14311
return NULL ;
14318
14312
}
14319
14313
if (!(dp -> flags & CACHE_FLAG_TIMEOUT )) {
@@ -14336,8 +14330,6 @@ static struct iax2_dpcache *find_cache(struct ast_channel *chan, const char *dat
14336
14330
}
14337
14331
}
14338
14332
/* Our caller will obtain the rest */
14339
- if (!old && chan )
14340
- ast_channel_undefer_dtmf (chan );
14341
14333
}
14342
14334
return dp ;
14343
14335
}
0 commit comments