diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-13 12:55:26 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-04-13 12:55:26 -0600 |
commit | 2a9d1f54758988ce23fbd1e9da4f0ad28c0edcbf (patch) | |
tree | 08b47b0e0772f590aa3ae48254590088a4b4402c /lib9p/include | |
parent | 52674d0483e3754b039857be1d11798859c5bcef (diff) | |
parent | bf32c2cd495099c93195b202158f46870ceed0ef (diff) |
Merge branch 'lukeshu/9p-malloc'
Diffstat (limited to 'lib9p/include')
-rw-r--r-- | lib9p/include/lib9p/srv.h | 79 |
1 files changed, 57 insertions, 22 deletions
diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h index 85fc6bd..7109179 100644 --- a/lib9p/include/lib9p/srv.h +++ b/lib9p/include/lib9p/srv.h @@ -21,13 +21,24 @@ 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; BEGIN_PRIVATE(LIB9P_SRV_H); - _lib9p_srv_flushch_t _flushch; + unsigned int refcount; + END_PRIVATE(LIB9P_SRV_H); +}; + +struct lib9p_srv_ctx { + struct lib9p_ctx basectx; + struct lib9p_srv_authinfo *authinfo; + + BEGIN_PRIVATE(LIB9P_SRV_H); + 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 +143,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 */ @@ -149,32 +160,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`. + * + * Will just close the connection if a T-message has a size[4] <7. * - * @errno LINUX_EMSGSIZE T-message has size[4] bigger than max_msg_size - * @errno LINUX_EDOM Tversion specified an impossibly small max_msg_size + * @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_ */ |