tevent_coroutine: let tevent_coroutine_yield() check for subreq == NULL, to make...
authorStefan Metzmacher <metze@samba.org>
Mon, 4 May 2009 10:23:34 +0000 (12:23 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 22 Apr 2013 09:21:46 +0000 (11:21 +0200)
Do we want that?

metze

lib/util/tevent_coroutine.c
source4/ntvfs/ipc/vfs_ipc.c

index ddbe3d049c9690c5affb452df5d53b0c7cb475f4..b1d606478030465139f389bce5ff9416c8b1e07c 100644 (file)
@@ -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;
 
index e2648852203e53a7c71081356bd1505e2081a51e..de51533c38b92a20df1fe5019e3d291b14041856 100644 (file)
@@ -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);
 }