Modified TCP transfer 76/171776/1 accepted/tizen/unified/20180313.061057 submit/tizen/20180312.055137
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 7 Mar 2018 07:36:24 +0000 (16:36 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Wed, 7 Mar 2018 07:36:24 +0000 (16:36 +0900)
1. Modified result compare
2. Remove response for kill-msg
3. Remove block send

Change-Id: Idde2423e5054e9813a746ee89779aaee35a62f8d
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/libmedia-thumbnail.spec
server/thumb-server-internal.c
src/ipc/media-thumb-ipc.c

index 40df784..c8020b5 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmedia-thumbnail
 Summary:    Media thumbnail service library for multimedia applications
-Version: 0.2.19
+Version: 0.2.20
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0 and PD
index e15ee8d..5a279d4 100755 (executable)
@@ -37,7 +37,6 @@
 #define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
 #define THUMB_DEFAULT_WIDTH 320
 #define THUMB_DEFAULT_HEIGHT 240
-#define THUMB_BLOCK_SIZE 512
 #define THUMB_COMM_SOCK_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcomm.socket")
 #define THUMB_EMPTY_STR ""
 
@@ -112,6 +111,11 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
                        close(client_sock);
                        return TRUE;
                }
+       } else {
+               thumb_warn("Shutting down...");
+               g_main_loop_quit(g_thumb_server_mainloop);
+               close(client_sock);
+               return TRUE;
        }
 
        SAFE_FREE(credentials.smack);
@@ -119,8 +123,7 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
 
        thumb_warn_slog("Received [%d] %.*s(%d) from PID(%d)", recv_msg.msg_type, MAX_FILEPATH_LEN, recv_msg.org_path, strlen(recv_msg.org_path), recv_msg.pid);
 
-       if (recv_msg.msg_type != THUMB_REQUEST_KILL_SERVER)
-               _thumb_daemon_process_job(&recv_msg, &res_msg);
+       _thumb_daemon_process_job(&recv_msg, &res_msg);
 
        if (res_msg.msg_type == 0)
                res_msg.msg_type = recv_msg.msg_type;
