From 6f5438eded37051094ba4d24cc100306b0488bb3 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 30 Nov 2012 19:32:19 -0500 Subject: [PATCH] freetdm: ftmod_zt: Handle driver events while reading media ftmod_analog_em: Initialize read data len to avoid crashing when the freetdm read function does not read anything --- .../src/ftmod/ftmod_analog_em/ftmod_analog_em.c | 6 ++++++ libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c index f7f0683673..8d2f1bb38f 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c +++ b/libs/freetdm/src/ftmod/ftmod_analog_em/ftmod_analog_em.c @@ -488,11 +488,17 @@ static void *ftdm_analog_em_channel_run(ftdm_thread_t *me, void *obj) continue; } + len = 0; if (ftdm_channel_read(ftdmchan, frame, &len) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "READ ERROR [%s]\n", ftdmchan->last_error); goto done; } + if (0 == len) { + ftdm_log(FTDM_LOG_DEBUG, "Nothing read\n"); + continue; + } + if (ftdmchan->detected_tones[0]) { int i; diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index c088c1453f..dc95c9ac08 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -1309,8 +1309,20 @@ static FIO_READ_FUNCTION(zt_read) else { if (errno == EAGAIN || errno == EINTR) continue; - if (errno == ELAST) - break; + if (errno == ELAST) { + zt_event_t zt_event_id = 0; + if (ioctl(ftdmchan->sockfd, codes.GETEVENT, &zt_event_id) == -1) { + ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Failed retrieving event after ELAST on read: %s\n", strerror(errno)); + r = -1; + break; + } + + if (handle_dtmf_event(ftdmchan, zt_event_id)) { + /* we should enqueue this event somewhere so it can be retrieved by the user, for now, dropping it to see what it is! */ + ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Dropping event %d to be able to read data\n", zt_event_id); + } + continue; + } ftdm_log(FTDM_LOG_ERROR, "read failed: %s\n", strerror(errno)); }