chan_lcr: this fixes hanging with app_rxfax and a race condition
authorPeter Schlaile <root@asterisk.schlaile.de>
Fri, 22 Aug 2008 18:08:43 +0000 (20:08 +0200)
committerroot <root@asterisk.schlaile.de>
Fri, 22 Aug 2008 18:08:43 +0000 (20:08 +0200)
in lcr_read

(lcr_read was hanging in locked-state forever, when no data was
available, making any further calls impossible.
Now we return a null-packet to asterisk)

Sidenode: you have to use lcr_config(r) to receive faxes correctly.
(app_rxfax seems to rely on 160-byte buffers)

chan_lcr.c

index e09004c..de9d788 100644 (file)
@@ -295,6 +295,7 @@ struct chan_call *alloc_call(void)
                free_call(*callp);
                return(NULL);
        }
                free_call(*callp);
                return(NULL);
        }
+       fcntl((*callp)->pipe[0], F_SETFL, O_NONBLOCK);
        CDEBUG(*callp, NULL, "Call instance allocated.\n");
        return(*callp);
 }
        CDEBUG(*callp, NULL, "Call instance allocated.\n");
        return(*callp);
 }
@@ -1964,9 +1965,14 @@ static struct ast_frame *lcr_read(struct ast_channel *ast)
                } else {
                        len = read(call->pipe[0], call->read_buff, sizeof(call->read_buff));
                }
                } else {
                        len = read(call->pipe[0], call->read_buff, sizeof(call->read_buff));
                }
+               if (len < 0 && errno == EAGAIN) {
+                       ast_mutex_unlock(&chan_lock);
+                       return &ast_null_frame;
+               }
                if (len <= 0) {
                        close(call->pipe[0]);
                        call->pipe[0] = -1;
                if (len <= 0) {
                        close(call->pipe[0]);
                        call->pipe[0] = -1;
+                       ast_mutex_unlock(&chan_lock);
                        return NULL;
                }
        }
                        return NULL;
                }
        }