netutils/webclient: check webclient example running status
authorJunyeon LEE <junyeon2.lee@samsung.com>
Mon, 29 May 2017 21:17:57 +0000 (06:17 +0900)
committerEunBong Song <eunb.song@samsung.com>
Tue, 11 Jul 2017 01:26:56 +0000 (10:26 +0900)
This commit addes global value for checking webclieng running status.
If webclient example runs twice at a time, global values like g_https
and g_async can be destroyed by latter webclient app.

Change-Id: I49644810de070c09d10e5d2c4bad402d35e5e505
Signed-off-by: Junyeon LEE <junyeon2.lee@samsung.com>
apps/examples/webclient/webclient_main.c

index d4773bd..d47a58c 100644 (file)
@@ -131,6 +131,7 @@ struct http_client_ssl_config_t g_config = {
        sizeof(c_ca_crt_rsa), sizeof(c_cli_crt_rsa), sizeof(c_cli_key_rsa), 2
 };
 
+static int g_running;
 static int g_https;
 static int g_async;
 static int g_testentity;
@@ -343,9 +344,17 @@ int webclient_main(int argc, char *argv[])
        pthread_t tid;
        struct webclient_input arg;
 
+       if (g_running) {
+               printf("Previous request is in process, Please wait.\n");
+               return -1;
+       } else {
+               g_running = 1;
+       }
+
        status = pthread_attr_init(&attr);
        if (status != 0) {
                printf("fail to start webclient\n");
+               g_running = 0;
                return -1;
        }
 
@@ -360,11 +369,13 @@ int webclient_main(int argc, char *argv[])
        status = pthread_create(&tid, &attr, webclient_cb, &arg);
        if (status < 0) {
                printf("fail to start webclient\n");
+               g_running = 0;
                return -1;
        }
        pthread_setname_np(tid, "webclient");
 
        pthread_join(tid, NULL);
 
+       g_running = 0;
        return 0;
 }