netutils/webserver: fix closing function
authorJunyeon LEE <junyeon2.lee@samsung.com>
Tue, 11 Apr 2017 01:52:29 +0000 (10:52 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Tue, 18 Apr 2017 03:02:16 +0000 (12:02 +0900)
This commit fixes the way of closing webserver thread.
Sometimes webserver can't kill the child pthread properly
and it causes some problem.

Change-Id: I2a2b1d95970f1e84fdcd4a51b9fa5ab25f7b70fd
Signed-off-by: Junyeon LEE <junyeon2.lee@samsung.com>
apps/netutils/webserver/http.c

index baf987e..6a60516 100644 (file)
@@ -207,6 +207,8 @@ stop :
        HTTP_LOGD("http_server_hander stop :%d\n", server->port);
 
        if (msg_q >= 0) {
+
+               int n_client = HTTP_CONF_MAX_CLIENT_HANDLE;
                http_server_mq_flush(msg_q);
 
                for (i = 0; i < HTTP_CONF_MAX_CLIENT_HANDLE; i++) {
@@ -215,9 +217,17 @@ stop :
                        mq_send(msg_q, (char *)&msg, mqattr.mq_msgsize, 1);
                }
 
-               for (i = 0; i < HTTP_CONF_MAX_CLIENT_HANDLE;  i++) {
-                       pthread_kill(server->c_tid[i], HTTP_CONF_SERVER_SIGWAKEUP);
-                       usleep(100);
+               mq_getattr(msg_q, &mqattr);
+
+               while ((mqattr.mq_curmsgs != 0) && (n_client > 0)) {
+                       usleep(100000);
+                       mq_getattr(msg_q, &mqattr);
+                       n_client = HTTP_CONF_MAX_CLIENT_HANDLE;
+                       for (i = 0; i < HTTP_CONF_MAX_CLIENT_HANDLE;  i++) {
+                               if (pthread_kill(server->c_tid[i], HTTP_CONF_SERVER_SIGWAKEUP) != OK) {
+                                       n_client--;
+                               }
+                       }
                }
 
                mq_close(msg_q);