summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--example/demo/hos_write_demo.cpp33
-rw-r--r--example/performance/HosClientPerformance.cpp2
-rw-r--r--src/hos_client.cpp3
3 files changed, 16 insertions, 22 deletions
diff --git a/example/demo/hos_write_demo.cpp b/example/demo/hos_write_demo.cpp
index 03fc5ad8..ca251853 100644
--- a/example/demo/hos_write_demo.cpp
+++ b/example/demo/hos_write_demo.cpp
@@ -54,8 +54,6 @@ int file_to_buffer(const char *file, char *buffer, int size)
void callback(bool result, const char *error, const char *bucket, const char *object, void *userdata)
{
- userdata_t *data = (userdata_t *)userdata;
- clock_gettime(CLOCK_MONOTONIC, data->finished);
return ;
}
@@ -80,6 +78,7 @@ int main(int argc, char *argv[])
userdata_t data = {&finished};
hos_instance hos_instance = NULL;
char object[1024];
+ const char *bucket = "hos_test_not_exit_bucket";
if (stat(file_name, &buffer) == -1)
{
@@ -99,7 +98,7 @@ int main(int argc, char *argv[])
hos_instance = hos_get_instance();
if (hos_instance->result == false)
{
- hos_instance = hos_init_instance(conf_file, module_name, 1, "hos_test_bucket");
+ hos_instance = hos_init_instance(conf_file, module_name, 1, bucket);
}
if (hos_instance->result == false)
{
@@ -109,32 +108,26 @@ int main(int argc, char *argv[])
}
printf("hos_init_instance success ... \n");
- mode = FILE_MODE;
- printf("hos_write file start ...\n");
- snprintf(object, 1023, "%s_write_file", file_name);
- fd = hos_open_fd("hos_test_bucket", object, callback, NULL, 0, mode);
- if (hos_write(fd, file_name, 0, 0) != HOS_CLIENT_OK)
+ printf("hos_upload_file start ...\n");
+ snprintf(object, 1023, "%s_upload_file", file_name);
+ if (hos_upload_file(bucket, file_name, callback, NULL, 0) != HOS_CLIENT_OK)
{
- printf("error: hos_write fialed!\n");
+ printf("error: hos_upload_file fialed!\n");
}
- hos_close_fd(fd, 0);
- printf("hos_write file end ...\n");
+ printf("hos_upload_file end ...\n");
- mode = BUFF_MODE;
- printf("hos_write buff start ...\n");
- snprintf(object, 1023, "%s_write_buff", file_name);
- fd = hos_open_fd("hos_test_bucket", object, callback, NULL, 0, mode);
- if (hos_write(fd, buf, buffer.st_size, 0) != HOS_CLIENT_OK)
+ printf("hos_upload_buff start ...\n");
+ snprintf(object, 1023, "%s_upload_buff", file_name);
+ if (hos_upload_buf(bucket, object, buf, buffer.st_size, callback, NULL, 0) != HOS_CLIENT_OK)
{
- printf("error: hos_write failed!\n");
+ printf("error: hos_upload_buff failed!\n");
}
- hos_close_fd(fd, 0);
- printf("hos_write buff end ...\n");
+ printf("hos_upload_buff end ...\n");
mode = BUFF_MODE | APPEND_MODE;
printf("hos_write buff start ...\n");
snprintf(object, 1023, "%s_write_APPEND", file_name);
- fd = hos_open_fd("hos_test_bucket", object, callback, NULL, 0, mode);
+ fd = hos_open_fd(bucket, object, callback, NULL, 0);
if (hos_write(fd, buf, buffer.st_size, 0) != HOS_CLIENT_OK)
{
printf("error: hos_write failed 1st!\n");
diff --git a/example/performance/HosClientPerformance.cpp b/example/performance/HosClientPerformance.cpp
index 08bbc945..244c16c0 100644
--- a/example/performance/HosClientPerformance.cpp
+++ b/example/performance/HosClientPerformance.cpp
@@ -155,7 +155,7 @@ static int upload_file(char *file, char *buff, int buff_len, thread_info_t *thre
for (i = 0; i < g_test_count; i++)
{
clock_gettime(CLOCK_MONOTONIC, &tstart);
- fd[i] = hos_open_fd(thread_info->bucket, thread_info->object, callback, NULL, thread_info->thread_num, g_mode);
+ fd[i] = hos_open_fd(thread_info->bucket, thread_info->object, callback, NULL, thread_info->thread_num);
if (hos_write(fd[i], file, 0, thread_info->thread_num) != HOS_CLIENT_OK)
{
printf("error:hos_write file:%s\n", file);
diff --git a/src/hos_client.cpp b/src/hos_client.cpp
index a589b26c..fb523b8c 100644
--- a/src/hos_client.cpp
+++ b/src/hos_client.cpp
@@ -46,6 +46,7 @@ extern "C"
struct hos_instance_s g_hos_instance;
hos_client_handle_t g_hos_handle;//一个进程只允许有一个g_hos_handle
static std::mutex m_client_lock;
+static std::mutex m_instance_lock;
static std::mutex m_delete_lock;
hos_fd_context_t **g_fd_context;
size_t *g_fd_info; //fd 实际从1开始,每个线程有独立的fd
@@ -1055,7 +1056,7 @@ int hos_close_fd(size_t fd, size_t thread_id)
int hos_shutdown_instance()
{
- std::lock_guard<std::mutex> locker(m_client_lock);
+ std::lock_guard<std::mutex> locker(m_instance_lock);
size_t i = 0;
hos_config_t *hos_conf = &g_hos_handle.hos_config;
hos_func_thread_t *hos_func = &g_hos_handle.hos_func;