修改并增加新接口
This commit is contained in:
115
example/single_thread.cpp_old
Normal file
115
example/single_thread.cpp_old
Normal file
@@ -0,0 +1,115 @@
|
||||
/*************************************************************************
|
||||
> File Name: single_thread.cpp
|
||||
> Author: pxz
|
||||
> Created Time: Fri 11 Sep 2020 09:52:05 AM CST
|
||||
************************************************************************/
|
||||
extern "C"
|
||||
{
|
||||
#include<stdio.h>
|
||||
#include<unistd.h>
|
||||
#include<string.h>
|
||||
#include<time.h>
|
||||
}
|
||||
#include"../src/hos_client.h"
|
||||
|
||||
#define MAX_TEST_TIMES 10
|
||||
|
||||
static size_t calc_time(struct timespec start, struct timespec end)
|
||||
{
|
||||
return (end.tv_sec * 1000 * 1000 * 1000 + end.tv_nsec -
|
||||
(start.tv_sec * 1000 * 1000 * 1000 + start.tv_nsec));
|
||||
}
|
||||
|
||||
void callback(bool result, const char *error, void *userdata)
|
||||
{
|
||||
//printf("result : %s\n", result ? "true":"false");
|
||||
if (result)
|
||||
return ;
|
||||
//printf("error: %s\n", error);
|
||||
//printf("userdata:%s\n", (char *)userdata);
|
||||
return ;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc != 3)
|
||||
{
|
||||
printf("usege: singThread [bucket name] [object name]\n");
|
||||
return -1;
|
||||
}
|
||||
struct timespec start, end;
|
||||
size_t time;
|
||||
int i = 0;
|
||||
char *bucket = argv[1];
|
||||
char *object = argv[2];
|
||||
printf("hos_client_init start ...\n");
|
||||
hos_client_handle handle = hos_client_create("http://192.168.44.12:9098/hos/", "default", "default", 4);
|
||||
if (handle == NULL)
|
||||
{
|
||||
printf("error:hos_client_handle\n");
|
||||
return -1;
|
||||
}
|
||||
printf("hos_client_init success ... \n");
|
||||
|
||||
printf("hos_create_bucket start ... \n");
|
||||
if(hos_create_bucket(handle, bucket))
|
||||
{
|
||||
printf("hos_create_bucket failed ... \n");
|
||||
return -1;
|
||||
}
|
||||
printf("hos_create_bucket success ... \n");
|
||||
|
||||
printf("hos_verify_bucket start ... \n");
|
||||
if(!hos_verify_bucket(handle, bucket))
|
||||
{
|
||||
printf("hos_verify_bucket failed ... \n");
|
||||
return -1;
|
||||
}
|
||||
printf("hos_verify_bucket success ... \n");
|
||||
|
||||
printf("hos_upload_file start ...\n");
|
||||
#if 1
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 0; i < MAX_TEST_TIMES; i++)
|
||||
{
|
||||
hos_upload_file(handle, bucket, object, callback, (void *)"this is userdata", 0);
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
time = calc_time(start, end);
|
||||
time /= MAX_TEST_TIMES;
|
||||
printf("hos_upload_file spent %llu ns\n", time);
|
||||
#if 0
|
||||
for (i = 0; i < MAX_TEST_TIMES; i++)
|
||||
{
|
||||
hos_close_fd(i, 0);
|
||||
}
|
||||
#endif
|
||||
printf("hos_upload_file end ...\n");
|
||||
#else
|
||||
|
||||
const char *buf = "this is hos_upload_buf\n";
|
||||
size_t buf_len = strlen(buf);
|
||||
printf("hos_upload_buf start ...\n");
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
for (i = 1; i <= MAX_TEST_TIMES; i++)
|
||||
{
|
||||
hos_upload_buf(handle, bucket, object, buf, buf_len, callback, (void *)"this is userdata", 0);
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &end);
|
||||
time = calc_time(start, end);
|
||||
time /= MAX_TEST_TIMES;
|
||||
printf("hos_upload_buf spent %llu ns\n", time);
|
||||
|
||||
for (i = 1; i <= MAX_TEST_TIMES; i++)
|
||||
{
|
||||
hos_close_fd(i, 0);
|
||||
}
|
||||
printf("hos_upload_buf end ...\n");
|
||||
|
||||
#endif
|
||||
printf("hos_client_close start ...\n");
|
||||
hos_client_destory(handle);
|
||||
printf("hos_client_close end ...\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user