client: read_events should return -1 after an error

Submitted by Marek Chalupa on Oct. 27, 2014, 8:19 a.m.

Details

Message ID 1414397986-18257-1-git-send-email-mchqwerty@gmail.com
State Accepted
Commit 59f255d66e4dad89f633deec535482faa8bd8561
Headers show

Not browsing as part of any series.

Commit Message

Marek Chalupa Oct. 27, 2014, 8:19 a.m.
When a thread is sleeping, waiting until another thread read
from the display, it always returns 0. Even when an error
occured. In documentation stands:

  "return 0 on success or -1 on error.  In case of error errno will
   be set accordingly"

So this is a fix for this.

Along with the read_events, fix a test so that it now complies
with this behaviour (and we have this tested)

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
---
 src/wayland-client.c | 5 +++++
 tests/display-test.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/wayland-client.c b/src/wayland-client.c
index b0f77b9..1a70dc7 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -1187,6 +1187,11 @@  read_events(struct wl_display *display)
 		while (display->read_serial == serial)
 			pthread_cond_wait(&display->reader_cond,
 					  &display->mutex);
+
+		if (display->last_error) {
+			errno = display->last_error;
+			return -1;
+		}
 	}
 
 	return 0;
diff --git a/tests/display-test.c b/tests/display-test.c
index eb4ba1c..6ce9fe5 100644
--- a/tests/display-test.c
+++ b/tests/display-test.c
@@ -384,9 +384,9 @@  thread_read_error(void *data)
 	 * thread should be woken up or it will block indefinitely.
 	 */
 	c->display_stopped = 1;
-	assert(wl_display_read_events(c->wl_display) == 0);
+	assert(wl_display_read_events(c->wl_display) == -1);
 
-	wl_display_dispatch_pending(c->wl_display);
+	assert(wl_display_dispatch_pending(c->wl_display) == -1);
 	assert(wl_display_get_error(c->wl_display));
 
 	pthread_exit(NULL);

Comments

On Mon, 27 Oct 2014 09:19:46 +0100
Marek Chalupa <mchqwerty@gmail.com> wrote:

> When a thread is sleeping, waiting until another thread read
> from the display, it always returns 0. Even when an error
> occured. In documentation stands:
> 
>   "return 0 on success or -1 on error.  In case of error errno will
>    be set accordingly"
> 
> So this is a fix for this.
> 
> Along with the read_events, fix a test so that it now complies
> with this behaviour (and we have this tested)
> 
> Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
> ---
>  src/wayland-client.c | 5 +++++
>  tests/display-test.c | 4 ++--
>  2 files changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index b0f77b9..1a70dc7 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -1187,6 +1187,11 @@ read_events(struct wl_display *display)
>  		while (display->read_serial == serial)
>  			pthread_cond_wait(&display->reader_cond,
>  					  &display->mutex);
> +
> +		if (display->last_error) {
> +			errno = display->last_error;
> +			return -1;
> +		}
>  	}
>  
>  	return 0;
> diff --git a/tests/display-test.c b/tests/display-test.c
> index eb4ba1c..6ce9fe5 100644
> --- a/tests/display-test.c
> +++ b/tests/display-test.c
> @@ -384,9 +384,9 @@ thread_read_error(void *data)
>  	 * thread should be woken up or it will block indefinitely.
>  	 */
>  	c->display_stopped = 1;
> -	assert(wl_display_read_events(c->wl_display) == 0);
> +	assert(wl_display_read_events(c->wl_display) == -1);
>  
> -	wl_display_dispatch_pending(c->wl_display);
> +	assert(wl_display_dispatch_pending(c->wl_display) == -1);
>  	assert(wl_display_get_error(c->wl_display));
>  
>  	pthread_exit(NULL);

Looks correct to me. Pushed.


Thanks,
pq