增加HTTP Post上传配置接口,支持主从双机备份与同步(冷备)
This commit is contained in:
@@ -21,6 +21,38 @@
|
||||
|
||||
#include "doris_client_http.h"
|
||||
|
||||
void easy_string_destroy(struct easy_string *estr)
|
||||
{
|
||||
if(estr->buff != NULL)
|
||||
{
|
||||
free(estr->buff);
|
||||
estr->buff = NULL;
|
||||
estr->len = estr->size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void easy_string_savedata(struct easy_string *estr, const char *data, size_t len)
|
||||
{
|
||||
if(estr->size-estr->len < len+1)
|
||||
{
|
||||
estr->size += len*4+1;
|
||||
estr->buff = (char*)realloc(estr->buff, estr->size);
|
||||
}
|
||||
|
||||
memcpy(estr->buff+estr->len, data, len);
|
||||
estr->len += len;
|
||||
estr->buff[estr->len]='\0';
|
||||
}
|
||||
|
||||
static inline void drsclient_set_sockopt_keepalive(int sd, int keepidle, int keepintvl, int keepcnt)
|
||||
{
|
||||
int keepalive = 1;
|
||||
setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (void*)&keepalive, sizeof(keepalive));
|
||||
setsockopt(sd, SOL_TCP, TCP_KEEPIDLE, (void*)&keepidle, sizeof(keepidle));
|
||||
setsockopt(sd, SOL_TCP, TCP_KEEPINTVL, (void*)&keepintvl, sizeof(keepintvl));
|
||||
setsockopt(sd, SOL_TCP, TCP_KEEPCNT, (void*)&keepcnt, sizeof(keepcnt));
|
||||
}
|
||||
|
||||
int32_t param_get_connected_hosts(struct doris_http_parameter *param)
|
||||
{
|
||||
return param->connected_hosts;
|
||||
@@ -199,6 +231,7 @@ static void client_bufferevent_error_cb(struct bufferevent *bev, short event, vo
|
||||
conhash_insert_dest_host(balance);
|
||||
assert(balance->param->connected_hosts > 0);
|
||||
assert(balance->param->failed_hosts >= 0);
|
||||
drsclient_set_sockopt_keepalive(bufferevent_getfd(bev), 10, 5, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -303,6 +336,24 @@ static int32_t doris_launch_group_connection(struct doris_http_parameter *param,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void doris_http_parameter_destroy(struct doris_http_parameter *param)
|
||||
{
|
||||
for(u_int32_t i=0; i<param->ipgroup.dstaddr_num; i++) //<2F><><EFBFBD><EFBFBD>
|
||||
{
|
||||
if(evtimer_pending(¶m->balance[i].timer_detect, NULL))
|
||||
{
|
||||
evtimer_del(¶m->balance[i].timer_detect);
|
||||
}
|
||||
if(param->balance[i].bev != NULL)
|
||||
{
|
||||
bufferevent_free(param->balance[i].bev);
|
||||
}
|
||||
}
|
||||
conhash_instance_free(param->conhash);
|
||||
free(param->ipgroup.dstaddrs);
|
||||
free(param);
|
||||
}
|
||||
|
||||
struct doris_http_parameter *doris_http_parameter_new(const char* profile_path, const char* section, struct event_base* evbase, void *runtime_log)
|
||||
{
|
||||
struct doris_http_parameter *param;
|
||||
@@ -352,6 +403,38 @@ struct doris_http_parameter *doris_http_parameter_new(const char* profile_path,
|
||||
return param;
|
||||
}
|
||||
|
||||
void doris_http_instance_destroy(struct doris_http_instance *instance)
|
||||
{
|
||||
map<u_int32_t, doris_curl_multihd*>::iterator iter;
|
||||
struct doris_curl_multihd *multihd;
|
||||
CURLMsg *msg;
|
||||
int msgs_left;
|
||||
struct doris_http_ctx *ctx;
|
||||
CURL *easy;
|
||||
|
||||
for(iter=instance->server_hosts->begin(); iter!=instance->server_hosts->end(); )
|
||||
{
|
||||
multihd = iter->second;
|
||||
|
||||
while((msg = curl_multi_info_read(multihd->multi_hd, &msgs_left)))
|
||||
{
|
||||
easy = msg->easy_handle;
|
||||
curl_easy_getinfo(easy, CURLINFO_PRIVATE, &ctx);
|
||||
curl_multi_remove_handle(multihd->multi_hd, easy);
|
||||
curl_easy_cleanup(easy);
|
||||
ctx->curl = NULL;
|
||||
ctx->transfering = 0;
|
||||
ctx->res = CURLE_ABORTED_BY_CALLBACK;
|
||||
ctx->res_code = 0;
|
||||
ctx->cb.transfer_done_cb(ctx->res, 0, ctx->error, ctx->cb.userp);
|
||||
}
|
||||
curl_multi_cleanup(multihd->multi_hd);
|
||||
|
||||
instance->server_hosts->erase(iter++);
|
||||
}
|
||||
free(instance);
|
||||
}
|
||||
|
||||
struct doris_http_instance *doris_http_instance_new(struct doris_http_parameter *param, struct event_base* evbase, void *runtimelog)
|
||||
{
|
||||
struct doris_http_instance *instance;
|
||||
|
||||
Reference in New Issue
Block a user