clients: Check return value of wl_display_dispatch()
authorKristian Høgsberg <krh@bitplanet.net>
Tue, 16 Oct 2012 17:16:10 +0000 (13:16 -0400)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 16 Oct 2012 17:17:16 +0000 (13:17 -0400)
The simple clients all just call wl_display_dispatch() in a while loop
without checking the return value.  Now, if the server dies or other
error occurs, we get a -1 return value instead and need to break the loop.

clients/simple-egl.c
clients/simple-shm.c
clients/simple-touch.c
clients/window.c

index af5c700..8823362 100644 (file)
@@ -591,7 +591,7 @@ main(int argc, char **argv)
        struct sigaction sigint;
        struct display display = { 0 };
        struct window  window  = { 0 };
-       int i;
+       int i, ret = 0;
 
        window.display = &display;
        display.window = &window;
@@ -627,8 +627,8 @@ main(int argc, char **argv)
        sigint.sa_flags = SA_RESETHAND;
        sigaction(SIGINT, &sigint, NULL);
 
-       while (running)
-               wl_display_dispatch(display.display);
+       while (running && ret != -1)
+               ret = wl_display_dispatch(display.display);
 
        fprintf(stderr, "simple-egl exiting\n");
 
index 92286fb..d03bed6 100644 (file)
@@ -328,6 +328,7 @@ main(int argc, char **argv)
        struct sigaction sigint;
        struct display *display;
        struct window *window;
+       int ret;
 
        display = create_display();
        window = create_window(display, 250, 250);
@@ -344,8 +345,8 @@ main(int argc, char **argv)
 
        redraw(window, NULL, 0);
 
-       while (running)
-               wl_display_dispatch(display->display);
+       while (running && ret != -1)
+               ret = wl_display_dispatch(display->display);
 
        fprintf(stderr, "simple-shm exiting\n");
        destroy_window(window);
index dafb58b..0eeb8f9 100644 (file)
@@ -316,11 +316,12 @@ int
 main(int argc, char **argv)
 {
        struct touch *touch;
+       int ret = 0;
 
        touch = touch_create(600, 500);
 
-       while (true)
-               wl_display_dispatch(touch->display);
+       while (ret != -1)
+               ret = wl_display_dispatch(touch->display);
 
        return 0;
 }
index 3f6a7c7..1d6600c 100644 (file)
@@ -3837,8 +3837,13 @@ handle_display_data(struct task *task, uint32_t events)
                return;
        }
 
-       if (events & EPOLLIN)
-               wl_display_dispatch(display->display);
+       if (events & EPOLLIN) {
+               ret = wl_display_dispatch(display->display);
+               if (ret == -1) {
+                       display_exit(display);
+                       return;
+               }
+       }
 
        if (events & EPOLLOUT) {
                ret = wl_display_flush(display->display);