From 70be48c73875fc2a8da25f1df4fe3a6502106678 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Wed, 4 Sep 2019 15:39:07 +0900 Subject: [PATCH] Remove batch db thread Use db update thread instead Change-Id: I6f559d98302f68f7750371b7f7a537e5f03a24b8 Signed-off-by: Minje Ahn --- lib/include/media-server-ipc.h | 7 +- lib/include/media-util-db.h | 8 - lib/include/media-util-internal.h | 3 - lib/media-util-db.c | 292 ------------------------------- lib/media-util-ipc.c | 1 - src/server/include/media-server-socket.h | 1 - src/server/media-server-db.c | 21 --- src/server/media-server-socket.c | 193 -------------------- 8 files changed, 1 insertion(+), 525 deletions(-) diff --git a/lib/include/media-server-ipc.h b/lib/include/media-server-ipc.h index d71f37f..a1046e4 100755 --- a/lib/include/media-server-ipc.h +++ b/lib/include/media-server-ipc.h @@ -22,15 +22,13 @@ #ifndef _MEDIA_SERVER_IPC_H_ #define _MEDIA_SERVER_IPC_H_ -#define MS_TIMEOUT_SEC_3 3 /**< Response from Server time out */ #define MS_TIMEOUT_SEC_10 10 /**< Response from Server time out */ #define MS_TIMEOUT_SEC_20 20 /**< Response from Media server time out */ #define MS_TIMEOUT_SEC_60 60 /**< Response from DCM daemon time out */ typedef enum { - MS_DB_BATCH_UPDATE_PORT = 0, /**< Media DB batch update */ - MS_SCAN_DAEMON_PORT, /**< Port of communication between scanner and server */ + MS_SCAN_DAEMON_PORT = 0, /**< Port of communication between scanner and server */ MS_SCANNER_PORT, /**< Directory Scanner */ MS_DB_UPDATE_PORT, /**< Media DB Update */ MS_THUMB_CREATOR_PORT, /**< Create thumbnail */ @@ -47,9 +45,6 @@ typedef enum { typedef enum { MS_MSG_DB_UPDATE = 0, /**< Media DB Update */ - MS_MSG_DB_UPDATE_BATCH_START, /**< Start of media DB update batch */ - MS_MSG_DB_UPDATE_BATCH, /**< Perform of media DB update batch */ - MS_MSG_DB_UPDATE_BATCH_END, /**< End of media DB update batch */ MS_MSG_DIRECTORY_SCANNING, /**< Non recursive Directory Scan and Media DB Update*/ MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE,/**< Recursive Directory Scan and Media DB Update*/ MS_MSG_BULK_INSERT, /**< Request bulk insert */ diff --git a/lib/include/media-util-db.h b/lib/include/media-util-db.h index 00727f6..129e15d 100755 --- a/lib/include/media-util-db.h +++ b/lib/include/media-util-db.h @@ -38,14 +38,6 @@ int media_db_request_update_db(const char *query_str, uid_t uid); int media_db_update_db_direct(const char *query_str, uid_t uid); -int media_db_request_update_db_batch_start(const char *query_str, uid_t uid); - -int media_db_request_update_db_batch(const char *query_str, uid_t uid); - -int media_db_request_update_db_batch_end(const char *query_str, uid_t uid); - -int media_db_request_update_db_batch_clear(void); - int media_db_check_integrity(sqlite3 *handle); int media_db_get_result(sqlite3 *handle, char *sql_str, sqlite3_stmt **stmt); diff --git a/lib/include/media-util-internal.h b/lib/include/media-util-internal.h index 119ae69..3b2f115 100755 --- a/lib/include/media-util-internal.h +++ b/lib/include/media-util-internal.h @@ -35,8 +35,5 @@ #define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n); int media_db_update_db(sqlite3 *handle, const char *query_str); -int media_db_update_db_batch_start(const char *query_str); -int media_db_update_db_batch(const char *query_str); -int media_db_update_db_batch_end(sqlite3 *handle, const char *query_str); #endif /*_MEDIA_UTIL_INTERNAL_H_*/ diff --git a/lib/media-util-db.c b/lib/media-util-db.c index a3b877c..8f5ec59 100755 --- a/lib/media-util-db.c +++ b/lib/media-util-db.c @@ -51,25 +51,8 @@ const char* (*icu_uloc_getDefault)(void); static void *funcHandle = NULL; -static __thread GArray *sql_list = NULL; - static int __media_db_request_recovery(uid_t uid); -static void __media_db_destroy_sql_list() -{ - if (sql_list != NULL) { - while (sql_list->len != 0) { - char *sql = g_array_index(sql_list, char *, 0); - g_array_remove_index(sql_list, 0); - - MS_SAFE_FREE(sql); - } - - g_array_unref(sql_list); - sql_list = NULL; - } -} - static int __media_db_busy_handler(void *pData, int count) { usleep(50000); @@ -333,112 +316,6 @@ RETRY: return ret; } -static __thread int g_tcp_client_sock = -1; - -static int __media_db_get_client_tcp_sock() -{ - return g_tcp_client_sock; -} - -static int __media_db_prepare_tcp_client_socket() -{ - int ret = MS_MEDIA_ERR_NONE; - int sockfd = -1; - struct sockaddr_un serv_addr; - - /*Create TCP Socket*/ - ret = ms_ipc_create_client_socket(MS_TIMEOUT_SEC_10, &sockfd); - MSAPI_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); - - /*Set server Address*/ - memset(&serv_addr, 0, sizeof(serv_addr)); - serv_addr.sun_family = AF_UNIX; - SAFE_STRLCPY(serv_addr.sun_path, tzplatform_mkpath(TZ_SYS_RUN, MEDIA_IPC_PATH[MS_DB_BATCH_UPDATE_PORT]), sizeof(serv_addr.sun_path)); - - /* Connecting to the media db server */ - if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) { - MSAPI_DBG_STRERROR("connect error"); - close(sockfd); - return MS_MEDIA_ERR_SOCKET_CONN; - } - - g_tcp_client_sock = sockfd; - - MSAPI_DBG("Connected successfully"); - - return 0; -} - -static int __media_db_close_tcp_client_socket() -{ - if (g_tcp_client_sock != -1) { - if (close(g_tcp_client_sock) < 0) { - MSAPI_DBG_STRERROR("socket close failed"); - return MS_MEDIA_ERR_SOCKET_INTERNAL; - } - g_tcp_client_sock = -1; - } - - return MS_MEDIA_ERR_NONE; -} - -static int __media_db_request_batch_update(ms_msg_type_e msg_type, const char *request_msg, uid_t uid) -{ - int ret = MS_MEDIA_ERR_NONE; - int request_msg_size = 0; - int sockfd = -1; - - if (!MS_STRING_VALID(request_msg)) { - MSAPI_DBG_ERR("invalid query"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - request_msg_size = strlen(request_msg); - if (request_msg_size >= MAX_MSG_SIZE) { - MSAPI_DBG_ERR("Too long query[%d] limit[%d]", request_msg_size, MAX_MSG_SIZE); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - MSAPI_DBG_SLOG("querysize[%d] query[%s]", request_msg_size, request_msg); - ms_comm_msg_s send_msg; - memset((void *)&send_msg, 0, sizeof(ms_comm_msg_s)); - - send_msg.msg_type = msg_type; - send_msg.uid = uid; - SAFE_STRLCPY(send_msg.msg, request_msg, sizeof(send_msg.msg)); - - sockfd = __media_db_get_client_tcp_sock(); - MSAPI_RETV_IF(sockfd <= 0, MS_MEDIA_ERR_SOCKET_CONN); - - /* Send request */ - if (send(sockfd, &send_msg, sizeof(send_msg), 0) != sizeof(send_msg)) { - MSAPI_DBG_STRERROR("send failed"); - return MS_MEDIA_ERR_SOCKET_SEND; - } - - /*Receive Response*/ - int recv_msg_size = -1; - int recv_msg = -1; - if ((recv_msg_size = recv(sockfd, &recv_msg, sizeof(recv_msg), 0)) < 0) { - MSAPI_DBG_ERR("recv failed : [%d]", sockfd); - if (errno == EWOULDBLOCK) { - MSAPI_DBG_ERR("Timeout. Can't try any more"); - return MS_MEDIA_ERR_SOCKET_RECEIVE_TIMEOUT; - } else { - MSAPI_DBG_STRERROR("recv failed"); - return MS_MEDIA_ERR_SOCKET_RECEIVE; - } - } - - MSAPI_DBG("RECEIVE OK [%d]", recv_msg); - ret = recv_msg; - - if (ret != MS_MEDIA_ERR_NONE) - MSAPI_DBG_ERR("batch updated[%d] failed, error [%d]", msg_type, ret); - - return ret; -} - #define RETRY_CNT 9 #define SLEEP_TIME 1000 * 1000 static int _media_db_update_directly(sqlite3 *db_handle, const char *sql_str) @@ -579,62 +456,6 @@ int media_db_update_db_direct(const char *query_str, uid_t uid) return ret; } -int media_db_request_update_db_batch_start(const char *query_str, uid_t uid) -{ - int ret = MS_MEDIA_ERR_NONE; - - MSAPI_DBG_FUNC(); - - MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query"); - - ret = __media_db_prepare_tcp_client_socket(); - if (ret != MS_MEDIA_ERR_NONE) { - MSAPI_DBG_ERR("__media_db_prepare_tcp_client_socket failed : %d", ret); - __media_db_close_tcp_client_socket(); - return ret; - } - - ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH_START, query_str, uid); - if (ret != MS_MEDIA_ERR_NONE) - __media_db_close_tcp_client_socket(); - - return ret; -} - -int media_db_request_update_db_batch(const char *query_str, uid_t uid) -{ - int ret = MS_MEDIA_ERR_NONE; - - MSAPI_DBG_FUNC(); - - MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query"); - - ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH, query_str, uid); - if (ret != MS_MEDIA_ERR_NONE) - __media_db_close_tcp_client_socket(); - - return ret; -} - -int media_db_request_update_db_batch_end(const char *query_str, uid_t uid) -{ - int ret = MS_MEDIA_ERR_NONE; - - MSAPI_DBG_FUNC(); - - if (!MS_STRING_VALID(query_str)) { - MSAPI_DBG_ERR("Invalid Query"); - __media_db_close_tcp_client_socket(); - return ret; - } - - ret = __media_db_request_batch_update(MS_MSG_DB_UPDATE_BATCH_END, query_str, uid); - - __media_db_close_tcp_client_socket(); - - return ret; -} - int media_db_update_db(sqlite3 *handle, const char *query_str) { int ret = MS_MEDIA_ERR_NONE; @@ -647,119 +468,6 @@ int media_db_update_db(sqlite3 *handle, const char *query_str) return ret; } -int media_db_update_db_batch_start(const char *query_str) -{ - int ret = MS_MEDIA_ERR_NONE; -#if 0 - char *query = NULL; - - MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query"); -#endif - if (sql_list != NULL) { - MSAPI_DBG_ERR("sql_list is already allocated"); - ret = MS_MEDIA_ERR_DB_SERVER_BUSY_FAIL; - } else { - sql_list = g_array_new(FALSE, FALSE, sizeof(char*)); - MSAPI_RETVM_IF(sql_list == NULL, MS_MEDIA_ERR_OUT_OF_MEMORY, "Out of memory"); -#if 0 - query = g_strdup(query_str); - if (MS_STRING_VALID(query)) { - g_array_append_val(sql_list, query); - } else { - MSAPI_DBG_ERR("query is null"); - __media_db_destroy_sql_list(); - ret = MS_MEDIA_ERR_OUT_OF_MEMORY; - } -#endif - } - - return ret; -} - -int media_db_update_db_batch(const char *query_str) -{ - int ret = MS_MEDIA_ERR_NONE; - char *query = NULL; - - MSAPI_RETVM_IF(!MS_STRING_VALID(query_str), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid Query"); - - if (sql_list) { - query = g_strdup(query_str); - if (MS_STRING_VALID(query)) { - g_array_append_val(sql_list, query); - } else { - MSAPI_DBG_ERR("query is null"); - ret = MS_MEDIA_ERR_OUT_OF_MEMORY; - } - } - - return ret; -} - -int media_db_update_db_batch_end(sqlite3 *handle, const char *query_str) -{ - int ret = MS_MEDIA_ERR_NONE; -#if 0 - char *query = NULL; -#endif - /* Unused (!MS_STRING_VALID(query_str)) */ - if (handle == NULL) { - __media_db_destroy_sql_list(); - MSAPI_DBG_ERR("Handle is NULL"); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } - - if (sql_list) { -#if 0 - query = g_strdup(query_str); - if (MS_STRING_VALID(query)) { - g_array_append_val(sql_list, query); - } else { - __media_db_destroy_sql_list(); - MSAPI_DBG_ERR("query is null"); - return MS_MEDIA_ERR_OUT_OF_MEMORY; - } -#endif - while (sql_list->len != 0) { - char *current_sql = NULL; - - current_sql = g_array_index(sql_list, char *, 0); - g_array_remove_index(sql_list, 0); - - if (MS_STRING_VALID(current_sql)) { - ret = _media_db_update_directly(handle, current_sql); - if (ret < 0) { -#if 0 - if (strncmp(current_sql, BATCH_START, strlen(BATCH_START)) == 0 || strncmp(current_sql, BATCH_END, strlen(BATCH_END)) == 0) { - MSAPI_DBG_ERR("Query failed : %s", current_sql); - MS_SAFE_FREE(current_sql); - break; - } else { - MSAPI_DBG_ERR("Query failed : %s, but keep going to run remaining queries", current_sql); - } -#endif - MSAPI_DBG_ERR("Query failed : %s, but keep going to run remaining queries", current_sql); - } - } - - MS_SAFE_FREE(current_sql); - } - } - - __media_db_destroy_sql_list(); - - return MS_MEDIA_ERR_NONE; -} - -int media_db_request_update_db_batch_clear(void) -{ - int ret = MS_MEDIA_ERR_NONE; - - __media_db_destroy_sql_list(); - - return ret; -} - static int __media_db_request_recovery(uid_t uid) { int ret = MS_MEDIA_ERR_NONE; diff --git a/lib/media-util-ipc.c b/lib/media-util-ipc.c index 2021c64..e52f2fa 100755 --- a/lib/media-util-ipc.c +++ b/lib/media-util-ipc.c @@ -29,7 +29,6 @@ #include "media-util-internal.h" char MEDIA_IPC_PATH[][70] = { - {"media-server/media_ipc_dbbatchupdate.socket"}, {"media-server/media_ipc_scandaemon.socket"}, {"media-server/media_ipc_scanner.socket"}, {"media-server/media_ipc_dbupdate.socket"}, diff --git a/src/server/include/media-server-socket.h b/src/server/include/media-server-socket.h index b4b06be..a26fb11 100755 --- a/src/server/include/media-server-socket.h +++ b/src/server/include/media-server-socket.h @@ -28,7 +28,6 @@ gboolean ms_read_socket(gpointer user_data); gboolean ms_read_db_tcp_socket(GIOChannel *src, GIOCondition condition, gpointer data); -gboolean ms_read_db_tcp_batch_socket(GIOChannel *src, GIOCondition condition, gpointer data); int ms_send_scan_request(ms_comm_msg_s *send_msg, int client_sock); int ms_send_storage_scan_request(const char *root_path, const char *storage_id, ms_dir_scan_type_t scan_type, uid_t uid); gboolean ms_receive_message_from_scanner(GIOChannel *src, GIOCondition condition, gpointer data); diff --git a/src/server/media-server-db.c b/src/server/media-server-db.c index 6774b47..3ea924c 100755 --- a/src/server/media-server-db.c +++ b/src/server/media-server-db.c @@ -44,12 +44,9 @@ gboolean ms_db_get_thread_status(void) gboolean ms_db_thread(void *data) { int sockfd = -1; - int tcp_sockfd = -1; int ret = MS_MEDIA_ERR_NONE; GSource *source = NULL; GIOChannel *channel = NULL; - GSource *tcp_source = NULL; - GIOChannel *tcp_channel = NULL; GMainContext *context = NULL; sqlite3 *db_handle = NULL; @@ -66,18 +63,9 @@ gboolean ms_db_thread(void *data) return FALSE; } - /* Create TCP Socket for batch query*/ - ret = ms_ipc_create_server_socket(MS_DB_BATCH_UPDATE_PORT, &tcp_sockfd); - if (ret != MS_MEDIA_ERR_NONE) { - close(sockfd); - MS_DBG_ERR("Failed to create socket"); - return FALSE; - } - context = g_main_context_new(); /*Init main loop*/ g_db_mainloop = g_main_loop_new(context, FALSE); - //context = g_main_loop_get_context(g_db_mainloop); /* Create new channel to watch UDP socket */ channel = g_io_channel_unix_new(sockfd); @@ -87,14 +75,6 @@ gboolean ms_db_thread(void *data) g_source_set_callback(source, (GSourceFunc)ms_read_db_tcp_socket, db_handle, NULL); g_source_attach(source, context); - /* Create new channel to watch TCP socket */ - tcp_channel = g_io_channel_unix_new(tcp_sockfd); - tcp_source = g_io_create_watch(tcp_channel, G_IO_IN); - - /* Set callback to be called when socket is readable */ - g_source_set_callback(tcp_source, (GSourceFunc)ms_read_db_tcp_batch_socket, db_handle, NULL); - g_source_attach(tcp_source, context); - g_main_context_push_thread_default(context); MS_DBG_INFO("Media Server DB thread is running"); @@ -110,7 +90,6 @@ gboolean ms_db_thread(void *data) /*close socket*/ close(sockfd); - close(tcp_sockfd); g_main_loop_unref(g_db_mainloop); diff --git a/src/server/media-server-socket.c b/src/server/media-server-socket.c index 12ec606..b0fde54 100755 --- a/src/server/media-server-socket.c +++ b/src/server/media-server-socket.c @@ -37,10 +37,8 @@ #include "media-server-socket.h" extern GAsyncQueue *scan_queue; -GAsyncQueue* ret_queue; GArray *owner_list; extern GMutex scanner_mutex; -gint cur_running_task; int ms_req_num; extern bool power_off; @@ -652,197 +650,6 @@ ERROR: return TRUE; } - -void _ms_process_tcp_message(gpointer data, gpointer user_data) -{ - int ret = MS_MEDIA_ERR_NONE; - char * sql_query = NULL; - ms_comm_msg_s recv_msg; - int client_sock = GPOINTER_TO_INT(data); - int send_msg = MS_MEDIA_ERR_NONE; - ms_peer_credentials creds; - - while (1) { - if (power_off) { - MS_DBG_WARN("in the power off sequence"); - break; - } - memset((void *)&recv_msg, 0, sizeof(ms_comm_msg_s)); - memset(&creds, 0, sizeof(creds)); - - ret = ms_cynara_receive_untrusted_message(client_sock, &recv_msg, &creds); - if (ret != MS_MEDIA_ERR_NONE) { - media_db_request_update_db_batch_clear(); - MS_DBG_ERR("ms_ipc_receive_message_tcp failed [%d]", ret); - send_msg = ret; - goto ERROR; - } - - if (ms_cynara_check(&creds, CONTENT_WRITE_PRIVILEGE) != MS_MEDIA_ERR_NONE) { - media_db_request_update_db_batch_clear(); - MS_SAFE_FREE(creds.smack); - MS_SAFE_FREE(creds.uid); - MS_DBG_ERR("Permission denied"); - send_msg = MS_MEDIA_ERR_PERMISSION_DENIED; - goto ERROR; - } - - MS_SAFE_FREE(creds.smack); - MS_SAFE_FREE(creds.uid); - - if (!MS_STRING_VALID(recv_msg.msg)) { - send_msg = MS_MEDIA_ERR_INVALID_PARAMETER; - goto ERROR; - } - - sql_query = g_strdup(recv_msg.msg); - if (sql_query != NULL) { - if (recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_START) { - ret = media_db_update_db_batch_start(sql_query); - } else if (recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_END) { - sqlite3 *db_handle = NULL; - if (media_db_connect(&db_handle, recv_msg.uid, true) != MS_MEDIA_ERR_NONE) { - MS_DBG_ERR("Failed to connect DB"); - send_msg = MS_MEDIA_ERR_DB_CONNECT_FAIL; - media_db_request_update_db_batch_clear(); - MS_SAFE_FREE(sql_query); - goto ERROR; - } - ret = media_db_update_db_batch_end(db_handle, sql_query); - - /* Disconnect DB*/ - media_db_disconnect(db_handle); - - } else if (recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH) { - ret = media_db_update_db_batch(sql_query); - } - - MS_SAFE_FREE(sql_query); - send_msg = ret; - - if (write(client_sock, &send_msg, sizeof(send_msg)) != sizeof(send_msg)) - MS_DBG_STRERROR("send failed"); - - if (recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_END) { - MS_DBG_WARN("Batch job is successfull!client sockfd [%d]", client_sock); - break; - } - - if (ret != MS_MEDIA_ERR_NONE && recv_msg.msg_type == MS_MSG_DB_UPDATE_BATCH_START) { - MS_DBG_ERR("Batch job start is failed!client sockfd [%d]", client_sock); - break; - } - } else { - MS_DBG_ERR("MS_MALLOC failed"); - media_db_request_update_db_batch_clear(); - /* send error to client */ - send_msg = MS_MEDIA_ERR_SOCKET_RECEIVE; - goto ERROR; - } - } - - if (close(client_sock) < 0) - MS_DBG_STRERROR("close failed"); - - if (g_atomic_int_dec_and_test(&cur_running_task)) - MS_DBG_INFO("There is no running task"); - - return; - -ERROR: - - /* send error to client */ - if (write(client_sock, &send_msg, sizeof(send_msg)) != sizeof(send_msg)) - MS_DBG_STRERROR("send failed"); - else - MS_DBG("Sent successfully"); - - if (close(client_sock) < 0) - MS_DBG_STRERROR("close failed"); - - if (g_atomic_int_dec_and_test(&cur_running_task)) - MS_DBG_INFO("There is no running task"); - - return; -} - -gboolean ms_read_db_tcp_batch_socket(GIOChannel *src, GIOCondition condition, gpointer data) -{ -#define MAX_THREAD_NUM 4 - - static GThreadPool *gtp = NULL; - GError *error = NULL; - int ret = MS_MEDIA_ERR_NONE; - int res = MS_MEDIA_ERR_NONE; - int sock = -1; - int client_sock = -1; - - sock = g_io_channel_unix_get_fd(src); - if (sock < 0) { - MS_DBG_ERR("sock fd is invalid!"); - return TRUE; - } - - /* get client socket fd */ - ret = ms_ipc_accept_client_tcp(sock, &client_sock); - if (ret != MS_MEDIA_ERR_NONE) { - media_db_request_update_db_batch_clear(); - return TRUE; - } - - MS_DBG_SLOG("Client[%d] is accepted", client_sock); - - if (gtp == NULL) { - MS_DBG_SLOG("Create New Thread Pool %d", client_sock); - gtp = g_thread_pool_new((GFunc)_ms_process_tcp_message, NULL, MAX_THREAD_NUM, TRUE, &error); - if (error != NULL) { - res = MS_MEDIA_ERR_OUT_OF_MEMORY; - goto ERROR; - } - } - - /*check number of running thread */ - if (g_atomic_int_get(&cur_running_task) < MAX_THREAD_NUM) { - MS_DBG_SLOG("CURRENT RUNNING TASK %d", cur_running_task); - g_atomic_int_inc(&cur_running_task); - g_thread_pool_push(gtp, GINT_TO_POINTER(client_sock), &error); - - if (error != NULL) { - res = MS_MEDIA_ERR_INTERNAL; - goto ERROR; - } - } else { - /* all thread is working, return busy error */ - res = MS_MEDIA_ERR_DB_BATCH_UPDATE_BUSY; - goto ERROR; - } - - return TRUE; - -ERROR: - { - int send_msg = MS_MEDIA_ERR_NONE; - - if (error != NULL) { - MS_DBG_SLOG("g_thread_pool_push failed [%s]", error->message); - g_error_free(error); - error = NULL; - } - - /* send error to clinet*/ - send_msg = res; - if (write(client_sock, &send_msg, sizeof(send_msg)) != sizeof(send_msg)) - MS_DBG_STRERROR("send failed"); - else - MS_DBG("Sent successfully"); - - if (close(client_sock) < 0) - MS_DBG_STRERROR("close failed"); - } - - return TRUE; -} - gboolean ms_receive_message_from_scanner(GIOChannel *src, GIOCondition condition, gpointer data) { ms_comm_msg_s recv_msg; -- 2.7.4