diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/ipc/media-thumb-ipc.c | 55 |
1 files changed, 17 insertions, 38 deletions
diff --git a/src/ipc/media-thumb-ipc.c b/src/ipc/media-thumb-ipc.c index 1b9393d..ae1a8a0 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 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(); } @@ -273,45 +265,34 @@ int _media_thumb_recv_msg(int sock, int header_size, thumbMsg *msg) 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); 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); 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) { - 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 +301,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; } @@ -366,6 +345,7 @@ int _media_thumb_set_buffer(thumbMsg *req_msg, unsigned char **buf, int *buf_siz int _media_thumb_request(int msg_type, const char *origin_path, char *thumb_path, int max_length, uid_t uid) { int sock = -1; + int header_size = 0; struct sockaddr_un serv_addr; int recv_str_len = 0; int err = MS_MEDIA_ERR_NONE; @@ -406,12 +386,11 @@ int _media_thumb_request(int msg_type, const char *origin_path, char *thumb_path unsigned char *buf = NULL; int buf_size = 0; - int header_size = 0; - header_size = sizeof(thumbMsg) - MAX_PATH_SIZE*2 - sizeof(unsigned char *); + header_size = sizeof(thumbMsg) - sizeof(unsigned char *); _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); close(sock); @@ -599,8 +578,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); @@ -691,8 +670,8 @@ 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) { - 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); |