From 57d4c9f154cacd5d0dcc2f45033d784b3e0b6734 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Tue, 4 Feb 2025 09:05:14 -0700 Subject: lib9p: Test that we can do clean shutdown --- lib9p/srv.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lib9p/srv.c') diff --git a/lib9p/srv.c b/lib9p/srv.c index 7e6402e..10a8a96 100644 --- a/lib9p/srv.c +++ b/lib9p/srv.c @@ -200,6 +200,8 @@ static void handle_message(struct _lib9p_srv_req *ctx); assert(srv->rootdir); assert(listener); + srv->readers++; + uint32_t initial_rerror_overhead = rerror_overhead_for_version(0, buf); for (;;) { @@ -210,7 +212,11 @@ static void handle_message(struct _lib9p_srv_req *ctx); }; if (!conn.fd) { nonrespond_errorf("accept: error"); - continue; + srv->readers--; + if (srv->readers == 0) + while (srv->writers > 0) + _lib9p_srv_reqch_send_req(&srv->_reqch, NULL); + cr_exit(); } struct _srv_sess sess = { @@ -287,9 +293,16 @@ COROUTINE lib9p_srv_write_cr(void *_srv) { assert(srv->rootdir); cr_begin(); + srv->writers++; + for (;;) { /* Receive the request from the reader coroutine. ************/ rpc_handle = _lib9p_srv_reqch_recv_req(&srv->_reqch); + if (!rpc_handle.req) { + srv->writers--; + _lib9p_srv_reqch_send_resp(rpc_handle, 0); + cr_exit(); + } /* Deep-copy the request from the reader coroutine's * stack to our stack. */ req = *rpc_handle.req; -- cgit v1.2.3-2-g168b