From 7741ed43f5bc0be9473a281d050c6fbdbc6aea81 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sun, 6 Apr 2025 03:28:09 -0600 Subject: lib9p: Rename the server coroutine functions, pull out the read func --- lib9p/include/lib9p/srv.h | 58 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 17 deletions(-) (limited to 'lib9p/include') diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h index 85fc6bd..7f2711c 100644 --- a/lib9p/include/lib9p/srv.h +++ b/lib9p/include/lib9p/srv.h @@ -149,32 +149,56 @@ struct lib9p_srv { }; /** - * In an infinite loop, accept a connection and read messages from it until - * close; dispatching requests to a pool of lib9p_srv_write_cr() coroutines - * with the same `srv`. + * In a loop loop, accept a connection call lib9p_srv_read() on it. + * If LO_CALL(listener, accept) fails, then the function returns. * - * Will just close the connection if a T-message has a size[4] <7. + * When the last lib9p_srv_accept_and_read_loop() instance for a given + * `srv` returns, it will signal all lib9p_srv_worker_loop() calls to + * return. + * + * @param srv: The server configuration and state; has an associated + * pool of lib9p_srv_worker_loop() coroutines. * - * @param srv: The server configuration and state; has an associated pool of - * lib9p_srv_write_cr() coroutines. * @param listener: The listener object to accept connections from. + */ +void lib9p_srv_accept_and_read_loop(struct lib9p_srv *srv, lo_interface net_stream_listener listener); + +/** + * You should probably not call this directly; you should probably use + * lib9p_srv_accept_and_read_loop(). + * + * Given an already-established stream connection (i.e. a TCP + * connection), service that connection; return once the connection is + * closed. Requests are dispatched to a pool of + * lib9p_srv_worker_loop() coroutines with the same `srv`. * - * @errno LINUX_EMSGSIZE T-message has size[4] bigger than max_msg_size - * @errno LINUX_EDOM Tversion specified an impossibly small max_msg_size + * Will just close the connection if a T-message has a size[4] <7. + * + * @param srv: The server configuration and state; has an associated + * pool of lib9p_srv_worker_loop() coroutines. + * + * @param conn: The listener object to accept connections from. + * + * Errors that this function itself may send to clients: + * + * @errno LINUX_EMSGSIZE T-message has size[4] bigger than max_msg_size + * @errno LINUX_EDOM Tversion specified an impossibly small max_msg_size * @errno LINUX_EOPNOTSUPP T-message has an R-message type, or an unrecognized T-message type - * @errno LINUX_EBADMSG T-message has wrong size[4] for its content, or has invalid UTF-8 - * @errno LINUX_ERANGE R-message does not fit into max_msg_size + * @errno LINUX_EBADMSG T-message has wrong size[4] for its content, or has invalid UTF-8 + * @errno LINUX_ERANGE R-message does not fit into max_msg_size */ -[[noreturn]] void lib9p_srv_read_cr(struct lib9p_srv *srv, lo_interface net_stream_listener listener); +void lib9p_srv_read(struct lib9p_srv *srv, lo_interface net_stream_conn conn); + + /** - * Service requests to the `struct lib9p_srv *srv` argument that have been - * read by lib9p_srv_read_cr(). + * 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. * - * @param struct lib9p_srv *srv: The server configuration and state; has an - * associated pool of lib9p_srv_read_cr() - * coroutines. + * @param srv: The server configuration and state; has an associated + * pool of lib9p_srv_accept_and_read_loop() coroutines. */ -COROUTINE lib9p_srv_write_cr(void *_srv); +void lib9p_srv_worker_loop(struct lib9p_srv *srv); #endif /* _LIB9P_SRV_H_ */ -- cgit v1.2.3-2-g168b From 06cc1184f375ce5929010254781483277d9447d2 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 12 Apr 2025 21:30:52 -0600 Subject: lib9p: srv: Less nesting in the context structs --- lib9p/include/lib9p/srv.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'lib9p/include') diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h index 7f2711c..1b14c32 100644 --- a/lib9p/include/lib9p/srv.h +++ b/lib9p/include/lib9p/srv.h @@ -21,13 +21,20 @@ CR_CHAN_DECLARE(_lib9p_srv_flushch, bool); -struct lib9p_srv_ctx { - struct lib9p_ctx basectx; - uint32_t uid; +struct lib9p_srv_authinfo { + lib9p_nuid_t uid; struct lib9p_s uname; +}; + +struct lib9p_srv_ctx { + struct lib9p_ctx basectx; + struct lib9p_srv_authinfo *authinfo; BEGIN_PRIVATE(LIB9P_SRV_H); - _lib9p_srv_flushch_t _flushch; + struct _lib9p_srv_sess *parent_sess; + lib9p_tag_t tag; + uint8_t *net_bytes; + _lib9p_srv_flushch_t flushch; END_PRIVATE(LIB9P_SRV_H); }; @@ -132,7 +139,7 @@ LO_INTERFACE(lib9p_srv_dio); /* main server entrypoints ****************************************************/ -CR_RPC_DECLARE(_lib9p_srv_reqch, struct _lib9p_srv_req *, bool); +CR_RPC_DECLARE(_lib9p_srv_reqch, struct lib9p_srv_ctx *, bool); struct lib9p_srv { /* Things you provide */ -- cgit v1.2.3-2-g168b From bf32c2cd495099c93195b202158f46870ceed0ef Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 12 Apr 2025 06:37:54 -0600 Subject: lib9p: Test+fix that auth data is tracked in the context --- lib9p/include/lib9p/srv.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib9p/include') diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h index 1b14c32..7109179 100644 --- a/lib9p/include/lib9p/srv.h +++ b/lib9p/include/lib9p/srv.h @@ -24,6 +24,10 @@ CR_CHAN_DECLARE(_lib9p_srv_flushch, bool); struct lib9p_srv_authinfo { lib9p_nuid_t uid; struct lib9p_s uname; + + BEGIN_PRIVATE(LIB9P_SRV_H); + unsigned int refcount; + END_PRIVATE(LIB9P_SRV_H); }; struct lib9p_srv_ctx { -- cgit v1.2.3-2-g168b