From: Daniel Elstner Date: Sun, 1 Nov 2015 18:38:40 +0000 (+0100) Subject: openbench-logic-sniffer: Avoid recreating event source X-Git-Tag: libsigrok-0.4.0~135 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8105e82913aface2a430c51ef3e9a45cfce68170;p=libsigrok.git openbench-logic-sniffer: Avoid recreating event source With the current driver API and the corresponding session event handling, it is not possible to destroy and then re-create an event source with the same key within the same main loop iteration. The next generation driver API will fix this problem. But for now, just change the driver to make do without that sort of thing. Also increase the I/O timeout to 100 ms to be safer in the event of all kind of delays the OS environment may induce. This fixes bug #678. --- diff --git a/src/hardware/openbench-logic-sniffer/api.c b/src/hardware/openbench-logic-sniffer/api.c index fe442ac6..ddd33e14 100644 --- a/src/hardware/openbench-logic-sniffer/api.c +++ b/src/hardware/openbench-logic-sniffer/api.c @@ -573,7 +573,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); - serial_source_add(sdi->session, serial, G_IO_IN, -1, + /* If the device stops sending for longer than it takes to send a byte, + * that means it's finished. But wait at least 100 ms to be safe. + */ + serial_source_add(sdi->session, serial, G_IO_IN, 100, ols_receive_data, cb_data); return SR_OK; diff --git a/src/hardware/openbench-logic-sniffer/protocol.c b/src/hardware/openbench-logic-sniffer/protocol.c index eb848cf9..6fb6b44f 100644 --- a/src/hardware/openbench-logic-sniffer/protocol.c +++ b/src/hardware/openbench-logic-sniffer/protocol.c @@ -344,16 +344,12 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data) serial = sdi->conn; devc = sdi->priv; + if (devc->num_transfers == 0 && revents == 0) { + /* Ignore timeouts as long as we haven't received anything */ + return TRUE; + } + if (devc->num_transfers++ == 0) { - /* - * First time round, means the device started sending data, - * and will not stop until done. If it stops sending for - * longer than it takes to send a byte, that means it's - * finished. We'll double that to 30ms to be sure... - */ - serial_source_remove(sdi->session, serial); - serial_source_add(sdi->session, serial, G_IO_IN, 30, - ols_receive_data, cb_data); devc->raw_sample_buf = g_try_malloc(devc->limit_samples * 4); if (!devc->raw_sample_buf) { sr_err("Sample buffer malloc failed.");