diff options
| author | Lu Qiuwen <[email protected]> | 2018-08-27 21:10:45 +0800 |
|---|---|---|
| committer | Lu Qiuwen <[email protected]> | 2018-08-27 21:10:45 +0800 |
| commit | 8869f1888ceb1cbacedc0457af8c55b099e9e94e (patch) | |
| tree | 91091af9b5430693de245fe2ce2fac102e683715 /common/src/tfe_future.cpp | |
| parent | f60b634ec63b6e37e47f007356748d5184f3ab99 (diff) | |
变更stream系列文件的名称,修正了部分编译错误
* 变更stream系列文件的名称为ssl_stream, tcp_stream等;
* 变更stream.h为platform.h,因该文件为平台整体公用;
* 修正了ssl_stream, ssl_sess_cache文件中的编译错误,部分实现的bug。
* 调整了tfe_future的路径,由平台实现改为公用组件。
Diffstat (limited to 'common/src/tfe_future.cpp')
| -rw-r--r-- | common/src/tfe_future.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/common/src/tfe_future.cpp b/common/src/tfe_future.cpp new file mode 100644 index 0000000..3a360f6 --- /dev/null +++ b/common/src/tfe_future.cpp @@ -0,0 +1,83 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include <tfe_future.h> +#include <tfe_utils.h> + +struct future +{ + void * user; + future_success_cb * cb_success; + future_failed_cb * cb_failed; +}; + +struct promise +{ + struct future f; + void * ctx; + promise_ctx_destroy_cb * cb_ctx_destroy; +}; + +struct future * promise_to_future(struct promise * p) +{ + return &p->f; +} + +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 promise * p = ALLOC(struct promise, 1); + p->f.user = user; + p->f.cb_success = cb_success; + p->f.cb_failed = cb_failed; + return &p->f; +} + +void future_destroy(struct future * f) +{ + struct promise * promise = future_to_promise(f); + if (promise->cb_ctx_destroy != NULL) + { + promise->cb_ctx_destroy(promise); + } + + memset(promise, 0, sizeof(struct promise)); + free(promise); +} + +void promise_failed(struct promise * p, enum e_future_error error, const char * what) +{ + p->f.cb_failed(error, what, p->f.user); + return; +} + +void promise_success(struct promise * p, void * result) +{ + p->f.cb_success(result, p->f.user); + return; +} + +void promise_set_ctx(struct promise * p, void * ctx, promise_ctx_destroy_cb * cb) +{ + p->ctx = ctx; + p->cb_ctx_destroy = cb; + return; +} + +void * promise_get_ctx(struct promise * p) +{ + return p->ctx; +} + +void * promise_dettach_ctx(struct promise * p) +{ + void * ctx = p->ctx; + p->ctx = NULL; + p->cb_ctx_destroy = NULL; + return ctx; +} |
