From c4365179ef4d1606cb6998feb5f45faaa4ebda79 Mon Sep 17 00:00:00 2001 From: Jiyong Min Date: Thu, 9 Feb 2017 19:52:50 +0900 Subject: [PATCH] Modify wrong socket_fd to communicate with media-server - The socket_fd should be not -1. - Socket timeout was increased to 60 sec. The timeout error happen frequently. As the result which we tested, it took 30 sec or more at wrost case. So it was increased to 60 sec. - ETC Arrange white space and logs Change-Id: I3bd2adfd4a0d54f684dc7819685b0f74558e0fc6 Signed-off-by: jiyong.min (cherry picked from commit 8490ba208cd2315dece1059b089ab4944fab2455) --- include/DcmIpcUtils.h | 2 ++ include/DcmTypes.h | 13 +------------ src/DcmIpcUtils.cpp | 12 +++++------- svc/DcmMainSvc.cpp | 22 +++++++++++++++------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/include/DcmIpcUtils.h b/include/DcmIpcUtils.h index 62a6382..00bab42 100755 --- a/include/DcmIpcUtils.h +++ b/include/DcmIpcUtils.h @@ -20,6 +20,8 @@ #include +#define DCM_TIMEOUT_SEC_60 60 /**< Response to media server time out */ + namespace DcmIpcUtils { int createSocket(int *socket_fd, DcmIpcPortType port); int acceptSocket(int serv_sock, int *client_sock); diff --git a/include/DcmTypes.h b/include/DcmTypes.h index c92a841..f88b417 100755 --- a/include/DcmTypes.h +++ b/include/DcmTypes.h @@ -79,9 +79,9 @@ typedef struct { DcmIpcMsgType msg_type; int pid; uid_t uid; + int result; size_t msg_size; /*this is size of message below and this does not include the terminationg null byte ('\0'). */ char msg[DCM_IPC_MSG_MAX_SIZE]; - int result; } DcmIpcMsg; typedef enum { @@ -103,17 +103,6 @@ typedef struct { DcmScanItemType scan_item_type; } DcmScanItem; -typedef enum { - DCM_FACE_ITEM_UPDATE_FACE = 0, /**< One face item is upated */ -} DcmFaceItemUpdateItem; - -typedef enum { - DCM_FACE_ITEM_INSERT = 0, /**< Database update operation is INSERT */ - DCM_FACE_ITEM_DELETE = 1, /**< Database update operation is DELETE */ - DCM_FACE_ITEM_UPDATE = 2, /**< Database update operation is UPDATE */ - DCM_FACE_ITEM_REMOVE = 3, /**< Database update operation is REMOVE */ -} DcmFaceItemUpdateType; - typedef struct { char *face_uuid; char *media_uuid; diff --git a/src/DcmIpcUtils.cpp b/src/DcmIpcUtils.cpp index ad5f395..19b1016 100755 --- a/src/DcmIpcUtils.cpp +++ b/src/DcmIpcUtils.cpp @@ -140,15 +140,15 @@ int DcmIpcUtils::sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, unsi dcm_error("Invalid port! Stop sending message..."); return DCM_ERROR_INVALID_PARAMETER; } - dcm_debug("Send message type: %d", msg_type); + dcm_debug("Send message type: %d %s %d", msg_type, msg, result); DcmIpcMsg send_msg; int sock = -1; if (socket_fd < 0) { struct sockaddr_un serv_addr; - struct timeval tv_timeout = { 10, 0 }; - + struct timeval tv_timeout = { DCM_TIMEOUT_SEC_60, 0 }; /* timeout: 60 seconds */ + if ((sock = socket(PF_FILE, SOCK_STREAM, 0)) < 0) { dcm_stderror("socket failed"); return DCM_ERROR_NETWORK; @@ -177,7 +177,7 @@ int DcmIpcUtils::sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, unsi /* Prepare send message */ memset((void *)&send_msg, 0, sizeof(DcmIpcMsg)); send_msg.msg_type = msg_type; - send_msg.result = result; + send_msg.result = (int)result; if (msg != NULL) { send_msg.msg_size = strlen(msg); strncpy(send_msg.msg, msg, send_msg.msg_size); @@ -197,7 +197,7 @@ int DcmIpcUtils::sendClientSocketMsg(int socket_fd, DcmIpcMsgType msg_type, unsi return DCM_ERROR_NETWORK; } - dcm_debug("Sent message type: %d", msg_type); + dcm_debug("Sent message type: %d %d", send_msg.msg_type, send_msg.result); close(sock); return DCM_SUCCESS; @@ -213,7 +213,6 @@ int DcmIpcUtils::sendSocketMsg(DcmIpcMsgType msg_type, uid_t uid, const char *ms int socket_fd = -1; struct sockaddr_un serv_addr; - //struct timeval tv_timeout = { 10, 0 }; /* timeout: 10 seconds */ DcmIpcMsg send_msg; /* Prepare send message */ @@ -270,7 +269,6 @@ int DcmIpcUtils::sendCompleteMsg(DcmIpcMsgType msg_type, const unsigned int coun int socket_fd = -1; struct sockaddr_un serv_addr; - //struct timeval tv_timeout = { 10, 0 }; /* timeout: 10 seconds */ DcmIpcMsg send_msg; /* Prepare send message */ diff --git a/svc/DcmMainSvc.cpp b/svc/DcmMainSvc.cpp index 37a83ef..e33896c 100755 --- a/svc/DcmMainSvc.cpp +++ b/svc/DcmMainSvc.cpp @@ -63,7 +63,7 @@ void DcmMainSvc::dcmServiceStartjobs(void) } /* Send ready response to dcm launcher */ - if (DcmIpcUtils::sendClientSocketMsg(-1, DCM_IPC_MSG_SERVICE_READY, 0, NULL, DCM_IPC_PORT_MS_RECV) != DCM_SUCCESS) { + if (DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SERVICE_READY, 0, NULL, DCM_IPC_PORT_MS_RECV) != DCM_SUCCESS) { dcm_error("Failed to send ready message"); } } @@ -160,6 +160,7 @@ gboolean DcmMainSvcCallBack::readMsg(GIOChannel *src, GIOCondition condition, gp if (DcmIpcUtils::receiveSocketMsg(client_sock, &recv_msg) < 0) { dcm_error("getRecvMsg failed"); + DcmIpcUtils::closeSocket(client_sock); return TRUE; } @@ -170,6 +171,7 @@ gboolean DcmMainSvcCallBack::readMsg(GIOChannel *src, GIOCondition condition, gp /* Create scan thread before main loop is started */ if (dcmSvc->createScanThread() != DCM_SUCCESS) { dcm_error("Failed to create scan thread! Exit main thread..."); + DcmIpcUtils::closeSocket(client_sock); return TRUE; } @@ -196,12 +198,18 @@ gboolean DcmMainSvcCallBack::readMsg(GIOChannel *src, GIOCondition condition, gp } else if (recv_msg.msg_type == DCM_IPC_MSG_SCAN_SINGLE) { dcm_debug("Scan single"); ret = DcmScanMain::ScanSingle(recv_msg.msg, recv_msg.uid, &face_count); - dcm_debug("Scan single result: %d", face_count); - ret = DcmIpcUtils::sendClientSocketMsg(-1, DCM_IPC_MSG_SCAN_SINGLE, face_count, recv_msg.msg, DCM_IPC_PORT_MS_RECV); - //ret = DcmIpcUtils::sendSocketMsg(DCM_IPC_MSG_SCAN_SINGLE, recv_msg.uid, recv_msg.msg, DCM_IPC_PORT_SCAN_RECV); -/* if (ret == DCM_SUCCESS) { - ret = DcmIpcUtils::sendClientSocketMsg(client_sock, DCM_IPC_MSG_SCAN_SINGLE, recv_msg.uid, recv_msg.msg, DCM_IPC_PORT_DCM_RECV); - }*/ + dcm_debug("Scan single result: %d (%d)", ret, face_count); + if (ret == DCM_SUCCESS) { + ret = DcmIpcUtils::sendClientSocketMsg(client_sock, DCM_IPC_MSG_SCAN_SINGLE, face_count, recv_msg.msg, DCM_IPC_PORT_MS_RECV); + if (ret != DCM_SUCCESS) { + dcm_error("Failed to sendClientSocketMsg! err: %d", ret); + } + } else { + ret = DcmIpcUtils::sendClientSocketMsg(client_sock, DCM_IPC_MSG_SCAN_SINGLE, ret, recv_msg.msg, DCM_IPC_PORT_MS_RECV); + if (ret != DCM_SUCCESS) { + dcm_error("Failed to sendClientSocketMsg! err: %d", ret); + } + } } else { dcm_debug("createDcmSvcReadSocket, invalid message(%d).", recv_msg.msg_type); } -- 2.34.1