client: read_events should return -1 after an error

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>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
Marek Chalupa 2014-10-27 09:19:46 +01:00 committed by Pekka Paalanen
parent 059220549c
commit 59f255d66e
2 changed files with 7 additions and 2 deletions

View File

@ -1190,6 +1190,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;

View File

@ -369,9 +369,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);