gboolean muse_core_ipc_job_function(struct muse_core_workqueue_job * job);
int muse_core_ipc_send_msg(int sock_fd, const char *msg);
-int muse_core_ipc_send_fd_msg(int sock_fd, int fd, const char *buf);
+int muse_core_ipc_send_fd_msg(int sock_fd, int *fds, const char *buf);
int muse_core_ipc_recv_msg(int sock_fd, char *msg);
-int muse_core_ipc_recv_fd_msg(int sock_fd, const char *buf, int *out_fd);
+int muse_core_ipc_recv_fd_msg(int sock_fd, char *buf, int *out_fd);
void muse_core_ipc_set_timeout(int sock_fd, unsigned long timeout_sec);
gboolean muse_core_ipc_data_job_function(muse_core_workqueue_job_t * job);
int muse_core_ipc_push_data(int sock_fd, const char *data, int size, uint64_t data_id);
muse_core_module_get_instance()->dispatch(cmd, module);
if (module->is_create_api_called == false) {
- LOGE("<<< ### _muse_core_ipc_client_cleanup [module %p] [get_dllsymbol_loaded_value %d]", module, value);
+ LOGE("_muse_core_ipc_client_cleanup [module %p] [get_dllsymbol_loaded_value %d]", module, value);
if (!value) {
LOGW("release module dll handle");
{
char *ptr = NULL;
size_t ptr_len = 0;
- size_t msg_len = 0;
int idx = 0;
g_return_val_if_fail(msg != NULL, MM_ERROR_NONE);
- msg_len = strlen(msg);
- msg[msg_len + 1] = '\0';
-
if (g_muse_core_ipc == NULL)
return MM_ERROR_NONE;
idx = ptr - msg;
memcpy(g_muse_core_ipc->muse_msg->cache, ptr + 1, ptr_len);
g_muse_core_ipc->muse_msg->cache_len = ptr_len;
- msg[idx + 1] = '\0';
}
return ptr_len;
int muse_core_ipc_send_msg(int sock_fd, const char *msg)
{
g_return_val_if_fail(msg != NULL, MM_ERROR_INVALID_ARGUMENT);
- return muse_core_ipc_send_fd_msg(sock_fd, SOCK_ERR, msg);
+ return muse_core_ipc_send_fd_msg(sock_fd, NULL, msg);
}
-int muse_core_ipc_send_fd_msg(int sock_fd, int fd, const char *buf)
+int muse_core_ipc_send_fd_msg(int sock_fd, int *fds, const char *buf)
{
int ret = MM_ERROR_NONE;
struct cmsghdr *cptr;
struct msghdr msg;
struct iovec iov;
- char data[CMSG_SPACE(sizeof(int))];
+ char data[CMSG_SPACE(sizeof(int)) * MUSE_NUM_FD];
char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
+ int *fdptr;
g_return_val_if_fail(buf != NULL, MM_ERROR_INVALID_ARGUMENT);
#endif
memset(&iov, 0, sizeof(iov));
- iov.iov_base = (void*)buf;
+ iov.iov_base = (void *)buf;
iov.iov_len = strlen(buf);
memset(&msg, 0, sizeof(msg));
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
- if (fd == SOCK_ERR) { /* when muse_core_ipc_send_msg is called */
+ if (fds == NULL) { /* when muse_core_ipc_send_msg is called */
msg.msg_control = NULL;
msg.msg_controllen = 0;
} else {
cptr = CMSG_FIRSTHDR(&msg);
if (cptr) {
- cptr->cmsg_len = CMSG_LEN(sizeof(int));
+ cptr->cmsg_len = CMSG_LEN(sizeof(int) * MUSE_NUM_FD);
cptr->cmsg_level = SOL_SOCKET;
cptr->cmsg_type = SCM_RIGHTS;
- *((int *) CMSG_DATA(cptr)) = fd;
- } else {
- LOGE("CMSG_FIRSTHDR NULL");
+ fdptr = (int *)CMSG_DATA(cptr);
+ memcpy(fdptr, fds, sizeof(int) * MUSE_NUM_FD);
+
+ /* the value of msg_controllen increases after memcpy so reassignes the orginal value */
+ msg.msg_controllen = cptr->cmsg_len;
}
}
return muse_core_ipc_recv_fd_msg(sock_fd, msg, NULL);
}
-int muse_core_ipc_recv_fd_msg(int sock_fd, const char *buf, int *out_fd)
+int muse_core_ipc_recv_fd_msg(int sock_fd, char *buf, int *out_fd)
{
int ret = MM_ERROR_NONE;
struct cmsghdr *cptr;
struct msghdr msg;
struct iovec iov;
int remained_msg_len = 0;
- char data[CMSG_SPACE(sizeof(int))];
+ char data[CMSG_SPACE(sizeof(int) * MUSE_NUM_FD)];
char err_msg[MAX_ERROR_MSG_LEN] = {'\0',};
+ int idx;
g_return_val_if_fail(buf != NULL, MM_ERROR_INVALID_ARGUMENT);
if ((ret = recvmsg(sock_fd, &msg, 0)) == SOCK_ERR) {
strerror_r(errno, err_msg, MAX_ERROR_MSG_LEN);
LOGE("fail to receive msg (%s)", err_msg);
+ return ret;
}
- /* When muse_core_ipc_send_fd_msg is called, cptr is null because send_fd is -1 (EBADF ERROR) */
- cptr = CMSG_FIRSTHDR(&msg);
-
if (out_fd) {
- if (cptr) {
- *out_fd = *(int*)CMSG_DATA(cptr);
- LOGD("out fd : %d", *out_fd);
- } else {
- *out_fd = SOCK_ERR;
+ /* When muse_core_ipc_send_fd_msg is called, cptr is null because send_fd is -1 (EBADF ERROR) */
+ cptr = CMSG_FIRSTHDR(&msg);
+
+ for (idx = 0; idx < MUSE_NUM_FD; idx++) {
+ if (cptr == NULL) {
+ out_fd[idx] = SOCK_ERR; /* you can check that idx is the last pointer */
+ break;
+ }
+ out_fd[idx] = *(int *)CMSG_DATA(cptr);
+ cptr = CMSG_NXTHDR(&msg, cptr);
}
}
+ buf[ret] = '\0';
+
return ret;
}
break;
case json_type_double:
*(double *)data = json_object_get_double(val);
- LOGD("json_type_double (%s) value: %p", key, (double *)data);
break;
case json_type_int:
if (m_type == MUSE_TYPE_ANY || m_type == MUSE_TYPE_INT) {
*(int32_t *)data = json_object_get_int(val);
- LOGD("json_type_int (%s) value: %d", key, *(int32_t *)data);
} else if (m_type == MUSE_TYPE_INT64) {
*(int64_t *)data = json_object_get_int64(val);
- LOGD("json_type_int (%s) value: %" G_GINT64_FORMAT "", key, *(int64_t *)data);
} else if (m_type == MUSE_TYPE_POINTER) {
if (sizeof(intptr_t) == 8)
*(intptr_t *)data = json_object_get_int64(val);
else
*(intptr_t *)data = json_object_get_int(val);
- LOGD("json_type_int (%s) value: %p", key, *(intptr_t *)data);
} else if (m_type == MUSE_TYPE_DOUBLE) {
*(double *)data = json_object_get_double(val);
- LOGD("json_type_double (%s) value: %.20lf", key, *(double *)data);
}
break;
case json_type_object: