summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2018-04-26 04:42:49 (GMT)
committerhj kim <backto.kim@samsung.com>2018-05-11 00:40:46 (GMT)
commit7c69a752fe648c40dc02c40abbde669eeaa07109 (patch)
treeb1cd69254862bf9da416eff87f5a7fd4f17f953e /src
parent24da53c234808e06b5a5c29bcb5e63bffa93d30a (diff)
downloadlibmedia-thumbnail-7c69a752fe648c40dc02c40abbde669eeaa07109.zip
libmedia-thumbnail-7c69a752fe648c40dc02c40abbde669eeaa07109.tar.gz
libmedia-thumbnail-7c69a752fe648c40dc02c40abbde669eeaa07109.tar.bz2
1. Rollback to split transmission 2. Change block size 512 to 10K Change-Id: I1786a26c08546ccaade8089970ad8edeb2cf2a60 Signed-off-by: Minje Ahn <minje.ahn@samsung.com> (cherry picked from commit bd703adacacd8e39c94140883cfe535ce05d3dee)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index 917aa6a..354dc8e 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -31,6 +31,7 @@
#include <grp.h>
#include <pwd.h>
+#define THUMB_SOCK_BLOCK_SIZE 10240
#define THUMB_IPC_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcreator.socket")
static GQueue *g_manage_queue = NULL;
@@ -246,53 +247,70 @@ bool __media_thumb_check_cancel_for_raw(void)
int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
{
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);
- if (buf == NULL) {
+ THUMB_MALLOC(block_buf, THUMB_SOCK_BLOCK_SIZE);
+ if (buf == NULL || block_buf == NULL) {
thumb_err("memory allocation failed");
SAFE_FREE(buf);
+ SAFE_FREE(block_buf);
return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
if (recv(sock, buf, header_size, 0) < 0) {
thumb_stderror("recv failed");
SAFE_FREE(buf);
+ SAFE_FREE(block_buf);
return _media_thumb_get_error();
}
memcpy(msg, buf, header_size);
+ SAFE_FREE(buf);
if (strlen(msg->org_path) == 0 || strlen(msg->org_path) >= MAX_FILEPATH_LEN) {
thumb_err("org_path size is invalid %d", strlen(msg->org_path));
- SAFE_FREE(buf);
+ SAFE_FREE(block_buf);
return MS_MEDIA_ERR_SOCKET_RECEIVE;
}
/* it can be empty string */
if (strlen(msg->dst_path) >= MAX_FILEPATH_LEN) {
thumb_err("dst_path size is invalid %d", strlen(msg->dst_path));
- SAFE_FREE(buf);
+ SAFE_FREE(block_buf);
return MS_MEDIA_ERR_SOCKET_RECEIVE;
}
- 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)
+ if (buf == NULL) {
+ SAFE_FREE(block_buf);
return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
- if (recv(sock, buf, remain_size, 0) < 0) {
- thumb_stderror("recv failed");
- SAFE_FREE(buf);
- return _media_thumb_get_error();
+ while (remain_size > 0) {
+ if (remain_size < THUMB_SOCK_BLOCK_SIZE) {
+ block_size = remain_size;
+ }
+ if (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;
}
SAFE_FREE(msg->thumb_data);
@@ -301,12 +319,14 @@ 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;
}