From 6914b1c855d53a52e8a730d5217a181866496093 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 25 Jun 2010 12:11:23 -0400 Subject: [PATCH] freetdm: improve channel read error logging --- libs/freetdm/src/ftdm_io.c | 8 ++++++++ libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index dca616e74b..d813fa5a48 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -2911,16 +2911,22 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OPEN)) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "channel not open"); + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "cannot read from channel that is not open\n"); return FTDM_FAIL; } if (!ftdmchan->fio->read) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "method not implemented"); + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "read method not implemented\n"); return FTDM_FAIL; } status = ftdm_raw_read(ftdmchan, data, datalen); + if (status != FTDM_SUCCESS) { + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "raw I/O read filed\n"); + } + if (status == FTDM_SUCCESS) { if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_USE_RX_GAIN) && (ftdmchan->native_codec == FTDM_CODEC_ALAW || ftdmchan->native_codec == FTDM_CODEC_ULAW)) { @@ -2947,6 +2953,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data status = codec_func(data, max, datalen); } else { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!"); + ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "no codec function to perform transcoding from %d to %d\n", ftdmchan->native_codec, ftdmchan->effective_codec); status = FTDM_FAIL; } } @@ -2979,6 +2986,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read(ftdm_channel_t *ftdmchan, void *data *sln++ = alaw_to_linear(*lp++); } else { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "codec error!"); + ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "invalid effective codec %d\n", ftdmchan->effective_codec); return FTDM_FAIL; } } diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 914e53e730..9a8cab4112 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -731,19 +731,23 @@ static FIO_COMMAND_FUNCTION(wanpipe_command) static FIO_READ_FUNCTION(wanpipe_read) { int rx_len = 0; + int myerrno = 0; wp_tdm_api_rx_hdr_t hdrframe; memset(&hdrframe, 0, sizeof(hdrframe)); - rx_len = sangoma_readmsg_tdm(ftdmchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen,0); + rx_len = sangoma_readmsg_tdm(ftdmchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen, 0); *datalen = rx_len; - if (rx_len == 0 || rx_len == -17) { + if (rx_len == 0) { + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Read 0 bytes\n"); return FTDM_TIMEOUT; } if (rx_len < 0) { + myerrno = errno; snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "%s", strerror(errno)); + ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Failed to read from sangoma device: %s (%d)\n", strerror(errno), rx_len); return FTDM_FAIL; }