Change TCP transfer 24/177424/2 submit/tizen/20180511.003859
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 26 Apr 2018 04:41:14 +0000 (13:41 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 11 May 2018 00:36:26 +0000 (00:36 +0000)
1. Rollback to split transmission
2. Change block size 512 to 10K

Change-Id: If3d95755db21a9ebca98c7d3f48a905c498c9355
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
(cherry picked from commit 7f023fb5587ebc4fbedf73575c69755ef1f5dd84)

src/server/media-server-thumb.c

index f99a138..711804c 100755 (executable)
@@ -31,6 +31,7 @@
 
 #define LOG_TAG "MEDIA_SERVER_THUMB"
 
+#define MS_SOCK_BLOCK_SIZE 10240
 #define THUMB_SERVER_PATH tzplatform_mkpath(TZ_SYS_BIN, "media-thumbnail-server")
 
 gboolean _ms_thumb_agent_timer();
@@ -106,7 +107,11 @@ int _media_thumb_get_error()
 int _ms_thumb_recv_msg(int sock, thumbMsg *msg)
 {
        int remain_size = 0;
+       int block_size = MS_SOCK_BLOCK_SIZE;
+       int recv_block = 0;
        unsigned char *buf = NULL;
+       unsigned char *block_buf = NULL;
+
        unsigned int header_size = 0;
 
        header_size = sizeof(thumbMsg) - sizeof(unsigned char *);
@@ -153,17 +158,33 @@ int _ms_thumb_recv_msg(int sock, thumbMsg *msg)
 
        if (msg->thumb_size > 0) {
                remain_size = msg->thumb_size;
+               MS_MALLOC(block_buf, MS_SOCK_BLOCK_SIZE);
+               if (block_buf == NULL)
+                       return MS_MEDIA_ERR_OUT_OF_MEMORY;
 
                MS_MALLOC(buf, remain_size);
-               if (buf == NULL)
+               if (buf == NULL) {
+                       MS_SAFE_FREE(block_buf);
                        return MS_MEDIA_ERR_OUT_OF_MEMORY;
+               }
 
-               if (recv(sock, buf, remain_size, 0) < 0) {
-                       MS_DBG_STRERROR("recv failed");
-                       MS_SAFE_FREE(buf);
-                       return _media_thumb_get_error();
+               while (remain_size > 0) {
+                       if (remain_size < MS_SOCK_BLOCK_SIZE)
+                               block_size = remain_size;
+
+                       if (recv(sock, block_buf, block_size, 0) < 0) {
+                               MS_DBG_STRERROR("recv failed");
+                               MS_SAFE_FREE(buf);
+                               MS_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;
+                       memset(block_buf, 0, MS_SOCK_BLOCK_SIZE);
                }
 
+               MS_SAFE_FREE(block_buf);
                MS_SAFE_FREE(msg->thumb_data);
 
                MS_MALLOC(msg->thumb_data, (unsigned int)(msg->thumb_size));
@@ -457,23 +478,22 @@ gboolean _ms_thumb_request_to_server(gpointer data)
        SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
 
        int buf_size = 0;
-       int remain_size = 0;
-       int head_size = sizeof(res_msg) - sizeof(unsigned char *);
+       int sending_block = 0;
+       int block_size = sizeof(res_msg) - sizeof(unsigned char *);
        unsigned char *buf = NULL;
        _ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
-       remain_size = buf_size - head_size;
 
-       if (send(client_sock, buf, head_size, 0) < 0) {
-               MS_DBG_STRERROR("send failed");
-       } else {
-               if (remain_size > 0) {
-                       if (send(client_sock, buf + head_size, remain_size, 0) < 0)
-                               MS_DBG_STRERROR("send failed");
-                       else
-                               MS_DBG_SLOG("Sent data(%d) from %s", res_msg.thumb_size, res_msg.org_path);
-               } else {
-                       MS_DBG_SLOG("Sent thumb(%s) from %s", res_msg.dst_path, res_msg.org_path);
-               }
+       while (buf_size > 0) {
+               if (buf_size < MS_SOCK_BLOCK_SIZE)
+                       block_size = buf_size;
+
+               if (send(client_sock, buf+sending_block, block_size, 0) < 0)
+                       MS_DBG_STRERROR("sendto failed");
+
+               sending_block += block_size;
+               buf_size -= block_size;
+               if (block_size < MS_SOCK_BLOCK_SIZE)
+                       block_size = MS_SOCK_BLOCK_SIZE;
        }
 
        close(client_sock);