重构 hos
This commit is contained in:
@@ -20,7 +20,7 @@ add_subdirectory(src)
|
|||||||
|
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libhos-client-cpp.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libhos-client-cpp.so DESTINATION ${CMAKE_INSTALL_PREFIX}/lib COMPONENT LIBRARIES)
|
||||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/hos_client.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include COMPONENT HEADER)
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/hos_client.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include COMPONENT HEADER)
|
||||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/hos.conf DESTINATION /etc/ld.so.conf.d COMPONENT PROFILE)
|
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/conf/hos.conf DESTINATION /etc/ld.so.conf.d COMPONENT PROFILE)
|
||||||
#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libhos-client-cpp.a DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT PROFILE)
|
#install(FILES ${CMAKE_CURRENT_BINARY_DIR}/src/libhos-client-cpp.a DESTINATION ${CMAKE_INSTALL_PREFIX} COMPONENT PROFILE)
|
||||||
|
|
||||||
include(Package)
|
include(Package)
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
/usr/local/lib64/
|
|
||||||
1265
src/hos_client.cpp
1265
src/hos_client.cpp
File diff suppressed because it is too large
Load Diff
120
src/hos_client.h
120
src/hos_client.h
@@ -1,13 +1,18 @@
|
|||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
> File Name: hos_client_api.h
|
> File Name: hos_client.h
|
||||||
> Author: pxz
|
> Author: pxz
|
||||||
> Created Time: Thu 10 Sep 2020 03:13:59 PM CST
|
> Created Time: Thu 10 Sep 2020 03:13:59 PM CST
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
#ifndef __HOS_CLIENT_INIT__
|
#ifndef __HOS_CLIENT_INIT__
|
||||||
#define __HOS_CLIENT_INIT__
|
#define __HOS_CLIENT_INIT__
|
||||||
|
|
||||||
/*hos client 句柄*/
|
/*hos instance */
|
||||||
typedef struct hos_client_handle_s* hos_client_handle;
|
typedef struct hos_instance_s{
|
||||||
|
bool result;
|
||||||
|
int error_code;
|
||||||
|
char error_message[1024];
|
||||||
|
const char *hos_url_prefix;
|
||||||
|
}* hos_instance;
|
||||||
|
|
||||||
#define HOS_CLIENT_OK 0
|
#define HOS_CLIENT_OK 0
|
||||||
|
|
||||||
@@ -20,10 +25,13 @@ typedef struct hos_client_handle_s* hos_client_handle;
|
|||||||
enum hoserrors
|
enum hoserrors
|
||||||
{
|
{
|
||||||
HOS_PARAMETER_ERROR = -1,
|
HOS_PARAMETER_ERROR = -1,
|
||||||
HOS_FILE_NOT_EXITS = -2,
|
HOS_FILE_NOT_EXIST = -2,
|
||||||
HOS_HASH_NOT_FIND = -3,
|
HOS_HASH_NOT_FIND = -3,
|
||||||
HOS_FD_NOT_ENOUGH = -4,
|
HOS_FD_NOT_ENOUGH = -4,
|
||||||
HOS_SEND_FAILED = -5,
|
HOS_SEND_FAILED = -5,
|
||||||
|
HOS_RUNTIME_LOG_FAILED = -6,
|
||||||
|
HOS_CONF_ERROR = -7,
|
||||||
|
HOS_BUCKET_NOT_EXIST = -8,
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,61 +83,42 @@ enum s3errors
|
|||||||
|
|
||||||
typedef void (*put_finished_callback)(bool, const char *, const char *, const char *, void *);
|
typedef void (*put_finished_callback)(bool, const char *, const char *, const char *, void *);
|
||||||
|
|
||||||
/*************************************************************************************
|
/*//FIXME 改为static,不再对外提供
|
||||||
* 函数名: hos_client_handle
|
*************************************************************************************
|
||||||
|
* 函数名: hos_instance
|
||||||
* 参数: const char *serverip 目的地址,如"192.168.44.12"
|
* 参数: const char *serverip 目的地址,如"192.168.44.12"
|
||||||
* size_t port 端口号
|
* size_t port 端口号
|
||||||
* const char *accesskeyid AWS access key ID,如”default“
|
* const char *accesskeyid AWS access key ID,如"default"
|
||||||
* const char *secretkey AWS secret key,如”default“
|
* const char *secretkey AWS secret key,如"default"
|
||||||
|
* siez_t pool_size 线程池大小
|
||||||
* size_t thread_sum 线程总数
|
* size_t thread_sum 线程总数
|
||||||
* 返回值: 成功返回一个非空句柄,失败返回NULL。
|
* 返回值: 成功返回一个实例,失败返回NULL。
|
||||||
*************************************************************************************/
|
*************************************************************************************
|
||||||
hos_client_handle hos_client_create(const char *serverip, size_t port, const char *accesskeyid, const char *secretkey, size_t pool_size);
|
hos_instance hos_client_create(const char *serverip, size_t port, const char *accesskeyid, const char *secretkey, size_t pool_size);
|
||||||
|
*/
|
||||||
|
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_get_error_msg
|
* 函数名: hos_init_instance
|
||||||
* 返回值: hos_client_create创建失败的原因
|
* 输入参数: conf_path 配置文件路径
|
||||||
|
* thread_num 线程数
|
||||||
|
* 返回值: hos 实例创建结果
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
char *hos_get_error_msg();
|
hos_instance hos_init_instance(const char *conf_path, const char *module, size_t thread_num, const char *bucket);
|
||||||
/*************************************************************************************
|
|
||||||
* 函数名: hos_get_error_num
|
|
||||||
* 返回值: hos_client_create创建失败的错误码
|
|
||||||
*************************************************************************************/
|
|
||||||
size_t hos_get_error_num();
|
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_create_bucket
|
* 函数名: hos_create_bucket
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
* 参数: const char *bucket 桶名称
|
||||||
* const char * bucket 桶名称
|
* 返回值: bool 成功返回true,失败返回false
|
||||||
* 返回值: int 成功返回0,S3错误返回s3errors错误码,hos client错误返回hoserrors错误码
|
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
bool hos_verify_bucket(hos_client_handle handle, const char *bucket);
|
//bool hos_verify_bucket(const char *bucket);
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_create_bucket
|
* 函数名: hos_create_bucket
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
* 参数: const char * bucket 桶名称
|
||||||
* const char * bucket 桶名称
|
* 返回值: int 成功返回0,S3错误返回s3errors错误码,hos client错误返回hoserrors错误码
|
||||||
* 返回值: int 成功返回0,S3错误返回s3errors错误码,hos client错误返回hoserrors错误码
|
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
int hos_create_bucket(hos_client_handle handle, const char *bucket);
|
int hos_create_bucket(hos_instance instance, const char *bucket);
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_set_cache_size
|
* 函数名: hos_upload_file
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
* 参数: hos_instance instance 非空句柄
|
||||||
* size_t cache_size append 模式每次追加的buffer大小
|
|
||||||
*************************************************************************************/
|
|
||||||
void hos_set_cache_size(hos_client_handle handle, size_t cache_size);
|
|
||||||
/*************************************************************************************
|
|
||||||
* 函数名: hos_set_cache_count
|
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
|
||||||
* size_t cache_count append 模式追加次数
|
|
||||||
*************************************************************************************/
|
|
||||||
void hos_set_cache_count(hos_client_handle handle, size_t cache_count);
|
|
||||||
/*************************************************************************************
|
|
||||||
* 函数名: hos_set_thread_sum
|
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
|
||||||
* size_t thread_sum append 模式追加次数
|
|
||||||
*************************************************************************************/
|
|
||||||
void hos_set_thread_sum(hos_client_handle handle, size_t thread_sum);
|
|
||||||
/*************************************************************************************
|
|
||||||
* 函数名: hos_upload_async
|
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
|
||||||
* const char * bucket 桶名称
|
* const char * bucket 桶名称
|
||||||
* const char * file_path 上传对象路径
|
* const char * file_path 上传对象路径
|
||||||
* put_finished_callback callback upload操作结束时调用的回调函数
|
* put_finished_callback callback upload操作结束时调用的回调函数
|
||||||
@@ -137,10 +126,10 @@ void hos_set_thread_sum(hos_client_handle handle, size_t thread_sum);
|
|||||||
* size_t thread_id 当前线程id
|
* size_t thread_id 当前线程id
|
||||||
* 返回值 int 成功返回0,失败返回hoserros错误码
|
* 返回值 int 成功返回0,失败返回hoserros错误码
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
int hos_upload_file(hos_client_handle handle, const char *bucket, const char *file_path, put_finished_callback callback, void* userdata, size_t thread_id);
|
int hos_upload_file(hos_instance instance, const char *bucket, const char *file_path, put_finished_callback callback, void* userdata, size_t thread_id);
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_upload_async
|
* 函数名: hos_upload_buf
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
* 参数: hos_instance instance 非空句柄
|
||||||
* const char * bucket 桶名称
|
* const char * bucket 桶名称
|
||||||
* const char * object 上传对象名称
|
* const char * object 上传对象名称
|
||||||
* const char *buf 上传的buf
|
* const char *buf 上传的buf
|
||||||
@@ -150,38 +139,28 @@ int hos_upload_file(hos_client_handle handle, const char *bucket, const char *fi
|
|||||||
* size_t thread_id 当前线程id
|
* size_t thread_id 当前线程id
|
||||||
* 返回值 int 成功返回0,失败返回hoserros错误码
|
* 返回值 int 成功返回0,失败返回hoserros错误码
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
int hos_upload_buf(hos_client_handle handle, const char *bucket, const char *object, const char *buf, size_t buf_len, put_finished_callback callback, void *userdata, size_t thread_id);
|
int hos_upload_buf(hos_instance instance, const char *bucket, const char *object, const char *buf, size_t buf_len, put_finished_callback callback, void *userdata, size_t thread_id);
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_open_fd
|
* 函数名: hos_open_fd
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
* 参数: const char * bucket 桶名称
|
||||||
* const char * bucket 桶名称
|
|
||||||
* const char * object 上传对象名称
|
* const char * object 上传对象名称
|
||||||
* put_finished_callback callback upload操作结束时调用的回调函数
|
* put_finished_callback callback upload操作结束时调用的回调函数
|
||||||
* void *data 用户自定义数据
|
* void *data 用户回调函数自定义数据
|
||||||
* size_t thread_id 线程ID
|
* size_t thread_id 线程ID
|
||||||
* int mode 模式 (FILE OR BUFFER, APPEND OR NOT)
|
* int mode 模式 (FILE OR BUFFER, APPEND OR NOT)
|
||||||
* 返回值 int 成功返回0,失败返回hoserros错误码
|
* 返回值 int 成功返回fd(fd >=3),失败返回hoserros错误码
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
int hos_open_fd(hos_client_handle handle, const char *bucket, const char *object, put_finished_callback callback, void *userdata, size_t thread_id, int mode);
|
int hos_open_fd(const char *bucket, const char *object, put_finished_callback callback, void *userdata, size_t thread_id, int mode);
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_upload_stream_async
|
* 函数名: hos_write
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
* 参数: size_t fd hos_open_fd返回的fd
|
||||||
* const char * stream 待上传的数据
|
* const char * stream 待上传的数据
|
||||||
* size_t stream 待上传的数据长度
|
* size_t stream 待上传的数据长度
|
||||||
* size_t thread_id 线程ID
|
* size_t thread_id 线程ID
|
||||||
* size_t position append模式下的每段内容编号
|
* size_t position append模式下的每段内容编号
|
||||||
* 返回值 int 成功返回0,失败返回hoserros错误码
|
* 返回值 int 成功返回0,失败返回hoserror
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id);
|
int hos_write(size_t fd, const char *stream, size_t stream_len, size_t thread_id);
|
||||||
/*************************************************************************************
|
|
||||||
* 函数名: hos_expand_fs2
|
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
|
||||||
* const char * path log 路径
|
|
||||||
* int format 0:default; 1: Json
|
|
||||||
* char *server_ip 服务IP地址
|
|
||||||
* int port 服务端口
|
|
||||||
*************************************************************************************/
|
|
||||||
void hos_expand_fs2(hos_client_handle handle, const char * path, int format, char *server_ip, int port);
|
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_close_fd
|
* 函数名: hos_close_fd
|
||||||
* 参数: size_t fd fd
|
* 参数: size_t fd fd
|
||||||
@@ -190,9 +169,8 @@ void hos_expand_fs2(hos_client_handle handle, const char * path, int format, cha
|
|||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
int hos_close_fd(size_t fd, size_t thread_id);
|
int hos_close_fd(size_t fd, size_t thread_id);
|
||||||
/*************************************************************************************
|
/*************************************************************************************
|
||||||
* 函数名: hos_client_destory
|
* 函数名: hos_shutdown_instance
|
||||||
* 参数: hos_client_handle handle 非空句柄
|
|
||||||
* 返回值 int 成功返回0,失败返回hoserros错误码
|
* 返回值 int 成功返回0,失败返回hoserros错误码
|
||||||
*************************************************************************************/
|
*************************************************************************************/
|
||||||
int hos_client_destory(hos_client_handle handle);
|
int hos_shutdown_instance();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
************************************************************************/
|
************************************************************************/
|
||||||
#include "hos_hash.h"
|
#include "hos_hash.h"
|
||||||
|
|
||||||
void add_hos_info(hos_info_t **handle, hos_info_t *input)
|
void add_fd_context(hos_fd_context_t **handle, hos_fd_context_t *input)
|
||||||
{
|
{
|
||||||
hos_info_t *value = NULL;
|
hos_fd_context_t *value = NULL;
|
||||||
HASH_FIND_INT(*handle, (int *)&input->fd, value);
|
HASH_FIND_INT(*handle, (int *)&input->fd, value);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
{
|
{
|
||||||
value = (hos_info_t *)malloc(sizeof(hos_info_t));
|
value = (hos_fd_context_t *)malloc(sizeof(hos_fd_context_t));
|
||||||
memcpy(value, input, sizeof(hos_info_t));
|
memcpy(value, input, sizeof(hos_fd_context_t));
|
||||||
value->object = (char *)calloc(1, strlen(input->object) + 1);
|
value->object = (char *)calloc(1, strlen(input->object) + 1);
|
||||||
value->bucket = (char *)calloc(1, strlen(input->bucket) + 1);
|
value->bucket = (char *)calloc(1, strlen(input->bucket) + 1);
|
||||||
memcpy(value->bucket, input->bucket, strlen(input->bucket));
|
memcpy(value->bucket, input->bucket, strlen(input->bucket));
|
||||||
@@ -22,7 +22,6 @@ void add_hos_info(hos_info_t **handle, hos_info_t *input)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
value->mode = input->mode;
|
value->mode = input->mode;
|
||||||
value->handle = input->handle;
|
|
||||||
if (value->object != NULL)
|
if (value->object != NULL)
|
||||||
{
|
{
|
||||||
free(value->object);
|
free(value->object);
|
||||||
@@ -50,16 +49,16 @@ void add_hos_info(hos_info_t **handle, hos_info_t *input)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hos_info_t *find_info_by_fd(hos_info_t *handle, size_t fd)
|
hos_fd_context_t *find_context_by_fd(hos_fd_context_t *handle, size_t fd)
|
||||||
{
|
{
|
||||||
hos_info_t *value = NULL;
|
hos_fd_context_t *value = NULL;
|
||||||
HASH_FIND_INT(handle, &fd, value);
|
HASH_FIND_INT(handle, &fd, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_info_by_fd(hos_info_t **handle, size_t fd)
|
void delete_context_by_fd(hos_fd_context_t **handle, size_t fd)
|
||||||
{
|
{
|
||||||
hos_info_t *value = NULL;
|
hos_fd_context_t *value = NULL;
|
||||||
|
|
||||||
HASH_FIND_INT(*handle, &fd, value);
|
HASH_FIND_INT(*handle, &fd, value);
|
||||||
if (value)
|
if (value)
|
||||||
@@ -79,9 +78,9 @@ void delete_info_by_fd(hos_info_t **handle, size_t fd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_all(hos_info_t **handle)
|
void delete_all(hos_fd_context_t **handle)
|
||||||
{
|
{
|
||||||
hos_info_t *current, *tmp;
|
hos_fd_context_t *current, *tmp;
|
||||||
HASH_ITER(hh, *handle, current, tmp)
|
HASH_ITER(hh, *handle, current, tmp)
|
||||||
{
|
{
|
||||||
if (current->bucket)
|
if (current->bucket)
|
||||||
|
|||||||
@@ -7,14 +7,14 @@
|
|||||||
#define __HOS_HASH_H__
|
#define __HOS_HASH_H__
|
||||||
|
|
||||||
#include <aws/core/Aws.h>
|
#include <aws/core/Aws.h>
|
||||||
#include "hos_client.h"
|
//#include "hos_client.h"
|
||||||
#include "uthash.h"
|
#include "uthash.h"
|
||||||
|
|
||||||
typedef struct hos_info_s
|
typedef struct hos_fd_context_s
|
||||||
{
|
{
|
||||||
size_t fd;
|
size_t fd;
|
||||||
int mode;
|
int mode;
|
||||||
hos_client_handle handle;
|
//hos_client_handle handle;
|
||||||
char *bucket;
|
char *bucket;
|
||||||
char *object;
|
char *object;
|
||||||
void *callback;
|
void *callback;
|
||||||
@@ -28,13 +28,13 @@ typedef struct hos_info_s
|
|||||||
#define HOS_FD_FREE 0
|
#define HOS_FD_FREE 0
|
||||||
#define HOS_FD_REGISTER 1
|
#define HOS_FD_REGISTER 1
|
||||||
#define HOS_FD_INJECT 2
|
#define HOS_FD_INJECT 2
|
||||||
size_t overtime; //计算后超时的时间
|
size_t overtime; //计算后的时间点,超过即inject fd
|
||||||
size_t timeout; //配置的超时时间,从status变成INJECT开始计时
|
size_t timeout; //配置的超时时间,从status变成INJECT开始计时
|
||||||
UT_hash_handle hh;
|
UT_hash_handle hh;
|
||||||
}hos_info_t;
|
}hos_fd_context_t;
|
||||||
|
|
||||||
void add_hos_info(hos_info_t **handle, hos_info_t *input);
|
void add_fd_context(hos_fd_context_t **handle, hos_fd_context_t *input);
|
||||||
hos_info_t *find_info_by_fd(hos_info_t *handle, size_t fd);
|
hos_fd_context_t *find_context_by_fd(hos_fd_context_t *handle, size_t fd);
|
||||||
void delete_info_by_fd(hos_info_t **handle, size_t fd);
|
void delete_context_by_fd(hos_fd_context_t **handle, size_t fd);
|
||||||
void delete_all(hos_info_t **handle);
|
void delete_all(hos_fd_context_t **handle);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user