thermferm/websocket.c

changeset 730
6eba006ed8f5
parent 724
01e3936f62d4
equal deleted inserted replaced
729:f5d94730db18 730:6eba006ed8f5
307 syslog(LOG_NOTICE, "Websocket: new client, now %d", ws_clients); 307 syslog(LOG_NOTICE, "Websocket: new client, now %d", ws_clients);
308 break; 308 break;
309 } 309 }
310 310
311 case LWS_CALLBACK_PROTOCOL_DESTROY: 311 case LWS_CALLBACK_PROTOCOL_DESTROY:
312 syslog(LOG_NOTICE, "Websocket: protocol cleaning up");
313 for (n = 0; n < sizeof ringbuffer / sizeof ringbuffer[0]; n++) 312 for (n = 0; n < sizeof ringbuffer / sizeof ringbuffer[0]; n++)
314 if (ringbuffer[n].payload) 313 if (ringbuffer[n].payload)
315 free(ringbuffer[n].payload); 314 free(ringbuffer[n].payload);
316 break; 315 break;
317 316
439 ws_broadcast(buf); 438 ws_broadcast(buf);
440 } 439 }
441 } 440 }
442 441
443 442
443 /*
444 * Fast way to stop the websocket service.
445 */
446 void my_ws_stop(void)
447 {
448 my_ws_shutdown = 1;
449 lws_cancel_service(context);
450 }
451
444 452
445 void *my_ws_loop(void *threadid) 453 void *my_ws_loop(void *threadid)
446 { 454 {
447 struct lws_context_creation_info info; 455 struct lws_context_creation_info info;
448 int n = 0; 456 int n = 0;
462 if (context == NULL) { 470 if (context == NULL) {
463 syslog(LOG_NOTICE, "libwebsocket_create_context() failed"); 471 syslog(LOG_NOTICE, "libwebsocket_create_context() failed");
464 my_ws_state = 0; 472 my_ws_state = 0;
465 return (void *)1; 473 return (void *)1;
466 } 474 }
467 syslog(LOG_NOTICE, "Websocket: server started port %d, pid=%d", info.port, pid); 475 syslog(LOG_NOTICE, "Thread my_ws_loop started port %d, pid=%d", info.port, pid);
468 476
469 /* 477 /*
470 * Loop forever until external shutdown variable is set. 478 * Loop forever until external shutdown variable is set.
471 */ 479 */
472 while (n >= 0 && ! my_ws_shutdown) { 480 while (n >= 0 && ! my_ws_shutdown) {
474 n = lws_service(context, 50); 482 n = lws_service(context, 50);
475 } 483 }
476 lws_context_destroy(context); 484 lws_context_destroy(context);
477 485
478 my_ws_state = 0; 486 my_ws_state = 0;
479 syslog(LOG_NOTICE, "Websocket: server stopped"); 487 syslog(LOG_NOTICE, "Thread my_ws_loop stopped");
480 return (void *)0; 488 return (void *)0;
481 } 489 }
482 490
483 491

mercurial