diff options
Diffstat (limited to 'lib9p/srv.c')
-rw-r--r-- | lib9p/srv.c | 31 |
1 files changed, 15 insertions, 16 deletions
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); } |