[PATCH] wayland-client: Treat EOF when reading the wayland socket as an error

Kristian Høgsberg hoegsberg at gmail.com
Tue Jul 9 14:40:35 PDT 2013


On Tue, Jul 09, 2013 at 02:10:45PM +0100, Neil Roberts wrote:
> If EOF is encountered while reading from the Wayland socket,
> wl_display_read_events() will now return -1 so that it will be treated
> as an error. The documentation for this function states that it will
> set errno when there is an error so it additionally makes up an errno
> of EPIPE.

Ah, yes, good catch.  The multi-thread behaviour of
wl_display_read_events() allows mulitple threads to call into it, but
only one of the threads will get to read the data from the socket.
When I wrote this I was thinking that all other threads will call
recvmsg non-blocking and return 0 bytes.  But 0 means "orderly
shutdown" of course, while -1 and errno = EAGAIN is "no data right
now".  We do handle that case, but return -1, which the higher-level
code will treat as an error.  I'll fix that in a follow-up commit.

> If we don't do this then when the compositor quits the Wayland socket
> will be become ready for reading but wl_display_dispatch will do
> nothing which typically makes the application take up 100% CPU. In
> particular eglSwapBuffers will likely get stuck in an infinite busy
> loop because it repeatedly calls wl_display_dispatch_queue while it
> waits for the frame callback.

Yes... I wonder why gtk+ doesn't handle POLLHUP and quits from that
though.

> ---
>  src/wayland-client.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index cb091ab..9400bcd 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -877,6 +877,15 @@ read_events(struct wl_display *display)
>  				display_fatal_error(display, errno);
>  			return -1;
>  		}
> +		else if (total == 0) {
> +			/* The compositor has closed the socket. This
> +			 * should be considered an error so we'll fake
> +			 * an errno */
> +			errno = EPIPE;

Yeah, EPIPE is fine I suppose.

thanks,
Kristian

> +			display_fatal_error(display, errno);
> +			return -1;
> +		}
> +
>  		for (rem = total; rem >= 8; rem -= size) {
>  			size = queue_event(display, rem);
>  			if (size == -1) {
> -- 
> 1.7.11.3.g3c3efa5
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list