From 95ac0ecc2f3ec73812867c655aa5b5e5594cffe4 Mon Sep 17 00:00:00 2001 From: Stefan Knoblich Date: Mon, 7 Jan 2013 13:24:01 +0100 Subject: [PATCH] ftmod_misdn: Retry recvfrom() in case of EAGAIN epoll_wait() on the B-channel socket may indicate pending messages, but recvfrom() returns EAGAIN. Retry a few more times (up to 5 retries) to get the pending message. Signed-off-by: Stefan Knoblich --- libs/freetdm/src/ftmod/ftmod_misdn/ftmod_misdn.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_misdn/ftmod_misdn.c b/libs/freetdm/src/ftmod/ftmod_misdn/ftmod_misdn.c index 48b70a319c..82a35ad7e6 100644 --- a/libs/freetdm/src/ftmod/ftmod_misdn/ftmod_misdn.c +++ b/libs/freetdm/src/ftmod/ftmod_misdn/ftmod_misdn.c @@ -2269,14 +2269,23 @@ static ftdm_status_t handle_b_channel_event(ftdm_channel_t *chan) struct misdn_chan_private *priv = ftdm_chan_io_private(chan); char buf[MAX_DATA_MEM] = { 0 }; struct mISDNhead *mh = (void *)buf; - int retval; + int retval, retries = 5; - if ((retval = recvfrom(chan->sockfd, buf, sizeof(buf), 0, NULL, NULL)) <= 0) { + do { + /* + * Retry reading multiple times if recvfrom() returns EAGAIN + */ + retval = recvfrom(chan->sockfd, buf, sizeof(buf), 0, NULL, NULL); + if (retval < 0 && errno != EAGAIN) + break; + + } while (retval < 0 && retries-- > 0); + + if (retval < 0) { ftdm_log_chan(chan, FTDM_LOG_ERROR, "mISDN failed to receive message: %s\n", strerror(errno)); return FTDM_FAIL; } - if (retval < MISDN_HEADER_LEN) { ftdm_log_chan(chan, FTDM_LOG_ERROR, "mISDN message too short, min.: %d, read: %d\n", (int)MISDN_HEADER_LEN, retval);