summaryrefslogtreecommitdiff
path: root/lib9p/srv.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-04 21:03:37 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-02-04 21:03:37 -0700
commit5c373cfe544df4ddba44adf3f6b60399340e4bd5 (patch)
treef96f5c57bbb042b3962bed49853621f6d344de04 /lib9p/srv.c
parent65f2a6fb8797385e06e61e13bac7a33d27f2097d (diff)
parent57d4c9f154cacd5d0dcc2f45033d784b3e0b6734 (diff)
Merge branch 'lukeshu/9p-exit'
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r--lib9p/srv.c15
1 files changed, 14 insertions, 1 deletions
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;