#define LOG_TAG "MEDIA_SERVER_THUMB"
-#define THUMB_SERVER_NAME "media-thumbnail"
-#define MS_SOCK_BLOCK_SIZE 512
#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 recv_msg_len = 0;
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 *);
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) {
MS_DBG_STRERROR("recv failed");
MS_SAFE_FREE(buf);
return _media_thumb_get_error();
MS_SAFE_FREE(buf);
if (msg->msg_type == THUMB_REQUEST_KILL_SERVER) {
- MS_DBG("msg_type only cases [%d]", msg->msg_type);
- return MS_MEDIA_ERR_NONE;
+ MS_DBG("Thumb-server does not send KILL_SERVER[%d]", msg->msg_type);
+ return MS_MEDIA_ERR_DATA_TAINTED;
}
if (strlen(msg->org_path) == 0 || strlen(msg->org_path) >= MS_FILE_PATH_LEN_MAX) {
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) {
- MS_SAFE_FREE(block_buf);
+ if (buf == NULL)
return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- while (remain_size > 0) {
- if (remain_size < MS_SOCK_BLOCK_SIZE)
- block_size = remain_size;
-
- if ((recv_msg_len = 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);
+ if (recv(sock, buf, remain_size, 0) < 0) {
+ MS_DBG_STRERROR("recv failed");
+ MS_SAFE_FREE(buf);
+ return _media_thumb_get_error();
}
- MS_SAFE_FREE(block_buf);
MS_SAFE_FREE(msg->thumb_data);
MS_MALLOC(msg->thumb_data, (unsigned int)(msg->thumb_size));
_ms_thumb_set_buffer(recv_msg, &buf, &buf_size);
//MS_DBG("buffer size : %d", buf_size);
- if (send(sock, buf, buf_size, 0) != buf_size) {
+ if (send(sock, buf, buf_size, 0) < 0) {
MS_DBG_STRERROR("send failed");
MS_SAFE_FREE(buf);
close(sock);
MS_SAFE_FREE(buf);
MS_DBG_SLOG("Sending msg to thumbnail server is successful");
+ if (recv_msg->msg_type == THUMB_REQUEST_KILL_SERVER) {
+ MS_DBG_SLOG("No response if msg type is kill server[%d]", recv_msg->msg_type);
+ close(sock);
+ return TRUE;
+ }
+
if (_ms_thumb_recv_msg(sock, res_msg) < 0) {
MS_DBG_ERR("_ms_thumb_recv_msg failed");
close(sock);
if (g_server_pid > 0) {
/* Kill thumbnail server */
thumbMsg msg;
- thumbMsg recv_msg;
memset((void *)&msg, 0, sizeof(msg));
- memset((void *)&recv_msg, 0, sizeof(recv_msg));
msg.msg_type = THUMB_REQUEST_KILL_SERVER;
msg.org_path[0] = '\0';
msg.dst_path[0] = '\0';
- msg.thumb_size = 0;
/* Command Kill to thumbnail server */
g_shutdowning_thumb_server = TRUE;
- if (!_ms_thumb_agent_send_msg_to_thumb_server(&msg, &recv_msg)) {
+ if (!_ms_thumb_agent_send_msg_to_thumb_server(&msg, NULL)) {
MS_DBG_ERR("_ms_thumb_agent_send_msg_to_thumb_server is failed");
g_shutdowning_thumb_server = FALSE;
}
usleep(200000);
- MS_SAFE_FREE(recv_msg.thumb_data);
} else {
MS_DBG_ERR("g_server_pid is %d. Maybe there's problem in thumbnail-server", g_server_pid);
}
unsigned char *buf = NULL;
_ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
- if (send(client_sock, buf, buf_size, 0) != buf_size)
+ if (send(client_sock, buf, buf_size, 0) < 0)
MS_DBG_STRERROR("sendto failed");
else
MS_DBG("Sent Refuse msg from %s", recv_msg->org_path);
SAFE_STRLCPY(res_msg.org_path, recv_msg->org_path, sizeof(res_msg.org_path));
int buf_size = 0;
- int sending_block = 0;
- int block_size = sizeof(res_msg) - sizeof(unsigned char *);
+ int remain_size = 0;
+ int head_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;
- 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) != block_size)
- 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;
+ 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);
+ }
}
- if (buf_size == 0)
- MS_DBG_SLOG("Sent data(%d) from %s", res_msg.thumb_size, res_msg.org_path);
-
close(client_sock);
MS_SAFE_FREE(buf);
MS_SAFE_FREE(req->recv_msg);
int buf_size = 0;
_ms_thumb_set_buffer(&res_msg, &buf, &buf_size);
- if (send(client_sock, buf, buf_size, 0) != buf_size)
- MS_DBG_STRERROR("sendto failed");
+ if (send(client_sock, buf, buf_size, 0) < 0)
+ MS_DBG_STRERROR("send failed");
else
MS_DBG("Sent Refuse msg from %s", recv_msg->org_path);