Remove the infinite timeout
When an Uwatec Aladin is connected, but the transfer hasn't been started yet, we receive a continuous stream of zero bytes. Approximately every 7-8ms a new zero byte is received. But when the dive computer is (temporary) disconnected, the stream of zero bytes also ends. The consequence is that due to the use of blocking read call with an infinite timeout, the application becomes unresponsive, without any chance to abort the communication. This can eaily be avoided by using a timeout instead. Receiving the main 2048 byte packet takes about 1050ms. Thus a 3000ms timeout should be long enough to not cause the main data transfer to timeout, but still short enough to cancel reasonable fast.
This commit is contained in:
parent
ecc23a5a76
commit
f42df2d846
@ -96,8 +96,8 @@ uwatec_aladin_device_open (dc_device_t **out, dc_context_t *context, dc_iostream
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
// Set the timeout for receiving data (INFINITE).
|
||||
status = dc_iostream_set_timeout (device->iostream, -1);
|
||||
// Set the timeout for receiving data (3000ms).
|
||||
status = dc_iostream_set_timeout (device->iostream, 3000);
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
ERROR (context, "Failed to set the timeout.");
|
||||
goto error_free;
|
||||
@ -172,11 +172,12 @@ uwatec_aladin_device_dump (dc_device_t *abstract, dc_buffer_t *buffer)
|
||||
status = dc_iostream_read (device->iostream, answer + i, 1, NULL);
|
||||
if (status != DC_STATUS_SUCCESS) {
|
||||
ERROR (abstract->context, "Failed to receive the answer.");
|
||||
return status;
|
||||
if (status != DC_STATUS_TIMEOUT)
|
||||
return status;
|
||||
}
|
||||
|
||||
const unsigned char expected = i < 3 ? 0x55 : 0x00;
|
||||
if (answer[i] != expected) {
|
||||
if (status != DC_STATUS_SUCCESS || answer[i] != expected) {
|
||||
device_event_emit (abstract, DC_EVENT_WAITING, NULL);
|
||||
i = 0;
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user