[PATCH] fix DownloadWidget behavior
Jef Driesen
jefdriesen at telenet.be
Sat Aug 24 14:24:32 UTC 2013
On 24-08-13 16:42, Danilo Cesar wrote:
> I would ask that someone make a test for me before applying this patch, please.
>
> Right now I'm facing a problem with libdivingcomputer where I set
> import_thread_cancelled=true but libdivecomputer doesn't stop the
> download.
>
> Since I'm having exactly the same problem on the Gtk version, I
> believe the problem might be a bug in libdivingcomputer AND my diving
> computer (mares matrix).
The fact that libdivecomputer doesn't cancel the current operation immediately
(or even at all) is by design.
The underlying reason is that not all communication protocols can technically
support this feature. Take for example a protocol where you send a single
request and get all data back at once. Once that request has been send, there
isn't anything you can do to stop the dive computer from transmitting data.
Since aborting abruptly might cause trouble, libdivecomputer will ignore the
cancellation request and continue.
The protocols that do support cancellation are typically the ones where you have
to send multiple requests, and in that case, libdivecomputer can safely cancel
between two requests. But even then a cancellation request won't be handled
immediately, because libdivecomputer has to wait until the current packet has
been finished. (Technically, because libdivecomputer does blocking I/O it won't
even notice your cancellation request, except at those points where it
explicitly checks for it with the device_is_cancelled function.)
Thus cancellation is always a best effort, without any guarantees ("cooperative
cancellation"). A cancellation request may be handled almost instantly, with a
small delay, or not at all.
Now after having explained the technical details, there might be some
libdivecomputer backends that can support cancellation but still lack the
necessary code to enable it. I quickly checked and that's indeed the case for
the Mares Matrix. It's an easy fix, but it will have to wait until I'm back from
my diving trip :-)
Jef
More information about the subsurface
mailing list