[Spice-devel] [PATCH spice-gtk] controller: async flush read/write

Uri Lublin uril at redhat.com
Tue Jul 3 05:09:48 PDT 2012


On 07/03/2012 04:41 AM, Marc-André Lureau wrote:
> Windows namedpipes behave a bit differently from Unix socket, and may
> return incomplete read/write. By using 2 read/write() helpers, try to
> complete the operation before returning. Since the IO operation may be
> splitted over several call, we make sure the buffer pointer is on the
> heap. We use exception for EOF or BROKEN_PIPE condition, which also
> simplifies the code.
>
> To really work with namedpipe, the giowin32streams need to be fixed as
> well to handle concurrent read&  write properly, see for details:
> https://bugzilla.gnome.org/show_bug.cgi?id=679288
> ---
>   gtk/controller/Makefile.am       |    1 +
>   gtk/controller/controller.vala   |   37 +++++++----------------------
>   gtk/controller/foreign-menu.vala |   48 ++++++++++++++------------------------
>   gtk/controller/util.vala         |   42 +++++++++++++++++++++++++++++++++
>   4 files changed, 69 insertions(+), 59 deletions(-)
>   create mode 100644 gtk/controller/util.vala
> diff --git a/gtk/controller/util.vala b/gtk/controller/util.vala
> +namespace SpiceCtrl {
> +
> +	public async void input_stream_read (InputStream stream, uint8[] buffer) throws GLib.IOError {
> +		var length = buffer.length;
> +		ssize_t i = 0;
> +
> +		while (i<  length) {
> +			var n = yield stream.read_async (buffer[i:length]);
> +			if (n == 0)
> +				throw new GLib.IOError.CLOSED ("closed stream") ;
> +			i += n;
> +		}
> +	}
> +
> +	public async void output_stream_write (OutputStream stream, owned uint8[] buffer) throws GLib.IOError {
> +		var length = buffer.length;
> +		ssize_t i = 0;
> +
> +		while (i<  length) {
> +			var n = yield stream.write_async (buffer[i:length]);

Does stream.write_async throws exceptions on errors ?
If not, then this code needs to handle errors (throw something).


> +			if (n == 0)
> +				throw new GLib.IOError.CLOSED ("closed stream") ;
> +			i += n;
> +		}
> +	}
> +
> +}
> \ No newline at end of file



More information about the Spice-devel mailing list