# HG changeset patch # User samer # Date 1329748295 0 # Node ID 8a71c55816bea5bd1dd80ab7d3269246d3085a95 # Parent 44e4b80bdf97319ca5c2a87dde9e7bf1a3040150 Put server loop timeout in server structure and set to 50ms default. diff -r 44e4b80bdf97 -r 8a71c55816be c/plosc.c --- a/c/plosc.c Wed Feb 01 15:42:55 2012 +0000 +++ b/c/plosc.c Mon Feb 20 14:31:35 2012 +0000 @@ -29,13 +29,14 @@ typedef struct _my_server_thread { lo_server s; pthread_t thread; + int timeout; volatile int active; volatile int done; } *my_server_thread; int my_server_thread_start(my_server_thread st); int my_server_thread_stop(my_server_thread st); -int my_server_thread_run(my_server_thread st, int timeout); +int my_server_thread_run(my_server_thread st); void my_server_thread_free(my_server_thread st); my_server_thread my_server_thread_new(const char *port, lo_err_handler err_h); @@ -694,10 +695,10 @@ // run OSC server in this thread but with an extra message handler // to allow the /plosc/stop message to terminate the loop. -static int run_stoppable_server(my_server_thread s, int timeout) +static int run_stoppable_server(my_server_thread s) { lo_server_add_method(s->s, "/plosc/stop", NULL, stop_handler, (void *)s); - my_server_thread_run(s,timeout); + my_server_thread_run(s); lo_server_del_method(s->s,"/plosc/stop",NULL); return TRUE; } @@ -784,7 +785,7 @@ { my_server_thread s; printf("running OSC server synchronously...\n"); - return get_server(server,&s) && run_stoppable_server(s,10); + return get_server(server,&s) && run_stoppable_server(s); } @@ -795,6 +796,7 @@ { my_server_thread st = malloc(sizeof(struct _my_server_thread)); st->s = lo_server_new(port, err_h); + st->timeout= 100; // will check st->active at 10Hz. st->active = 0; st->done = 0; @@ -854,8 +856,10 @@ return 0; } -int my_server_thread_run(my_server_thread st, int timeout) +int my_server_thread_run(my_server_thread st) { + int timeout=st->timeout; + st->active = 1; st->done = 0; while (st->active) { @@ -874,7 +878,7 @@ printf("OSC server started.\n"); PL_thread_attach_engine(NULL); - my_server_thread_run(st,50); + my_server_thread_run(st); PL_thread_destroy_engine(); printf("OSC server stopped.\n"); pthread_exit(NULL);