Modify wrong socket_fd to communicate with media-server 27/115727/1
authorJiyong Min <jiyong.min@samsung.com>
Thu, 9 Feb 2017 10:52:50 +0000 (19:52 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Tue, 21 Feb 2017 06:38:45 +0000 (22:38 -0800)
 - 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 <jiyong.min@samsung.com>
(cherry picked from commit 8490ba208cd2315dece1059b089ab4944fab2455)

include/DcmIpcUtils.h
include/DcmTypes.h
src/DcmIpcUtils.cpp
svc/DcmMainSvc.cpp

index 62a63820c72a28ba00616747fb2897d5de8630c8..00bab422ab4194ddcebe2566ee66486118637043 100755 (executable)
@@ -20,6 +20,8 @@
 
 #include <DcmTypes.h>
 
+#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);
index c92a84188a8d0ad9c61c3a369ed23a1fb3f879a3..f88b417d80e64917cd55a8d22576f92225289d07 100755 (executable)
@@ -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;
index ad5f3953768da5466715e68908dfb97711f3dd3e..19b1016dfbbdaf0e9210e12b9016a8a5f3b23332 100755 (executable)
@@ -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 */
index 37a83ef818c58ecb8b08b96d2142beaf662dde70..e33896c9b8e7eb918ed6652fba1551931e9eb219 100755 (executable)
@@ -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);
        }