summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2018-08-16 05:08:07 (GMT)
committerMinje ahn <minje.ahn@samsung.com>2018-08-16 06:42:18 (GMT)
commit248a3a5c689466bf4f99abd2fde7c485acd24466 (patch)
tree25f9d05e394634c54c398d21852859921b4075ee
parentbd703adacacd8e39c94140883cfe535ce05d3dee (diff)
downloadlibmedia-thumbnail-accepted/tizen_4.0_unified.zip
libmedia-thumbnail-accepted/tizen_4.0_unified.tar.gz
libmedia-thumbnail-accepted/tizen_4.0_unified.tar.bz2
Change-Id: I28a1445463df8dc6ac6fb18fb1a2d395913d8264 Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
-rwxr-xr-xserver/thumb-server-internal.c18
-rwxr-xr-xsrc/ipc/media-thumb-ipc.c45
2 files changed, 25 insertions, 38 deletions
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index 16d58f3..6e1138a 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -38,7 +38,6 @@
#define LOG_TAG "MEDIA_THUMBNAIL_SERVER"
#define THUMB_DEFAULT_WIDTH 320
#define THUMB_DEFAULT_HEIGHT 240
-#define THUMB_BLOCK_SIZE 10240
#define THUMB_COMM_SOCK_PATH tzplatform_mkpath(TZ_SYS_RUN, "media-server/media_ipc_thumbcomm.socket")
#define THUMB_EMPTY_STR ""
@@ -149,23 +148,18 @@ 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 send_len = 0;
+ int send_pos = 0;
unsigned char *buf = NULL;
_media_thumb_set_buffer(&res_msg, &buf, &buf_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) < 0) {
+ if ((send_len = send(client_sock, buf + send_pos, buf_size, 0)) < 0) {
thumb_stderror("send failed");
+ break;
}
-
- sending_block += block_size;
- buf_size -= block_size;
- if (block_size < THUMB_BLOCK_SIZE)
- block_size = THUMB_BLOCK_SIZE;
+ send_pos += send_len;
+ buf_size -= send_len;
}
SAFE_FREE(buf);
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c
index b092cea..95870d2 100755
--- a/src/ipc/media-thumb-ipc.c
+++ b/src/ipc/media-thumb-ipc.c
@@ -31,7 +31,6 @@
#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;
@@ -247,46 +246,46 @@ 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;
+ int recv_len = 0;
+ int recv_pos = 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(sock, buf, header_size, 0) < 0) {
- thumb_stderror("recv failed");
- SAFE_FREE(buf);
- SAFE_FREE(block_buf);
- return _media_thumb_get_error();
+ while (header_size > 0) {
+ if ((recv_len = recv(sock, buf + recv_pos, header_size, 0)) < 0) {
+ thumb_stderror("recv failed");
+ SAFE_FREE(buf);
+ return _media_thumb_get_error();
+ }
+ header_size -= recv_len;
+ recv_pos += recv_len;
}
+ header_size = recv_pos;
+ recv_pos = 0;
+
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(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(block_buf);
return MS_MEDIA_ERR_SOCKET_RECEIVE;
}
if (msg->thumb_size < 0) {
thumb_err("recv data is wrong");
- SAFE_FREE(block_buf);
return MS_MEDIA_ERR_SOCKET_RECEIVE;
}
@@ -294,23 +293,19 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg)
remain_size = msg->thumb_size;
THUMB_MALLOC(buf, remain_size);
if (buf == NULL) {
- SAFE_FREE(block_buf);
return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
while (remain_size > 0) {
- if (remain_size < THUMB_SOCK_BLOCK_SIZE) {
- block_size = remain_size;
- }
- if (recv(sock, block_buf, block_size, 0) < 0) {
+ if ((recv_len = recv(sock, buf + recv_pos, remain_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;
+
+ fsync(sock);
+ remain_size -= recv_len;
+ recv_pos += recv_len;
}
SAFE_FREE(msg->thumb_data);
@@ -319,14 +314,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;
}