Improve mainloop 85/230785/5
authorMinje Ahn <minje.ahn@samsung.com>
Tue, 14 Apr 2020 06:59:18 +0000 (15:59 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 16 Apr 2020 05:40:09 +0000 (14:40 +0900)
Change-Id: I061dcf98e221d00c4593471945f32dfeaf476736
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
server/thumb-server-internal.c
server/thumb-server.c

index 294dc80e8b5a14f2ea0d8385b4c1892a8aa65cec..bb6e7ef6c2e76a67a35d0a704e782f8911521a84 100755 (executable)
@@ -242,7 +242,7 @@ ERROR:
        return G_SOURCE_REMOVE;
 }
 
-gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
+gboolean _thumb_server_read_socket(GIOChannel *channel, GIOCondition condition, gpointer data)
 {
        struct sockaddr_un client_addr;
        unsigned int client_addr_len;
@@ -263,7 +263,7 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
        memset((void *)&res_msg, 0, sizeof(res_msg));
        memset((void *)&credentials, 0, sizeof(credentials));
 
-       sock = g_io_channel_unix_get_fd(src);
+       sock = g_io_channel_unix_get_fd(channel);
        thumb_retvm_if(sock < 0, G_SOURCE_CONTINUE, "sock fd is invalid!");
 
        client_addr_len = sizeof(client_addr);
@@ -287,7 +287,9 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
        } else {
                thumb_warn("Shutting down...");
                g_main_loop_quit(thumb_server);
-               goto ERROR;
+               close(client_sock);
+
+               return G_SOURCE_REMOVE;
        }
 
        SAFE_FREE(credentials.smack);
index 3541d44c10b7db39e90c63b5078775cf01f12f72..750f7825e8955181253236cab057f4dc08058608 100755 (executable)
@@ -37,9 +37,7 @@ static GMainLoop *g_thumb_server_mainloop;
 int main(void)
 {
        int sockfd = -1;
-       GSource *source = NULL;
        GIOChannel *channel = NULL;
-       GMainContext *context = NULL;
 
        if (ms_cynara_initialize() != MS_MEDIA_ERR_NONE) {
                thumb_err("Cynara initialization failed");
@@ -52,32 +50,20 @@ int main(void)
                return -1;
        }
 
-       g_thumb_server_mainloop = g_main_loop_new(context, FALSE);
-       context = g_main_loop_get_context(g_thumb_server_mainloop);
+       g_thumb_server_mainloop = g_main_loop_new(NULL, FALSE);
 
        /* Create new channel to watch tcp socket */
        channel = g_io_channel_unix_new(sockfd);
-       source = g_io_create_watch(channel, G_IO_IN);
-
-       /* Set callback to be called when socket is readable */
-       g_source_set_callback(source, (GSourceFunc)_thumb_server_read_socket, (gpointer)g_thumb_server_mainloop, NULL);
-       g_source_attach(source, context);
+       g_io_add_watch(channel, G_IO_IN, _thumb_server_read_socket, g_thumb_server_mainloop);
+       g_io_channel_unref(channel);
 
-       GSource *source_evas_init = NULL;
-       source_evas_init = g_idle_source_new();
-       g_source_set_callback(source_evas_init, _thumb_daemon_start_jobs, NULL, NULL);
-       g_source_attach(source_evas_init, context);
+       g_idle_add(_thumb_daemon_start_jobs, NULL);
 
        thumb_info("Thumbnail server is running");
        g_main_loop_run(g_thumb_server_mainloop);
 
        thumb_info("Thumbnail server is shutting down");
-       g_io_channel_shutdown(channel,  FALSE, NULL);
-       g_io_channel_unref(channel);
-       /*close socket*/
        close(sockfd);
-
-       g_main_loop_quit(g_thumb_server_mainloop);
        g_main_loop_unref(g_thumb_server_mainloop);
        ms_cynara_finish();