@@ -132,35 +135,29 @@ gboolean _thumb_server_read_socket(GIOChannel *src, GIOCondition condition, gpoi
                res_msg.dst_path[0] = '\0';
 
        int buf_size = 0;
-       int sending_block = 0;
-       int block_size = sizeof(res_msg) - sizeof(unsigned char *);
+       int remain_size = 0;
+       int head_size = sizeof(res_msg) - sizeof(unsigned char *);
        unsigned char *buf = NULL;
        _media_thumb_set_buffer(&res_msg, &buf, &buf_size);
+       remain_size = buf_size - head_size;
 
-       while (buf_size > 0) {
-               if (buf_size < THUMB_BLOCK_SIZE)
-                       block_size = buf_size;
-
-               if (send(client_sock, buf+sending_block, block_size, 0) != block_size) {
-                       thumb_stderror("sendto failed");
+       if (send(client_sock, buf, head_size, 0) < 0) {
+               thumb_stderror("send failed");
+       } else {
+               if (remain_size > 0) {
+                       if (send(client_sock, buf + head_size, remain_size, 0) < 0) {
+                               thumb_stderror("send failed");
+                       } else {
+                               thumb_dbg_slog("Sent data(%d) from %s", res_msg.thumb_size, res_msg.org_path);
+                       }
+               } else {
+                       thumb_dbg_slog("Sent thumbnail(%s) from %s", res_msg.dst_path, res_msg.org_path);
                }
-
-               sending_block += block_size;
-               buf_size -= block_size;
-               if (block_size < THUMB_BLOCK_SIZE)
-                       block_size = THUMB_BLOCK_SIZE;
        }
 
-       thumb_dbg_slog("Sent data(%d) from %s", res_msg.thumb_size, res_msg.org_path);
-
        SAFE_FREE(buf);
        SAFE_FREE(res_msg.thumb_data);
 
-       if (recv_msg.msg_type == THUMB_REQUEST_KILL_SERVER) {
-               thumb_warn("Shutting down...");
-               g_main_loop_quit(g_thumb_server_mainloop);
-       }
-
        close(client_sock);
 
        return TRUE;
@@ -191,8 +188,8 @@ static gboolean __thumb_server_send_msg_to_agent(int msg_type)
 
        send_msg.msg_type = msg_type;
 
-       if (send(sock, &send_msg, sizeof(ms_thumb_server_msg), 0) != sizeof(ms_thumb_server_msg)) {
-               thumb_stderror("sendto failed");
+       if (send(sock, &send_msg, sizeof(ms_thumb_server_msg), 0) < 0) {
+               thumb_stderror("send failed");
                close(sock);
                return FALSE;
        }
@@ -211,7 +208,7 @@ static gboolean _thumb_server_send_deny_message(int sockfd)
        msg.msg_type = THUMB_RESPONSE;
        msg.status = MS_MEDIA_ERR_PERMISSION_DENIED;
 
-       if (send(sockfd, &msg, bytes_to_send, 0) != bytes_to_send) {
+       if (send(sockfd, &msg, bytes_to_send, 0) < 0) {
                thumb_stderror("send failed");
                return FALSE;
        }
index 9f652a2..feaff11 100755 (executable)
@@ -31,7 +31,6 @@
 #include <grp.h>
 #include <pwd.h>
 
-#define THUMB_SOCK_BLOCK_SIZE 512
 #define THUMB_IPC_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcreator.socket")
 
 static GQueue *g_manage_queue = NULL;
@@ -246,26 +245,19 @@ bool __media_thumb_check_cancel_for_raw(void)
 
 int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
 {
-       int recv_msg_len = 0;
        int remain_size = 0;
-       int block_size = THUMB_SOCK_BLOCK_SIZE;
-       int recv_block = 0;
        unsigned char *buf = NULL;
-       unsigned char *block_buf = NULL;
 
        THUMB_MALLOC(buf, header_size);
-       THUMB_MALLOC(block_buf, THUMB_SOCK_BLOCK_SIZE);
-       if (buf == NULL || block_buf == NULL) {
+       if (buf == NULL) {
                thumb_err("memory allocation failed");
                SAFE_FREE(buf);
-               SAFE_FREE(block_buf);
                return MS_MEDIA_ERR_OUT_OF_MEMORY;
        }
 
-       if ((recv_msg_len = recv(sock, buf, header_size, 0)) <= 0) {
+       if (recv(sock, buf, header_size, 0) < 0) {
                thumb_stderror("recv failed");
                SAFE_FREE(buf);
-               SAFE_FREE(block_buf);
                return _media_thumb_get_error();
        }
 
@@ -287,31 +279,19 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
        SAFE_FREE(buf);
        if (msg->thumb_size < 0) {
                thumb_err("recv data is wrong");
-               SAFE_FREE(block_buf);
                return MS_MEDIA_ERR_SOCKET_RECEIVE;
        }
 
        if (msg->thumb_size > 0) {
                remain_size = msg->thumb_size;
                THUMB_MALLOC(buf, remain_size);
-               if (buf == NULL) {
-                       SAFE_FREE(block_buf);
+               if (buf == NULL)
                        return MS_MEDIA_ERR_OUT_OF_MEMORY;
-               }
 
-               while (remain_size > 0) {
-                       if (remain_size < THUMB_SOCK_BLOCK_SIZE) {
-                               block_size = remain_size;
-                       }
-                       if ((recv_msg_len = recv(sock, block_buf, block_size, 0)) < 0) {
-                               thumb_stderror("recv failed");
-                               SAFE_FREE(buf);
-                               SAFE_FREE(block_buf);
-                               return _media_thumb_get_error();
-                       }
-                       memcpy(buf+recv_block, block_buf, block_size);
-                       recv_block += block_size;
-                       remain_size -= block_size;
+               if (recv(sock, buf, remain_size, 0) < 0) {
+                       thumb_stderror("recv failed");
+                       SAFE_FREE(buf);
+                       return _media_thumb_get_error();
                }
 
                SAFE_FREE(msg->thumb_data);
@@ -320,14 +300,12 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
                        memcpy(msg->thumb_data, buf, msg->thumb_size);
                } else {
                        SAFE_FREE(buf);
-                       SAFE_FREE(block_buf);
 
                        return MS_MEDIA_ERR_OUT_OF_MEMORY;
                }
        }
 
        SAFE_FREE(buf);
-       SAFE_FREE(block_buf);
 
        return MS_MEDIA_ERR_NONE;
 }
@@ -513,8 +491,8 @@ static int _media_thumb_send_request()
        int buf_size = 0;
        _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
 
-       if (send(sock, buf, buf_size, 0) != buf_size) {
-               thumb_err("sendto failed: %d", errno);
+       if (send(sock, buf, buf_size, 0) < 0) {
+               thumb_err("send failed: %d", errno);
                SAFE_FREE(buf);
                g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));
                g_io_channel_shutdown(channel, TRUE, NULL);
@@ -605,7 +583,7 @@ static int _media_thumb_raw_data_send_request()
        int buf_size = 0;
        _media_thumb_set_buffer(&req_msg, &buf, &buf_size);
 
-       if (send(sock, buf, buf_size, 0) != buf_size) {
+       if (send(sock, buf, buf_size, 0) < 0) {
                thumb_err("sendto failed: %d", errno);
                SAFE_FREE(buf);
                g_source_destroy(g_main_context_find_source_by_id(g_main_context_get_thread_default(), source_id));