summaryrefslogtreecommitdiff
path: root/lib9p
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-14 18:29:15 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-10-14 18:29:15 -0600
commit3dcbd43ecd77c28762b0595475893ff052c0444a (patch)
tree9823d647e98811bc33f19152217b0bfc72edb8ed /lib9p
parent1427269e8650964713505728eda84bfec1f685e1 (diff)
wip libnet rewrite
Diffstat (limited to 'lib9p')
-rw-r--r--lib9p/CMakeLists.txt1
-rw-r--r--lib9p/include/lib9p/srv.h3
-rw-r--r--lib9p/srv.c31
3 files changed, 17 insertions, 18 deletions
diff --git a/lib9p/CMakeLists.txt b/lib9p/CMakeLists.txt
index 3584d7a..63469d9 100644
--- a/lib9p/CMakeLists.txt
+++ b/lib9p/CMakeLists.txt
@@ -12,4 +12,5 @@ target_sources(lib9p INTERFACE
)
target_link_libraries(lib9p INTERFACE
libcr_ipc
+ libnet
)
diff --git a/lib9p/include/lib9p/srv.h b/lib9p/include/lib9p/srv.h
index 4bf957c..284888f 100644
--- a/lib9p/include/lib9p/srv.h
+++ b/lib9p/include/lib9p/srv.h
@@ -96,7 +96,6 @@ CR_RPC_DECLARE(_lib9p_srv_reqch, struct _lib9p_srv_req *, bool)
struct lib9p_srv {
/* Things you provide */
- int sockfd;
void /*TODO*/ (*auth )(struct lib9p_srv_ctx *, char *treename); /* optional */
struct lib9p_srv_file *(*rootdir)(struct lib9p_srv_ctx *, char *treename);
@@ -114,7 +113,7 @@ struct lib9p_srv {
* @errno LINUX_ERANGE R-message does not fit into max_msg_size
*/
-COROUTINE lib9p_srv_read_cr(void *_srv);
+__attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct libnet_listener *listener);
COROUTINE lib9p_srv_write_cr(void *_srv);
#endif /* _LIB9P_SRV_H_ */
diff --git a/lib9p/srv.c b/lib9p/srv.c
index a3e4335..282cd68 100644
--- a/lib9p/srv.c
+++ b/lib9p/srv.c
@@ -8,13 +8,15 @@
#include <libcr_ipc/chan.h>
#include <libcr_ipc/mutex.h>
#include <libcr_ipc/select.h>
-#include <libnetio/netio.h>
+#include <libnet/libnet.h>
#include <lib9p/srv.h>
#include "internal.h"
/* structs ********************************************************************/
+#define MCALL(o, m, ...) (o)->vtable->m(o __VA_OPT__(,) __VA_ARGS__)
+
#define FIDFLAG_OPEN_R (1<<0)
#define FIDFLAG_OPEN_W (1<<1)
#define FIDFLAG_RCLOSE (1<<2)
@@ -51,7 +53,7 @@ struct _srv_fidinfo {
struct _srv_conn {
/* immutable */
struct lib9p_srv *parent_srv;
- int fd;
+ struct libnet_conn *fd;
cid_t reader; /* the lib9p_srv_read_cr() coroutine */
/* mutable */
cr_mutex_t writelock;
@@ -143,7 +145,7 @@ static void respond_error(struct _lib9p_srv_req *req) {
&host, req->net_bytes);
cr_mutex_lock(&sess->parent_conn->writelock);
- r = netio_write(sess->parent_conn->fd,
+ r = MCALL(sess->parent_conn->fd, write,
req->net_bytes, decode_u32le(req->net_bytes));
cr_mutex_unlock(&sess->parent_conn->writelock);
if (r < 0)
@@ -152,12 +154,12 @@ static void respond_error(struct _lib9p_srv_req *req) {
/* read coroutine *************************************************************/
-static bool read_at_least(int fd, uint8_t *buf, size_t goal, size_t *done) {
+static bool read_at_least(struct libnet_conn *fd, uint8_t *buf, size_t goal, size_t *done) {
assert(buf);
assert(goal);
assert(done);
while (*done < goal) {
- ssize_t r = netio_read(fd, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done);
+ ssize_t r = MCALL(fd, read, &buf[*done], CONFIG_9P_MAX_MSG_SIZE - *done);
if (r < 0) {
nonrespond_errorf("read: %s", strerror(-r));
return true;
@@ -173,24 +175,23 @@ static bool read_at_least(int fd, uint8_t *buf, size_t goal, size_t *done) {
static void handle_message(struct _lib9p_srv_req *ctx);
-COROUTINE lib9p_srv_read_cr(void *_srv) {
+__attribute__ ((noreturn)) void lib9p_srv_read_cr(struct lib9p_srv *srv, struct libnet_listener *listener) {
uint8_t buf[CONFIG_9P_MAX_MSG_SIZE];
- struct lib9p_srv *srv = _srv;
assert(srv);
assert(srv->rootdir);
- cr_begin();
+ assert(listener);
uint32_t initial_rerror_overhead = rerror_overhead_for_version(0, buf);
for (;;) {
struct _srv_conn conn = {
.parent_srv = srv,
- .fd = netio_accept(srv->sockfd),
+ .fd = MCALL(listener, accept),
.reader = cr_getcid(),
};
- if (conn.fd < 0) {
- nonrespond_errorf("accept: %s", strerror(-conn.fd));
+ if (!conn.fd) {
+ nonrespond_errorf("accept: error");
continue;
}
@@ -246,16 +247,14 @@ COROUTINE lib9p_srv_read_cr(void *_srv) {
_lib9p_srv_reqch_send_req(&srv->_reqch, &req);
}
close:
- netio_close(conn.fd, true, sess.reqs.len == 0);
+ MCALL(conn.fd, close, true, sess.reqs.len == 0);
if (sess.reqs.len) {
sess.closing = true;
cr_pause_and_yield();
assert(sess.reqs.len == 0);
- netio_close(conn.fd, true, true);
+ MCALL(conn.fd, close, true, true);
}
}
-
- cr_end();
}
/* write coroutine ************************************************************/
@@ -380,7 +379,7 @@ static void handle_message(struct _lib9p_srv_req *ctx) {
goto write;
cr_mutex_lock(&ctx->parent_sess->parent_conn->writelock);
- netio_write(ctx->parent_sess->parent_conn->fd,
+ MCALL(ctx->parent_sess->parent_conn->fd, write,
ctx->net_bytes, decode_u32le(ctx->net_bytes));
cr_mutex_unlock(&ctx->parent_sess->parent_conn->writelock);
}