diff --git a/example/demo/conf/default.conf b/example/demo/conf/default.conf index e9dad5d7..e7cef06c 100644 --- a/example/demo/conf/default.conf +++ b/example/demo/conf/default.conf @@ -1,10 +1,10 @@ [hos_default_conf] -hos_serverip=192.168.40.223 -hos_serverport=9099 +hos_serverip=192.168.10.1 +hos_serverport=9098 hos_accesskeyid="default" hos_secretkey="default" hos_log_path="./log/hoslog" #default -hos_log_level=30 #default +hos_log_level=10 #default hos_poolsize=0 #default hos_thread_sum=32 #default hos_cache_size=102400 #default diff --git a/example/demo/hos_write_demo.cpp b/example/demo/hos_write_demo.cpp index 7d757a7c..70b27bcf 100644 --- a/example/demo/hos_write_demo.cpp +++ b/example/demo/hos_write_demo.cpp @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) mode = BUFF_MODE | APPEND_MODE; printf("hos_write buff start ...\n"); snprintf(object, 1023, "%s_write_APPEND", file_name); - fd = hos_open_fd(bucket, object, callback, NULL, 0); + int err = hos_open_fd(bucket, object, callback, NULL, 0, &fd); if (hos_write(fd, buf, buffer.st_size) != HOS_CLIENT_OK) { printf("error: hos_write failed 1st!\n"); diff --git a/example/performance/HosClientPerformance.cpp b/example/performance/HosClientPerformance.cpp index 59366474..8341d507 100644 --- a/example/performance/HosClientPerformance.cpp +++ b/example/performance/HosClientPerformance.cpp @@ -122,6 +122,7 @@ static int upload_file(char *file, char *buff, int buff_len, thread_info_t *thre double variance = 0.00; double average = 0.00; long time = 0; + int err = 0; //写文件 //clock_gettime(CLOCK_MONOTONIC, &tstart); @@ -154,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); + err = hos_open_fd(thread_info->bucket, thread_info->object, callback, NULL, thread_info->thread_num, &fd[i]); if (hos_write(fd[i], file, 0) != HOS_CLIENT_OK) { printf("error:hos_write file:%s\n", file); @@ -210,10 +211,11 @@ static int upload_buff(char * buff, int buff_len, thread_info_t *thread_info, ch double variance = 0.00; double average = 0.00; long record[30000] = {0}; + int err = 0; if (g_mode & APPEND_MODE) { - fd[0] = hos_open_fd(thread_info->bucket, thread_info->object, callback, NULL, thread_info->thread_num); + err = hos_open_fd(thread_info->bucket, thread_info->object, callback, NULL, thread_info->thread_num, &fd[0]); for (i = 0; i < g_test_count; i++) { diff --git a/gtest/gtest_hos_close_fd.cpp b/gtest/gtest_hos_close_fd.cpp index 160bda59..7d953521 100644 --- a/gtest/gtest_hos_close_fd.cpp +++ b/gtest/gtest_hos_close_fd.cpp @@ -77,7 +77,8 @@ TEST(hos_close_fd, normal) gtest_hos_handle_init(&expect_hos_handle, thread_num); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - long fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0); + size_t fd = 0; + int err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info); @@ -121,7 +122,8 @@ TEST(hos_close_fd, paramer_error) expect_hos_handle.hos_config.thread_num=2; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - long fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0); + size_t fd = 0; + int err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info); diff --git a/gtest/gtest_hos_open_fd.cpp b/gtest/gtest_hos_open_fd.cpp index ac2ec3e6..ade49852 100644 --- a/gtest/gtest_hos_open_fd.cpp +++ b/gtest/gtest_hos_open_fd.cpp @@ -77,13 +77,15 @@ TEST(hos_open_fd, normal) gtest_hos_handle_init(&expect_hos_handle, 2); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0); + size_t fd = 0; + int err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[0]); CheckStructGHosFdContext((hos_fd_context_t *)fd, &expect_fd_info[0]); - size_t fd1 = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 1); + size_t fd1 = 0; + err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 1, &fd1); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[1]); @@ -129,8 +131,9 @@ TEST(hos_open_fd, paramer_error) gtest_hos_handle_init(&expect_hos_handle, 2); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - int fd = hos_open_fd(NULL, "object", NULL, NULL, 0); - EXPECT_EQ(fd, HOS_PARAMETER_ERROR); + size_t fd = 0; + int err = hos_open_fd(NULL, "object", NULL, NULL, 0, &fd); + EXPECT_EQ(err, HOS_PARAMETER_ERROR); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); @@ -164,8 +167,9 @@ TEST(hos_open_fd, over_threadnums) gtest_hos_handle_init(&expect_hos_handle, 2); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - int fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 3); - EXPECT_EQ(fd, HOS_PARAMETER_ERROR); + size_t fd = 0; + int err = hos_open_fd(HOS_CONF, "object", NULL, NULL, 3, &fd); + EXPECT_EQ(err, HOS_PARAMETER_ERROR); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); @@ -190,6 +194,7 @@ TEST(hos_open_fd, over_threadnums) TEST(hos_open_fd, not_init_instance) { - int fd = hos_open_fd(HOS_CONF, "object", NULL, NULL, 0); - EXPECT_EQ(fd, HOS_INSTANCE_NOT_ENABLE); + size_t fd = 0; + int err = hos_open_fd(HOS_CONF, "object", NULL, NULL, 0, &fd); + EXPECT_EQ(err, HOS_INSTANCE_NOT_ENABLE); } \ No newline at end of file diff --git a/gtest/gtest_hos_write.cpp b/gtest/gtest_hos_write.cpp index c149c4a9..a987a165 100644 --- a/gtest/gtest_hos_write.cpp +++ b/gtest/gtest_hos_write.cpp @@ -121,7 +121,8 @@ TEST(hos_write, normal) data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_write_buff_cb, (void *)"object_buff", 0); + size_t fd = 0; + int err = hos_open_fd(HOS_BUCKET, "object_buff", hos_write_buff_cb, (void *)"object_buff", 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[0]); @@ -140,7 +141,8 @@ TEST(hos_write, normal) CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd1 = hos_open_fd(HOS_BUCKET, "object_append", hos_write_append_cb, (void *)"object_append", 1); + size_t fd1 = 0; + err = hos_open_fd(HOS_BUCKET, "object_append", hos_write_append_cb, (void *)"object_append", 1, &fd1); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[1]); @@ -222,7 +224,8 @@ TEST(hos_write, bucket_not_exits) data_info = (data_info_t *)expect_hos_handle.hos_func.fs2_info.reserved; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd = hos_open_fd("bucket_not_exits", "object_buff", hos_bucket_not_exits_cb, (void *)"object_buff", 0); + size_t fd = 0; + int err = hos_open_fd("bucket_not_exits", "object_buff", hos_bucket_not_exits_cb, (void *)"object_buff", 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[0]); @@ -240,7 +243,8 @@ TEST(hos_write, bucket_not_exits) CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd1 = hos_open_fd("bucket_not_exits", "object_append", hos_bucket_not_exits_cb, (void *)"object_append", 1); + size_t fd1 = 0; + err = hos_open_fd("bucket_not_exits", "object_append", hos_bucket_not_exits_cb, (void *)"object_append", 1, &fd1); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[1]); @@ -323,7 +327,8 @@ TEST(hos_write, sync_mode) expect_hos_handle.hos_config.pool_thread_size = 0; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd = hos_open_fd(HOS_BUCKET, "object_buff", NULL, NULL, 0); + size_t fd = 0; + int err = hos_open_fd(HOS_BUCKET, "object_buff", NULL, NULL, 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[0]); @@ -338,7 +343,8 @@ TEST(hos_write, sync_mode) CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd1 = hos_open_fd(HOS_BUCKET, "object_append", NULL, NULL, 1); + size_t fd1 = 0; + err = hos_open_fd(HOS_BUCKET, "object_append", NULL, NULL, 1, &fd1); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[1]); @@ -418,7 +424,8 @@ TEST(hos_write, sync_mode_bucket_not_exits) expect_hos_handle.hos_config.pool_thread_size = 0; CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd = hos_open_fd(HOS_CONF, "object_buff", NULL, NULL, 0); + size_t fd = 0; + int err = hos_open_fd(HOS_CONF, "object_buff", NULL, NULL, 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[0]); @@ -435,7 +442,8 @@ TEST(hos_write, sync_mode_bucket_not_exits) CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - size_t fd1 = hos_open_fd(HOS_CONF, "object_append", NULL, NULL, 1); + size_t fd1 = 0; + err = hos_open_fd(HOS_CONF, "object_append", NULL, NULL, 1, &fd1); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[1]); @@ -513,7 +521,8 @@ TEST(hos_write, paramer_error) gtest_hos_handle_init(&expect_hos_handle, thread_num); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - long fd = hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, NULL, 0); + size_t fd = 0; + int err = hos_open_fd(HOS_BUCKET, "object_buff", hos_callback, NULL, 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info); @@ -597,7 +606,8 @@ TEST(hos_write, over_threadnums) gtest_hos_handle_init(&expect_hos_handle, thread_num); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); - long fd = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0); + size_t fd = 0; + int err = hos_open_fd(HOS_BUCKET, "object", NULL, NULL, 0, &fd); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info); @@ -657,7 +667,7 @@ static void *hos_function(void *ptr) size_t thread_id = reinterpret_cast(ptr); hos_instance hos_instance = NULL; int i = 0; - long fd[HOS_FD_NUMS_LOCAL] = {0}; + size_t fd[HOS_FD_NUMS_LOCAL] = {0}; char object[HOS_FD_NUMS_LOCAL][1024]; int ret = 0; hos_instance_s expect_hos_instance; @@ -665,6 +675,7 @@ static void *hos_function(void *ptr) hos_fd_context_t expect_fd_info[32][20]; int thread_num = 32; data_info_t *data_info = NULL; + int err = 0; { hos_instance = hos_get_instance(); @@ -683,8 +694,8 @@ static void *hos_function(void *ptr) for (i = 0; i < HOS_FD_NUMS_LOCAL; i++) { snprintf(object[i], 1024, "object_%lu_%d", thread_id, i); - fd[i] = hos_open_fd(HOS_BUCKET, object[i], hos_callback, object[i], 0); - EXPECT_EQ(fd[i], i + 1); + err = hos_open_fd(HOS_BUCKET, object[i], hos_callback, object[i], 0, &fd[i]); + EXPECT_EQ(err, i + 1); CheckHosInstance(hos_instance, &expect_hos_instance); CheckStructGHosHandle(&g_hos_handle, &expect_hos_handle); gtest_hos_fd_init(&expect_fd_info[thread_id][i]); diff --git a/src/hos_client.cpp b/src/hos_client.cpp index 6fc5d0f7..3266fd53 100644 --- a/src/hos_client.cpp +++ b/src/hos_client.cpp @@ -892,10 +892,11 @@ int hos_upload_buf(const char *bucket, const char *object, const char *buf, size return hos_upload_stream(bucket, object, buf, buf_len, callback, userdata, thread_id); } -long hos_open_fd(const char *bucket, const char *object, put_finished_callback callback, void *userdata, size_t thread_id) +int hos_open_fd(const char *bucket, const char *object, put_finished_callback callback, void *userdata, size_t thread_id, size_t *fd) { if (g_hos_instance.status != INSTANCE_ENABLE_STATE) { + *fd = 0; return HOS_INSTANCE_NOT_ENABLE; } if ((bucket == NULL) || (object == NULL) || (thread_id > g_hos_handle.hos_config.thread_num) || strlen(bucket) == 0 || strlen(object) == 0) @@ -903,6 +904,7 @@ long hos_open_fd(const char *bucket, const char *object, put_finished_callback c MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_FATAL, "hos_open_fd", "error: [%s] bucket:%s, obejct:%s, thread_id:%lu", g_hos_instance.hos_url_prefix, (bucket == NULL)?"null":bucket, (object == NULL)?"null":object, thread_id); + *fd = 0; return HOS_PARAMETER_ERROR; } @@ -922,7 +924,8 @@ long hos_open_fd(const char *bucket, const char *object, put_finished_callback c MESA_HANDLE_RUNTIME_LOG(g_hos_handle.log, RLOG_LV_DEBUG, "hos_open_fd", "debug: [%s] thread_id:%lu, fd:%lu", g_hos_instance.hos_url_prefix, thread_id, (long)&hos_fd); - return (long)hos_fd; + *fd = (size_t)hos_fd; + return HOS_CLIENT_OK; } int hos_write(size_t fd, const char *stream, size_t stream_len) diff --git a/src/hos_client.h b/src/hos_client.h index 21d3fb37..7e3b048a 100644 --- a/src/hos_client.h +++ b/src/hos_client.h @@ -130,7 +130,7 @@ int hos_upload_buf(const char *bucket, const char *object, const char *buf, size * int mode 模式 (FILE OR BUFFER, APPEND OR NOT) * 返回值 long 成功返回fd(fd >0),失败返回hoserros错误码 *************************************************************************************/ -long hos_open_fd(const char *bucket, const char *object, put_finished_callback callback, void *userdata, size_t thread_id); +int hos_open_fd(const char *bucket, const char *object, put_finished_callback callback, void *userdata, size_t thread_id, size_t *fd); /************************************************************************************* * 函数名: hos_write * 参数: size_t fd hos_open_fd返回的fd