Update to change the registered event with EPOLL_CTL_MOD 41/181241/5 accepted/tizen/unified/20180614.150824 submit/tizen/20180614.010841
authorYoungHun Kim <yh8004.kim@samsung.com>
Mon, 11 Jun 2018 06:20:23 +0000 (15:20 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Tue, 12 Jun 2018 04:32:14 +0000 (13:32 +0900)
Change-Id: I62a43c62c2fe0e93bbceab2afad119e62a056611

packaging/mused.spec
server/include/muse_server_connection.h
server/src/muse_server_connection.c
server/src/muse_server_private.c
server/src/muse_server_system.c

index 9c83f7178d2350e81b83bf76fcfb695bfb89c17d..259cc62bb0f2c3e14f838aeaf58559e0258cd806 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mused
 Summary:    A multimedia daemon
-Version:    0.3.41
+Version:    0.3.42
 Release:    0
 Group:      System/Libraries
 License:    Apache-2.0
index eda80f7568ad35b4cde2463dba6ca4aff7cb0b83..482f2cd6e69b2a940f573a0e891cf7952fe9b434 100644 (file)
@@ -54,7 +54,7 @@ void ms_connection_init(ms_connection_t *connection);
 void ms_connection_deinit(ms_connection_t *connection);
 int ms_connection_register(muse_module_h m);
 int ms_connection_unregister(muse_module_h m);
-ms_event_e ms_connection_event_trigger(int *value);
+ms_event_e ms_connection_event_handler(int *state_value);
 void ms_connection_lock(ms_connection_t *connection);
 void ms_connection_unlock(ms_connection_t *connection);
 
index 4ab245aeace4b274e5580705d6333aadab59c075..957cf30a63000b2d6d98689e12a9b138cbf8f98c 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "muse_server_private.h"
 
+#define EPOLL_ERR -1
+
 static const char *connection_cmd[API_MAX] = {
        "connect",
        "disconnect"
@@ -89,7 +91,7 @@ int ms_connection_register(muse_module_h m)
        event.events = EPOLLIN;
        event.data.ptr = GINT_TO_POINTER(fd);
 
-       if (epoll_ctl(connection->epfd, EPOLL_CTL_ADD, fd, &event) == MUSE_ERR) {
+       if (epoll_ctl(connection->epfd, EPOLL_CTL_ADD, fd, &event) == EPOLL_ERR) {
                strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
                LOGE("epoll ctl error - %s", err_msg);
        }
@@ -111,7 +113,6 @@ int ms_connection_unregister(muse_module_h m)
 {
        int fd;
        GQueue *queue;
-       char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
        ms_connection_t *connection = ms_get_instance()->connection;
 
        LOGD("Enter");
@@ -126,11 +127,6 @@ int ms_connection_unregister(muse_module_h m)
 
        fd = m->ch[MUSE_CHANNEL_MSG].sock_fd;
 
-       if (epoll_ctl(connection->epfd, EPOLL_CTL_DEL, fd, NULL) == MUSE_ERR) {
-               strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
-               LOGE("epoll ctl error - %s", err_msg);
-       }
-
        g_queue_remove(queue, (gpointer)m);
 
        connection->instance_count[m->idx]--;
@@ -144,15 +140,15 @@ int ms_connection_unregister(muse_module_h m)
        return MM_ERROR_NONE;
 }
 
-ms_event_e ms_connection_event_trigger(int *value)
+ms_event_e ms_connection_event_handler(int *state_value)
 {
-       int idx, fd_count;
+       int idx, fd, fd_count;
        ms_event_e event_value = MUSE_EVENT_UNKNOWN;
        struct epoll_event *p_event;
        char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
        ms_connection_t *connection = ms_get_instance()->connection;
 
-       g_return_val_if_fail(connection, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(connection, MUSE_EVENT_UNKNOWN);
 
        fd_count = epoll_wait(connection->epfd, connection->events, MS_EVENT_MAX, MS_TIMEOUT_MSEC);
 
@@ -168,15 +164,29 @@ ms_event_e ms_connection_event_trigger(int *value)
 
        for (idx = 0; idx < fd_count; idx++) {
                p_event = &connection->events[idx];
+               fd = GPOINTER_TO_INT(p_event->data.ptr);
+               event_value = MUSE_EVENT_UNKNOWN;
+
+               if (p_event->events == EPOLLIN) {
+                       LOGI("CONNECTED [epoll fd : %d] [client fd : %d]", connection->epfd, fd);
+
+                       p_event->events = EPOLLRDHUP;
+                       if (epoll_ctl(connection->epfd, EPOLL_CTL_MOD, fd, p_event) == EPOLL_ERR) {
+                               strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
+                               LOGE("epoll ctl error - %s", err_msg);
+                       }
 
-               if (p_event->events == EPOLLIN || p_event->events == EPOLLOUT) {
-                       if (*value != MUSE_CONNECTION_STATE_CONNECTED)
-                               event_value = MUSE_EVENT_CONNECTION_STATE_CHANGED;
-                       *value = MUSE_CONNECTION_STATE_CONNECTED;
-               } else {
-                       if (*value != MUSE_CONNECTION_STATE_DISCONNECTED)
-                               event_value = MUSE_EVENT_CONNECTION_STATE_CHANGED;
-                       *value = MUSE_CONNECTION_STATE_DISCONNECTED;
+                       event_value = MUSE_EVENT_CONNECTION_STATE_CHANGED;
+               } else if (p_event->events & EPOLLRDHUP) {
+                       LOGI("DISCONNECTED [epoll fd : %d] [client fd : %d]", connection->epfd, fd);
+
+                       if (epoll_ctl(connection->epfd, EPOLL_CTL_DEL, fd, p_event) == EPOLL_ERR) {
+                               strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);
+                               LOGE("epoll ctl error - %s", err_msg);
+                       }
+
+                       *state_value = MUSE_CONNECTION_STATE_DISCONNECTED;
+                       event_value = MUSE_EVENT_CONNECTION_STATE_CHANGED;
                }
        }
 
@@ -199,6 +209,8 @@ void ms_connection_deinit(ms_connection_t *connection)
 {
        g_return_if_fail(connection);
 
+       g_queue_free(connection->instance_queue);
+
        g_mutex_clear(&connection->lock);
 
        close(connection->epfd);
index 2ac80d1ffc7ce896a540cdd0ececba25b56c5f4d..591e353d3b01631fe05fff4f9fbed18716383fcd 100644 (file)
@@ -416,22 +416,17 @@ static void _ms_wait_event(void)
 
 gpointer _ms_diag_thread(gpointer data)
 {
-       ms_event_e event_value;
-       int value = MUSE_ERR;
+       int state_value = MUSE_CONNECTION_STATE_INVALID;
 
        g_return_val_if_fail(muse_server, NULL);
 
        while (1) {
-               event_value = ms_connection_event_trigger(&value);
-
-               if (event_value == MUSE_EVENT_CONNECTION_STATE_CHANGED) {
-                       if (value == MUSE_CONNECTION_STATE_CONNECTED) {
+               if (ms_connection_event_handler(&state_value) == MUSE_EVENT_CONNECTION_STATE_CHANGED) {
+                       if (state_value == MUSE_CONNECTION_STATE_CONNECTED) {
                                /* will be updated about connection at the next patch */
-                       } else if (value == MUSE_CONNECTION_STATE_DISCONNECTED) {
+                       } else if (state_value == MUSE_CONNECTION_STATE_DISCONNECTED) {
                                LOGD("Diagnostic thread checks the memory of idle");
                                ms_check_memory(muse_server->pid);
-                       } else {
-                               LOGW("Need to check the value (%d)", value);
                        }
                }
        }
index c9bf802c8509982977c85d69c5e643c3337cce4c..bcd923741e70f52ea5d0ce046890c66bfaa56577 100644 (file)
@@ -261,12 +261,10 @@ int ms_system_get_memory_info(int pid)
        process_memory_info_s *info = NULL;
        int ret = runtime_info_get_process_memory_info(&pid, 1, &info);
 
-       if (MM_ERROR_NONE == ret && info) {
+       if (MM_ERROR_NONE == ret && info)
                used_pss_mb = info->pss;
-               LOGI("[%d] Proportional set size %d (KB)", pid, used_pss_mb);
-       } else {
+       else
                LOGE("Fail to get process (%d) memory %s", pid, get_error_message(ret));
-       }
 
        MUSE_FREE(info);