From 723a598c24ffd6b70b67e1ee1864a87ba33ed1ce Mon Sep 17 00:00:00 2001 From: Arnaldo Pereira Date: Tue, 21 Dec 2010 16:32:02 -0200 Subject: [PATCH] freetdm: core - lock the channel on ftdm_channel_read_event() ftmod_zt - not locking the channel on zt_channel_next_event(), minor changes --- libs/freetdm/src/ftdm_io.c | 9 +++++++-- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index c04dd85a17..458025e5de 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -1142,14 +1142,17 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read_event(ftdm_channel_t *ftdmchan, ftdm ftdm_span_t *span = ftdmchan->span; ftdm_assert_return(span->fio != NULL, FTDM_FAIL, "No I/O module attached to this span!\n"); + ftdm_channel_lock(ftdmchan); + if (!span->fio->channel_next_event) { ftdm_log(FTDM_LOG_ERROR, "channel_next_event method not implemented in module %s!", span->fio->name); - return FTDM_NOTIMPL; + status = FTDM_NOTIMPL; + goto done; } status = span->fio->channel_next_event(ftdmchan, event); if (status != FTDM_SUCCESS) { - return status; + goto done; } /* before returning the event to the user we do some core operations with certain OOB events */ @@ -1177,6 +1180,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_read_event(ftdm_channel_t *ftdmchan, ftdm break; } +done: + ftdm_channel_unlock(ftdmchan); return status; } diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index 25f9b291ed..7ce3f71cc8 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -1007,7 +1007,8 @@ FIO_CHANNEL_NEXT_EVENT_FUNCTION(zt_channel_next_event) if (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_EVENT)) { ftdm_clear_flag(ftdmchan, FTDM_CHANNEL_EVENT); if (ioctl(ftdmchan->sockfd, codes.GETEVENT, &zt_event_id) == -1) { - snprintf(span->last_error, sizeof(span->last_error), "%s", strerror(errno)); + ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Failed retrieving event from channel: %s\n", + strerror(errno)); return FTDM_FAIL; } @@ -1044,7 +1045,7 @@ FIO_CHANNEL_NEXT_EVENT_FUNCTION(zt_channel_next_event) case ZT_EVENT_RINGOFFHOOK: { if (ftdmchan->type == FTDM_CHAN_TYPE_FXS || (ftdmchan->type == FTDM_CHAN_TYPE_EM && ftdmchan->state != FTDM_CHANNEL_STATE_UP)) { - ftdm_set_flag_locked(ftdmchan, FTDM_CHANNEL_OFFHOOK); + ftdm_set_flag(ftdmchan, FTDM_CHANNEL_OFFHOOK); event_id = FTDM_OOB_OFFHOOK; } else if (ftdmchan->type == FTDM_CHAN_TYPE_FXO) { event_id = FTDM_OOB_RING_START; @@ -1076,7 +1077,7 @@ FIO_CHANNEL_NEXT_EVENT_FUNCTION(zt_channel_next_event) break; default: { - ftdm_log(FTDM_LOG_WARNING, "Unhandled event %d for %d:%d\n", zt_event_id, span->span_id, i); + ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Unhandled event %d for %d:%d\n", zt_event_id, span->span_id, i); event_id = FTDM_OOB_INVALID; } break;