summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib9p/srv.c26
-rw-r--r--lib9p/srv_include/lib9p/srv.h24
2 files changed, 30 insertions, 20 deletions
diff --git a/lib9p/srv.c b/lib9p/srv.c
index dae73ea..b604324 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -450,8 +450,6 @@ void lib9p_srv_accept_and_read_loop(struct lib9p_srv *srv, lo_interface net_stre
}
}
-static void handle_message(struct srv_req *ctx);
-
void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) {
assert(srv);
assert(srv->rootdir);
@@ -511,7 +509,7 @@ void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn _conn) {
/* Handle the message... */
if (req.net_bytes[4] == LIB9P_TYP_Tversion)
/* ...in this coroutine for Tversion, */
- handle_message(&req);
+ lib9p_srv_worker(&req);
else
/* ...but usually in another coroutine. */
cr_rpc_send_req(&srv->_reqch, &req);
@@ -577,14 +575,7 @@ void lib9p_srv_worker_loop(struct lib9p_srv *srv) {
cr_rpc_send_resp(rpc_handle, 0);
/* Process the request. **************************************/
- handle_message(&req);
-
- /* Release resources. ****************************************/
- while (cr_chan_can_send(&req.flushch))
- cr_chan_send(&req.flushch, false);
- map_del(&req.parent_sess->reqs, req.tag);
- if (req.parent_sess->closing && !map_len(&req.parent_sess->reqs))
- cr_unpause(req.parent_sess->parent_conn->reader);
+ lib9p_srv_worker(&req);
}
}
@@ -640,11 +631,11 @@ static tmessage_handler tmessage_handlers[0x100] = {
#endif
};
-static void handle_message(struct srv_req *ctx) {
+void lib9p_srv_worker(struct srv_req *ctx) {
uint8_t *host_req = NULL;
uint8_t host_resp[CONFIG_9P_SRV_MAX_HOSTMSG_SIZE];
- /* Unmarshal it. */
+ /* Unmarshal it. *****************************************************/
ssize_t host_size = lib9p_Tmsg_validate(&ctx->basectx, ctx->net_bytes);
if (host_size < 0)
goto write;
@@ -655,9 +646,10 @@ static void handle_message(struct srv_req *ctx) {
&typ, host_req);
srv_msglog(ctx, typ, host_req);
- /* Handle it. */
+ /* Handle it. ********************************************************/
tmessage_handlers[typ](ctx, (void *)host_req, (void *)host_resp);
+ /* Write the response. ***********************************************/
write:
if (lib9p_ctx_has_error(&ctx->basectx))
srv_respond_error(ctx);
@@ -670,9 +662,15 @@ static void handle_message(struct srv_req *ctx) {
srv_msglog(ctx, typ+1, &host_resp);
srv_write_Rmsg(ctx, &net_resp);
}
+ /* Release resources. ************************************************/
if (host_req)
free(host_req);
free(ctx->net_bytes);
+ while (cr_chan_can_send(&ctx->flushch))
+ cr_chan_send(&ctx->flushch, false);
+ map_del(&ctx->parent_sess->reqs, ctx->tag);
+ if (ctx->parent_sess->closing && !map_len(&ctx->parent_sess->reqs))
+ cr_unpause(ctx->parent_sess->parent_conn->reader);
}
/* handle_T* ******************************************************************/
diff --git a/lib9p/srv_include/lib9p/srv.h b/lib9p/srv_include/lib9p/srv.h
index db5be41..9b133e1 100644
--- a/lib9p/srv_include/lib9p/srv.h
+++ b/lib9p/srv_include/lib9p/srv.h
@@ -207,20 +207,32 @@ void lib9p_srv_accept_and_read_loop(struct lib9p_srv *srv, lo_interface net_stre
* @errno L_EDOM Tversion specified an impossibly small max_msg_size
* @errno L_EOPNOTSUPP T-message has an R-message type, or an unrecognized T-message type
* @errno L_EBADMSG T-message has wrong size[4] for its content, or has invalid UTF-8
- * @errno L_ERANGE R-message does not fit into max_msg_size
*/
void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn conn);
-
-
/**
- * In a loop, service requests to the `struct lib9p_srv *srv` argument
- * that have been read by lib9p_srv_accept_and_read_loop() /
- * lib9p_srv_read(). A "NULL" request causes the function to return.
+ * In a loop, call lib9p_srv_worker() to service requests to the
+ * `struct lib9p_srv *srv` argument that have been read by
+ * lib9p_srv_accept_and_read_loop() / lib9p_srv_read(). A "NULL"
+ * request causes the function to return.
*
* @param srv: The server configuration and state; has an associated
* pool of lib9p_srv_accept_and_read_loop() coroutines.
*/
void lib9p_srv_worker_loop(struct lib9p_srv *srv);
+/**
+ * You should probably not call this directly; you should probably use
+ * lib9p_srv_worker_loop().
+ *
+ * Handle and send a response to a single request.
+ *
+ * @param req: The request to handle.
+ *
+ * Errors that this function itself may send to clients:
+ *
+ * @errno L_ERANGE R-message does not fit into max_msg_size
+ */
+void lib9p_srv_worker(struct lib9p_srv_ctx *req);
+
#endif /* _LIB9P_SRV_H_ */