make test client notice if server closed on him
authorAndy Green <andy@warmcat.com>
Mon, 14 Feb 2011 20:25:43 +0000 (20:25 +0000)
committerAndy Green <andy@warmcat.com>
Mon, 14 Feb 2011 20:25:43 +0000 (20:25 +0000)
Signed-off-by: Andy Green <andy@warmcat.com>
test-server/test-client.c

index 52ce477..e887971 100644 (file)
@@ -29,6 +29,7 @@
 #include <poll.h>
 
 static unsigned int opts;
+static int was_closed;
 
 /*
  * This demo shows how to connect multiple websockets simultaneously to a
@@ -91,6 +92,11 @@ callback_lws_mirror(struct libwebsocket_context * this,
 
        switch (reason) {
 
+       case LWS_CALLBACK_CLOSED:
+               fprintf(stderr, "LWS_CALLBACK_CLOSED\n");
+               was_closed = 1;
+               break;
+
        case LWS_CALLBACK_CLIENT_ESTABLISHED:
 
                /*
@@ -256,9 +262,11 @@ int main(int argc, char **argv)
         */
 
        n = 0;
-       while (n >= 0)
+       while (n >= 0 && !was_closed)
                n = libwebsocket_service(context, 1000);
 
+       fprintf(stderr, "Exiting\n");
+
        libwebsocket_context_destroy(context);
 
        return 0;