]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
ftmod_isdn: Handle zero length read correctly.
authorStefan Knoblich <stkn@openisdn.net>
Mon, 23 Jul 2012 22:00:01 +0000 (00:00 +0200)
committerStefan Knoblich <stkn@openisdn.net>
Mon, 23 Jul 2012 22:07:41 +0000 (00:07 +0200)
ftmod_misdn currently returns len == 0 if the incoming message,
that triggered the read() call, does not contain any data.
Users of ftdm_channel_read() need to handle this case, or they
may possibly end up in an endless loop.

This patch reworks the ftdm_channel_read() handling in ftmod_isdn
and prevents it from entering an endless loop. The read error counter
is reset on first sucessful read w/ data.

Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
libs/freetdm/src/ftmod/ftmod_isdn/ftmod_isdn.c

index c3bd175328fdd9b1c639d427588bc540ab5f514d..4d6c2dcb792d7a9113401498542be302a4be4395 100644 (file)
@@ -2055,10 +2055,13 @@ static void *ftdm_isdn_run(ftdm_thread_t *me, void *obj)
                        break;
                default:
                        {
-                               errs = 0;
                                if (flags & FTDM_READ) {
                                        len = sizeof(frame);
-                                       if (ftdm_channel_read(isdn_data->dchan, frame, &len) == FTDM_SUCCESS) {
+                                       if (ftdm_channel_read(isdn_data->dchan, frame, &len) != FTDM_SUCCESS) {
+                                               ftdm_log_chan_msg(isdn_data->dchan, FTDM_LOG_ERROR, "Failed to read from D-Channel\n");
+                                               continue;
+                                       }
+                                       if (len > 0) {
 #ifdef HAVE_PCAP
                                                if (isdn_pcap_capture_both(isdn_data)) {
                                                        isdn_pcap_write(isdn_data, frame, len, ISDN_PCAP_INCOMING);
@@ -2066,6 +2069,9 @@ static void *ftdm_isdn_run(ftdm_thread_t *me, void *obj)
 #endif
                                                Q921QueueHDLCFrame(&isdn_data->q921, frame, (int)len);
                                                Q921Rx12(&isdn_data->q921);
+
+                                               /* Successful read, reset error counter */
+                                               errs = 0;
                                        }
                                } else {
                                        ftdm_log(FTDM_LOG_DEBUG, "No Read FLAG!\n");