修改future-promise接口,准备增加性能调试功能。
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <sys/time.h>
|
||||
|
||||
enum e_future_error
|
||||
{
|
||||
@@ -14,13 +15,25 @@ typedef void (future_success_cb)(future_result_t* result, void * user);
|
||||
typedef void (future_failed_cb)(enum e_future_error err, const char * what, void * user);
|
||||
typedef void (promise_ctx_destroy_cb)(struct promise * p);
|
||||
|
||||
struct future * future_create(future_success_cb * cb_success, future_failed_cb * cb_failed, void * user);
|
||||
struct future * promise_to_future(struct promise * p);
|
||||
struct promise * future_to_promise(struct future * f);
|
||||
void future_promise_library_init(void);
|
||||
|
||||
/*
|
||||
* Future APIs are used by Async RPC caller.
|
||||
*/
|
||||
struct future * future_create(const char* symbol, future_success_cb * cb_success, future_failed_cb * cb_failed, void * user);
|
||||
void future_set_timeout(struct future * f, struct timeval timeout);
|
||||
void future_destroy(struct future * f);
|
||||
|
||||
|
||||
/*
|
||||
* Promise APIs are used by Async RPC implementation.
|
||||
*/
|
||||
struct promise * future_to_promise(struct future * f);
|
||||
void promise_failed(struct promise * p, enum e_future_error error, const char * what);
|
||||
void promise_success(struct promise * p, void * result);
|
||||
void promise_set_ctx(struct promise * p, void * ctx, promise_ctx_destroy_cb * cb);
|
||||
void * promise_get_ctx(struct promise * p);
|
||||
void * promise_dettach_ctx(struct promise * p);
|
||||
//return 1 on a meaningful timeout, or 0 on no timeout.
|
||||
int promise_get_timeout(struct promise * p, struct timeval * timeout);
|
||||
|
||||
|
||||
@@ -4,10 +4,15 @@
|
||||
|
||||
#include <tfe_future.h>
|
||||
#include <tfe_utils.h>
|
||||
|
||||
struct _future_promise_debug
|
||||
{
|
||||
struct timeval create_time;
|
||||
};
|
||||
struct future
|
||||
{
|
||||
void * user;
|
||||
char symbol[TFE_SYMBOL_MAX];
|
||||
struct timeval timeout;
|
||||
future_success_cb * cb_success;
|
||||
future_failed_cb * cb_failed;
|
||||
};
|
||||
@@ -16,12 +21,13 @@ struct promise
|
||||
{
|
||||
struct future f;
|
||||
void * ctx;
|
||||
int has_timeout;
|
||||
promise_ctx_destroy_cb * cb_ctx_destroy;
|
||||
struct _future_promise_debug __debug;
|
||||
};
|
||||
|
||||
struct future * promise_to_future(struct promise * p)
|
||||
void future_promise_library_init(void)
|
||||
{
|
||||
return &p->f;
|
||||
return;
|
||||
}
|
||||
|
||||
struct promise * future_to_promise(struct future * f)
|
||||
@@ -29,15 +35,23 @@ struct promise * future_to_promise(struct future * f)
|
||||
return (struct promise *) f;
|
||||
}
|
||||
|
||||
struct future * future_create(future_success_cb * cb_success, future_failed_cb * cb_failed, void * user)
|
||||
struct future * future_create(const char* symbol, future_success_cb * cb_success, future_failed_cb * cb_failed, void * user)
|
||||
{
|
||||
struct promise * p = ALLOC(struct promise, 1);
|
||||
p->f.user = user;
|
||||
p->f.cb_success = cb_success;
|
||||
p->f.cb_failed = cb_failed;
|
||||
strncpy(p->f.symbol,symbol,sizeof(p->f.symbol));
|
||||
gettimeofday(&p->__debug.create_time, NULL);
|
||||
return &p->f;
|
||||
}
|
||||
|
||||
void future_set_timeout(struct future * f, struct timeval timeout)
|
||||
{
|
||||
struct promise * p=(struct promise *) f;
|
||||
f->timeout=timeout;
|
||||
p->has_timeout=1;
|
||||
return;
|
||||
}
|
||||
void future_destroy(struct future * f)
|
||||
{
|
||||
struct promise * promise = future_to_promise(f);
|
||||
@@ -81,3 +95,18 @@ void * promise_dettach_ctx(struct promise * p)
|
||||
p->cb_ctx_destroy = NULL;
|
||||
return ctx;
|
||||
}
|
||||
/**
|
||||
Get timeout from a promise which is set in future.
|
||||
|
||||
@param timeout Output.
|
||||
@return 1 on a meaningful timeout, or 0 on no timeout.
|
||||
*/
|
||||
int promise_get_timeout(struct promise * p, struct timeval * timeout)
|
||||
{
|
||||
if(p->has_timeout)
|
||||
{
|
||||
*timeout=p->f.timeout;
|
||||
}
|
||||
return p->has_timeout;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <MESA/MESA_handle_logger.h>
|
||||
#include <tfe_utils.h>
|
||||
#include <tfe_future.h>
|
||||
#include <tfe_stream.h>
|
||||
#include <platform.h>
|
||||
#include <proxy.h>
|
||||
@@ -197,6 +198,7 @@ int main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
future_promise_library_init();
|
||||
/* PROXY INSTANCE */
|
||||
g_default_proxy = ALLOC(struct tfe_proxy, 1);
|
||||
assert(g_default_proxy);
|
||||
|
||||
@@ -378,7 +378,12 @@ struct ssl_mgr * ssl_manager_init(const char * ini_profile, const char * section
|
||||
TFE_LOG_ERROR(logger, "Unsupported SSL/TLS protocol %s", version_str);
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
ret=ssl_init();
|
||||
if(ret<0)
|
||||
{
|
||||
TFE_LOG_ERROR(logger, "OpenSSL global init failed.");
|
||||
goto error_out;
|
||||
}
|
||||
//tfe2a uses SSLv23_method, it was been deprecated and replaced with the TLS_method() in openssl 1.1.0.
|
||||
mgr->sslmethod = TLS_method;
|
||||
MESA_load_profile_uint_def(ini_profile, section, "ssl_compression", &(mgr->sslcomp), 1);
|
||||
@@ -853,7 +858,7 @@ extern void ssl_async_upstream_create(struct future * f, struct ssl_mgr * mgr, e
|
||||
ctx->mgr = mgr;
|
||||
promise_set_ctx(p, ctx, ssl_connect_origin_ctx_free);
|
||||
|
||||
ctx->f_peek_chello = future_create(peek_chello_on_succ, peek_chello_on_fail, p);
|
||||
ctx->f_peek_chello = future_create("peek_sni", peek_chello_on_succ, peek_chello_on_fail, p);
|
||||
ssl_async_peek_client_hello(ctx->f_peek_chello, fd_downstream, evbase, mgr->logger);
|
||||
}
|
||||
|
||||
@@ -1188,7 +1193,7 @@ void ssl_async_downstream_create(struct future * f, struct ssl_mgr * mgr, struct
|
||||
{
|
||||
ATOMIC_INC(&(mgr->stat_val[SSL_FAKE_CRT]));
|
||||
}
|
||||
ctx->f_query_cert = future_create(ask_keyring_on_succ, ask_keyring_on_fail, p);
|
||||
ctx->f_query_cert = future_create("ask_kyr",ask_keyring_on_succ, ask_keyring_on_fail, p);
|
||||
key_keeper_async_ask(ctx->f_query_cert, mgr->keeper_of_keys, keyring_id, ctx->origin_crt, ctx->is_origin_crt_vaild,
|
||||
evbase);
|
||||
return;
|
||||
|
||||
@@ -518,7 +518,7 @@ void ssl_upstream_create_on_success(future_result_t * result, void * user)
|
||||
_stream->defer_fd_upstream = 0;
|
||||
|
||||
/* Next, create downstream */
|
||||
_stream->future_downstream_create = future_create(ssl_downstream_create_on_success,
|
||||
_stream->future_downstream_create = future_create("ssl_down",ssl_downstream_create_on_success,
|
||||
ssl_downstream_create_on_fail, _stream);
|
||||
|
||||
ssl_async_downstream_create(_stream->future_downstream_create, _stream->ssl_mgr,
|
||||
@@ -617,7 +617,7 @@ void tfe_stream_init_by_fds(struct tfe_stream * stream, evutil_socket_t fd_downs
|
||||
{
|
||||
_stream->ssl_mgr = _stream->proxy_ref->ssl_mgr_handler;
|
||||
|
||||
_stream->future_upstream_create = future_create(
|
||||
_stream->future_upstream_create = future_create("ssl_up",
|
||||
ssl_upstream_create_on_success, ssl_upstream_create_on_fail, (void *) _stream);
|
||||
|
||||
/* Defer setup conn_downstream & conn_upstream in async callbacks. */
|
||||
|
||||
Reference in New Issue
Block a user