From 47a05cc0c422ed0871cc517f90e9a1ab69a13647 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 4 May 2009 12:23:34 +0200 Subject: [PATCH 1/1] tevent_coroutine: let tevent_coroutine_yield() check for subreq == NULL, to make the callers easier. Do we want that? metze --- lib/util/tevent_coroutine.c | 13 +++++++++++++ source4/ntvfs/ipc/vfs_ipc.c | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/util/tevent_coroutine.c b/lib/util/tevent_coroutine.c index ddbe3d049c96..b1d606478030 100644 --- a/lib/util/tevent_coroutine.c +++ b/lib/util/tevent_coroutine.c @@ -165,6 +165,19 @@ void _tevent_coroutine_yield(struct tevent_coroutine *tco, struct tevent_req *subreq, const char *location) { + if (subreq == NULL) { + tco->result.state = TEVENT_COROUTINE_NO_MEMORY; + tco->result.location = location; + tco->result.return_location = location; + /* + * this jumps back to tevent_coroutine_run() after + * co_call(). + */ + tco->coro = NULL; + co_exit(); + return; + } + tco->result.state = TEVENT_COROUTINE_YIELD; tco->result.location = location; diff --git a/source4/ntvfs/ipc/vfs_ipc.c b/source4/ntvfs/ipc/vfs_ipc.c index e2648852203e..de51533c38b9 100644 --- a/source4/ntvfs/ipc/vfs_ipc.c +++ b/source4/ntvfs/ipc/vfs_ipc.c @@ -681,6 +681,7 @@ static struct tevent_coroutine_result *example_ocor_body(struct tevent_coroutine } tevent_coroutine_yield(coro, subreq); ok = tevent_wakeup_recv(subreq); + TALLOC_FREE(subreq); DEBUG(0,("%s[%p]: 2. %s wakeup[%d]\n", __location__, coro, state->string, ok)); @@ -751,6 +752,7 @@ static struct tevent_coroutine_result *example_coro_body(struct tevent_coroutine } tevent_coroutine_yield(coro, subreq); ret = example_ocor_recv(subreq, &sys_errno); + TALLOC_FREE(subreq); if (ret == -1) { tevent_coroutine_error(coro, sys_errno); return tevent_coroutine_return(coro); @@ -758,6 +760,20 @@ static struct tevent_coroutine_result *example_coro_body(struct tevent_coroutine DEBUG(0,("%s:%s[%p]: 2. %s example_ocor[%d]\n", __location__, __FUNCTION__, coro, state->string, ret)); + 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); + TALLOC_FREE(subreq); + if (ret == -1) { + tevent_coroutine_error(coro, sys_errno); + return tevent_coroutine_return(coro); + } + + DEBUG(0,("%s:%s[%p]: 3. %s example_ocor[%d]\n", __location__, __FUNCTION__, coro, state->string, ret)); + tevent_coroutine_done(coro); return tevent_coroutine_return(coro); } -- 2.34.1