和tfe联调完成,修复一些已知问题,增加一些日志

This commit is contained in:
崔一鸣
2018-09-19 17:06:42 +08:00
parent 6733ff0686
commit a62d9ac7f6
9 changed files with 789 additions and 46 deletions

View File

@@ -54,10 +54,12 @@ static void _wrapped_promise_success(struct promise* p, void* result)
{
return;
}
/*
if(ctx->evbase)
{
event_base_loopexit(ctx->evbase, 0);
}
*/
//promise_dettach_ctx(p);
//tfe_rpc_promise_free_ctx(ctx);
promise_success(p, result);
@@ -66,11 +68,13 @@ static void _wrapped_promise_success(struct promise* p, void* result)
static void _wrapped_promise_failed(struct promise * p, enum e_future_error error, const char * what)
{
/*
struct tfe_rpc_ctx* ctx = (struct tfe_rpc_ctx*)promise_get_ctx(p);
if(ctx->evbase)
{
event_base_loopexit(ctx->evbase, 0);
}
*/
promise_failed(p, error, what);
//promise_dettach_ctx(p);
//ctx_destroy_cb(ctx);
@@ -151,6 +155,28 @@ void connection_close_cb(struct evhttp_connection* connection, void* arg)
//printf("call connection_close_cb\n");
}
char* get_request_url(struct evhttp_uri* uri, int url_len)
{
const char* path = evhttp_uri_get_path(uri);
const char* query = evhttp_uri_get_query(uri);
char *request_url = NULL;
request_url = (char*)malloc(url_len);
if(path == NULL || strnlen(path, url_len) == 0)
{
snprintf(request_url, url_len, "/");
}
else
{
snprintf(request_url, url_len, "%s", path);
}
if(query && strnlen(query, url_len))
{
strncat(request_url, "?", url_len);
strncat(request_url, query, url_len);
}
return request_url;
}
//data is for POST. if method is GET, data should be NULL
void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD method, enum TFE_RPC_FLAG flag, const char* data, int data_len, struct event_base * evbase)
{
@@ -163,7 +189,7 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
{
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "event base is NULL");
return;
}
}
struct evhttp_uri* uri = evhttp_uri_parse(url);
if(NULL == uri)
{
@@ -181,22 +207,6 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
{
port = 80;
}
const char* path = evhttp_uri_get_path(uri);
const char* query = evhttp_uri_get_query(uri);
char request_url[TFE_STRING_MAX] = "";
if(path == NULL || strnlen(path, TFE_STRING_MAX) == 0)
{
snprintf(request_url, TFE_STRING_MAX, "/");
}
else
{
snprintf(request_url, TFE_STRING_MAX, "%s", path);
}
if(query && strnlen(query, TFE_STRING_MAX))
{
strncat(request_url, "?", TFE_STRING_MAX);
strncat(request_url, query, TFE_STRING_MAX);
}
//printf("url:%s host:%s port:%d path:%s query:%s request_url:%s\n", url, host, port, path, query, request_url);
struct evdns_base* dnsbase = evdns_base_new(evbase, EVDNS_BASE_INITIALIZE_NAMESERVERS);
if (!dnsbase)
@@ -219,6 +229,14 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
}
evhttp_request_set_error_cb(request, request_error_cb);
evhttp_add_header(evhttp_request_get_output_headers(request), "Host", host);
int url_len = strlen(url);
char* request_url = get_request_url(uri, url_len);
//printf("request url is %s\n", request_url);
if(request_url == NULL)
{
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "get request url failed");
return;
}
switch(method)
{
case GET:
@@ -232,6 +250,7 @@ void tfe_rpc_async_ask(struct future* f, const char* url, enum TFE_RPC_METHOD me
_wrapped_promise_failed(p, FUTURE_ERROR_EXCEPTION, "method is invalid!");
return;
}
free(request_url);
}
struct tfe_rpc_response_result* tfe_rpc_release(void* result)