Commit 875953c3 authored by Jonathan Michalon's avatar Jonathan Michalon

libovccclient/ovccclient-server: be aware of timeout cancellable

Since the two only entry points from API to read/write on the network
socket are 'send_message' and 'receive_type', and we manage the cancellation
by hand there (no undelying IO call here, just signals from loops), if both
are aware of TimeoutCancellable we can transparently switch to a more precise
"TIMED_OUT" error in that case instead of a plain "CANCELLED". API callers
can then easily distinguish between IOErrors.
parent c882668d
......@@ -258,7 +258,15 @@ namespace OVCCClient
yield;
if (cancellable != null) {
cancellable.set_error_if_cancelled ();
if (cancellable is TimeoutCancellable) {
var c = (TimeoutCancellable) cancellable;
if (c.timed_out) {
/* switch to a more precise error */
throw new GLib.IOError.TIMED_OUT ("Cancelled by a timeout of %us", c.timeout);
}
} else {
cancellable.set_error_if_cancelled ();
}
}
return msg;
}
......@@ -306,11 +314,19 @@ namespace OVCCClient
if (err != null) {
throw err;
} else if (cancellable != null) {
cancellable.set_error_if_cancelled ();
if (cancellable.is_cancelled()) {
/* maybe not sufficient if already popped out */
send_loop_queue.remove(msg);
}
if (cancellable is TimeoutCancellable) {
var c = (TimeoutCancellable) cancellable;
if (c.timed_out) {
/* switch to a more precise error */
throw new GLib.IOError.TIMED_OUT ("Cancelled by a timeout of %us", c.timeout);
}
} else {
cancellable.set_error_if_cancelled ();
}
}
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment