+struct example_ocor_state {
+ const char *string;
+};
+
+static struct tevent_coroutine_result *example_ocor_body(struct tevent_coroutine *coro,
+ struct tevent_context *ev,
+ void *private_data);
+
+static struct tevent_req *example_ocor_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ const char *string)
+{
+ struct tevent_req *req;
+ struct example_ocor_state *state;
+ struct tevent_coroutine *coro;
+
+ req = tevent_req_create(mem_ctx, &state, struct example_ocor_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ state->string = string;
+
+ coro = tevent_coroutine_create(req, ev, example_ocor_body);
+ if (tevent_req_nomem(coro, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ tevent_coroutine_run(coro);
+ if (!tevent_req_is_in_progress(req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ return req;
+}
+
+static struct tevent_coroutine_result *example_ocor_body(struct tevent_coroutine *coro,
+ struct tevent_context *ev,
+ void *private_data)
+{
+ struct example_ocor_state *state = talloc_get_type_abort(private_data,
+ struct example_ocor_state);
+ struct tevent_req *subreq;
+ bool ok;
+
+ DEBUG(0,("%s[%p]: 1. %s\n", __location__, coro, state->string));
+
+ subreq = tevent_wakeup_send(state, ev, timeval_current_ofs(0,500));
+ if (tevent_coroutine_nomem(subreq, coro)) {
+ return tevent_coroutine_return(coro);
+ }
+ tevent_coroutine_yield(coro, subreq);
+ ok = tevent_wakeup_recv(subreq);
+
+ DEBUG(0,("%s[%p]: 2. %s wakeup[%d]\n", __location__, coro, state->string, ok));
+
+ tevent_coroutine_done(coro);
+ return tevent_coroutine_return(coro);
+}
+
+static int example_ocor_recv(struct tevent_req *req, int *perrno)
+{
+ if (tevent_req_is_unix_error(req, perrno)) {
+ return -1;
+ }
+
+ return 0;
+}
+
+struct example_coro_state {
+ const char *string;
+};
+
+static struct tevent_coroutine_result *example_coro_body(struct tevent_coroutine *coro,
+ struct tevent_context *ev,
+ void *private_data);
+
+static struct tevent_req *example_coro_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ const char *string)
+{
+ struct tevent_req *req;
+ struct example_coro_state *state;
+ struct tevent_coroutine *coro;
+
+ req = tevent_req_create(mem_ctx, &state, struct example_coro_state);
+ if (req == NULL) {
+ return NULL;
+ }
+
+ state->string = string;
+
+ coro = tevent_coroutine_create(req, ev, example_coro_body);
+ if (tevent_req_nomem(coro, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ tevent_coroutine_run(coro);
+ if (!tevent_req_is_in_progress(req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ return req;
+}
+
+static struct tevent_coroutine_result *example_coro_body(struct tevent_coroutine *coro,
+ struct tevent_context *ev,
+ void *private_data)
+{
+ struct example_coro_state *state = talloc_get_type_abort(private_data,
+ struct example_coro_state);
+ struct tevent_req *subreq;
+ int ret;
+ int sys_errno;
+
+ DEBUG(0,("%s:%s[%p]: 1. %s\n", __location__, __FUNCTION__, coro, state->string));
+
+ subreq = example_ocor_send(state, ev, state->string);
+ if (tevent_coroutine_nomem(subreq, coro)) {
+ return tevent_coroutine_return(coro);
+ }
+ tevent_coroutine_yield(coro, subreq);
+ ret = example_ocor_recv(subreq, &sys_errno);
+ if (ret == -1) {
+ tevent_coroutine_error(coro, sys_errno);
+ return tevent_coroutine_return(coro);
+ }
+
+ DEBUG(0,("%s:%s[%p]: 2. %s example_ocor[%d]\n", __location__, __FUNCTION__, coro, state->string, ret));
+
+ tevent_coroutine_done(coro);
+ return tevent_coroutine_return(coro);
+}
+
+static int example_coro_recv(struct tevent_req *req, int *perrno)
+{
+ if (tevent_req_is_unix_error(req, perrno)) {
+ return -1;
+ }
+
+ return 0;
+}
+