#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();
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 *);
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));
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);