支持promise finish。

This commit is contained in:
zhangchengwei
2018-11-23 20:55:28 +08:00
committed by zhengchao
parent 313f36c58a
commit 9fc2a8a0d2
8 changed files with 85 additions and 29 deletions

View File

@@ -631,7 +631,7 @@ bool fetch_header_over_biz(struct tango_cache_ctx *ctx)
{
tango_cache_set_fail_state(ctx, CACHE_ERR_INTERNAL);
ctx->get.state = GET_STATE_DELETE;
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
promise_failed(ctx->promise, FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
return false;
}
@@ -640,7 +640,7 @@ bool fetch_header_over_biz(struct tango_cache_ctx *ctx)
ctx->get.result.data_frag = ctx->get.response_tag.buff;
ctx->get.result.size = ctx->get.response_tag.len;
ctx->get.result.type = RESULT_TYPE_USERTAG;
promise_success(future_to_promise(ctx->future), &ctx->get.result);
promise_success(ctx->promise, &ctx->get.result);
easy_string_destroy(&ctx->get.response_tag);
}
if(ctx->response.len > 0)
@@ -648,7 +648,7 @@ bool fetch_header_over_biz(struct tango_cache_ctx *ctx)
ctx->get.result.data_frag = ctx->response.buff;
ctx->get.result.size = ctx->response.len;
ctx->get.result.type = RESULT_TYPE_HEADER;
promise_success(future_to_promise(ctx->future), &ctx->get.result);
promise_success(ctx->promise, &ctx->get.result);
easy_string_destroy(&ctx->response);
}
return true;
@@ -671,7 +671,7 @@ static size_t curl_get_response_body_cb(void *ptr, size_t size, size_t count, vo
ctx->get.result.data_frag = (const char *)ptr;
ctx->get.result.size = size * count;
ctx->get.result.type = RESULT_TYPE_BODY;
promise_success(future_to_promise(ctx->future), &ctx->get.result);
promise_success(ctx->promise, &ctx->get.result);
return size*count;
}
@@ -689,7 +689,8 @@ bool check_expires_fresh_header(struct tango_cache_ctx *ctx)
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
ctx->get.state = GET_STATE_DELETE; //<2F><><EFBFBD><EFBFBD>ʧЧʱ<D0A7><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ctx->get.result.type = RESULT_TYPE_MISS;
promise_success(future_to_promise(ctx->future), &ctx->get.result);
promise_success(ctx->promise, &ctx->get.result);
promise_finish(ctx->promise);
easy_string_destroy(&ctx->response);
return false;
}
@@ -698,7 +699,8 @@ bool check_expires_fresh_header(struct tango_cache_ctx *ctx)
{
tango_cache_set_fail_state(ctx, CACHE_TIMEOUT);
ctx->get.result.type = RESULT_TYPE_MISS;
promise_success(future_to_promise(ctx->future), &ctx->get.result);
promise_success(ctx->promise, &ctx->get.result);
promise_finish(ctx->promise);
easy_string_destroy(&ctx->response);
return false;
}
@@ -710,7 +712,7 @@ static bool check_get_result_code(struct tango_cache_ctx *ctx, CURLcode code, lo
if(code != CURLE_OK)
{
tango_cache_set_fail_state(ctx, CACHE_ERR_CURL);
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
promise_failed(ctx->promise, FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
return false;
}
@@ -720,12 +722,13 @@ static bool check_get_result_code(struct tango_cache_ctx *ctx, CURLcode code, lo
{
tango_cache_set_fail_state(ctx, CACHE_CACHE_MISS);
ctx->get.result.type = RESULT_TYPE_MISS;
promise_success(future_to_promise(ctx->future), &ctx->get.result);
promise_success(ctx->promise, &ctx->get.result);
promise_finish(ctx->promise);
}
else
{
tango_cache_set_fail_state(ctx, CACHE_ERR_INTERNAL);
promise_failed(future_to_promise(ctx->future), FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
promise_failed(ctx->promise, FUTURE_ERROR_CANCEL, tango_cache_get_errstring(ctx));
}
return false;
}
@@ -817,7 +820,8 @@ void tango_cache_curl_get_done(struct tango_cache_ctx *ctx, CURLcode res, long r
if(ctx->method!=CACHE_REQUEST_HEAD || fetch_header_over_biz(ctx)) //HEAD<41><44><EFBFBD>ֵ<EFBFBD><D6B5>ֶβ<D6B6>ȫ<EFBFBD>Ȳ<EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޣ<EFBFBD>
{
ctx->get.result.type = RESULT_TYPE_END;
promise_success(future_to_promise(ctx->future), &ctx->get.result);
promise_success(ctx->promise, &ctx->get.result);
promise_finish(ctx->promise);
}
}
tango_cache_ctx_destroy(ctx);