#endif
#undef LOG_TAG
-#define LOG_TAG "MUSED_SERVER"
-#define MSG_KEY_PID "pid"
-#define MS_TIMEOUT_MSEC 1000
+#define LOG_TAG "MUSED_SERVER"
+#define MSG_KEY_PID "pid"
+#define MS_TIMEOUT_SEC 1
+#define MS_TIMEOUT_MSEC MS_TIMEOUT_SEC * 1000
#define MS_RECV_TRY_COUNT_MAX 3
-
-#define MSG_DONE "DONE"
+#define MSG_DONE "DONE"
gboolean ms_ipc_job_function(ms_workqueue_job_t *job);
gboolean ms_ipc_data_job_function(ms_workqueue_job_t *job);
{
int idx, fd, ep_fd, fd_count, errsv;
struct epoll_event *p_event;
+ struct timeval tv_c, tv_s, tv_r;
char err_msg[MUSE_MSG_LEN_MAX] = {'\0',};
ms_connection_t *connection = NULL;
ep_fd = connection->epfd;
do { /* We have to execute epoll_wait again in case of error of EINTR */
+ gettimeofday(&tv_s, NULL);
fd_count = epoll_wait(ep_fd, connection->events, MS_EVENT_MAX, MS_TIMEOUT_MSEC);
if (fd_count < 0) {
errsv = errno;
strerror_r(errsv, err_msg, MUSE_MSG_LEN_MAX);
LOGE("[%d : %d] errno : %d (%s)", ep_fd, muse_core_fd_is_valid(ep_fd), errsv, err_msg);
}
+ gettimeofday(&tv_c, NULL);
} while (fd_count < 0 && errsv == EINTR);
if (fd_count == 0) { /* There is no muse instance during timeout, which is not error case */
+ timersub(&tv_c, &tv_s, &tv_r);
+ if (tv_r.tv_sec != MS_TIMEOUT_SEC) {
+ LOGW("sleep (10 ms) because epoll_wait does not wait for events during timeout, which would occur high cpu usage");
+ usleep(100000);
+ }
return FALSE;
} else if (fd_count < 0) { /* When an error occurs, epoll_wait() returns -1 */
strerror_r(errno, err_msg, MUSE_MSG_LEN_MAX);