summaryrefslogtreecommitdiff
path: root/lib9p/tests/test_server
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/tests/test_server')
-rw-r--r--lib9p/tests/test_server/fs_flush.c34
-rw-r--r--lib9p/tests/test_server/fs_shutdown.c25
-rw-r--r--lib9p/tests/test_server/fs_whoami.c32
-rw-r--r--lib9p/tests/test_server/main.c3
4 files changed, 42 insertions, 52 deletions
diff --git a/lib9p/tests/test_server/fs_flush.c b/lib9p/tests/test_server/fs_flush.c
index 63a52af..0ae905f 100644
--- a/lib9p/tests/test_server/fs_flush.c
+++ b/lib9p/tests/test_server/fs_flush.c
@@ -9,20 +9,19 @@
#define IMPLEMENTATION_FOR_LIB9P_SRV_H YES /* for ctx->flush_ch */
#include "fs_flush.h"
-LO_IMPLEMENTATION_C(lib9p_srv_file, struct flush_file, flush_file, static);
+LO_IMPLEMENTATION_C(lib9p_srv_file, struct flush_file, flush_file);
struct flush_fio {
struct flush_file *parent;
};
-LO_IMPLEMENTATION_H(lib9p_srv_fio, struct flush_fio, flush_fio);
-LO_IMPLEMENTATION_C(lib9p_srv_fio, struct flush_fio, flush_fio, static);
+LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct flush_fio, flush_fio);
/* srv_file *******************************************************************/
-static void flush_file_free(struct flush_file *self) {
+void flush_file_free(struct flush_file *self) {
assert(self);
}
-static struct lib9p_qid flush_file_qid(struct flush_file *self) {
+struct lib9p_qid flush_file_qid(struct flush_file *self) {
assert(self);
return (struct lib9p_qid){
.type = LIB9P_QT_FILE,
@@ -31,7 +30,7 @@ static struct lib9p_qid flush_file_qid(struct flush_file *self) {
};
}
-static lib9p_srv_stat_or_error flush_file_stat(struct flush_file *self, struct lib9p_srv_ctx *ctx) {
+lib9p_srv_stat_or_error flush_file_stat(struct flush_file *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
return ERROR_NEW_VAL(lib9p_srv_stat, ((struct lib9p_srv_stat){
@@ -47,20 +46,20 @@ static lib9p_srv_stat_or_error flush_file_stat(struct flush_file *self, struct l
.extension = lib9p_str(NULL),
}));
}
-static error flush_file_wstat(struct flush_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) {
+error flush_file_wstat(struct flush_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) {
assert(self);
assert(ctx);
return error_new(E_POSIX_EROFS, "cannot wstat API file");
}
-static error flush_file_remove(struct flush_file *self, struct lib9p_srv_ctx *ctx) {
+error flush_file_remove(struct flush_file *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
return error_new(E_POSIX_EROFS, "cannot remove API file");
}
-LIB9P_SRV_NOTDIR(struct flush_file, flush_file);
+LIB9P_SRV_NOTDIR(, struct flush_file, flush_file);
-static lib9p_srv_fio_or_error flush_file_fopen(struct flush_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) {
+lib9p_srv_fio_or_error flush_file_fopen(struct flush_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) {
assert(self);
assert(ctx);
@@ -77,7 +76,7 @@ static void flush_fio_iofree(struct flush_fio *self) {
free(self);
}
-static struct lib9p_qid flush_fio_qid(struct flush_fio *self) {
+static struct lib9p_qid flush_fio_ioqid(struct flush_fio *self) {
assert(self);
return flush_file_qid(self->parent);
}
@@ -94,8 +93,8 @@ static uint32_t_or_error flush_fio_pwrite(struct flush_fio *LM_UNUSED(self),
assert_notreached("not writable");
}
-static iovec_or_error flush_fio_pread(struct flush_fio *self, struct lib9p_srv_ctx *ctx,
- uint32_t byte_count, uint64_t LM_UNUSED(byte_offset)) {
+static error flush_fio_pread(struct flush_fio *self, struct lib9p_srv_ctx *ctx,
+ lo_interface io_writer dst, uint64_t LM_UNUSED(src_offset), uint32_t byte_count) {
assert(self);
assert(ctx);
@@ -115,14 +114,11 @@ static iovec_or_error flush_fio_pread(struct flush_fio *self, struct lib9p_srv_c
/* Return */
switch (self->parent->flush_behavior) {
case FLUSH_READ:
- return ERROR_NEW_VAL(iovec, ((struct iovec){
- .iov_base = "Sloth\n",
- .iov_len = 6 < byte_count ? 6 : byte_count,
- }));
+ return io_write(dst, "Sloth\n", 6 < byte_count ? 6 : byte_count).err;
case FLUSH_ERROR:
- return ERROR_NEW_ERR(iovec, error_new(E_POSIX_EAGAIN, "request canceled by flush"));
+ return error_new(E_POSIX_EAGAIN, "request canceled by flush");
case FLUSH_SILENT:
- return ERROR_NEW_ERR(iovec, error_new(E_POSIX_ECANCELED, "request canceled by flush"));
+ return error_new(E_POSIX_ECANCELED, "request canceled by flush");
default:
assert_notreached("invalid flush_behavior");
}
diff --git a/lib9p/tests/test_server/fs_shutdown.c b/lib9p/tests/test_server/fs_shutdown.c
index 079442e..22aca9e 100644
--- a/lib9p/tests/test_server/fs_shutdown.c
+++ b/lib9p/tests/test_server/fs_shutdown.c
@@ -8,20 +8,19 @@
#include "fs_shutdown.h"
-LO_IMPLEMENTATION_C(lib9p_srv_file, struct shutdown_file, shutdown_file, static);
+LO_IMPLEMENTATION_C(lib9p_srv_file, struct shutdown_file, shutdown_file);
struct shutdown_fio {
struct shutdown_file *parent;
};
-LO_IMPLEMENTATION_H(lib9p_srv_fio, struct shutdown_fio, shutdown_fio);
-LO_IMPLEMENTATION_C(lib9p_srv_fio, struct shutdown_fio, shutdown_fio, static);
+LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct shutdown_fio, shutdown_fio);
/* srv_file *******************************************************************/
-static void shutdown_file_free(struct shutdown_file *self) {
+void shutdown_file_free(struct shutdown_file *self) {
assert(self);
}
-static struct lib9p_qid shutdown_file_qid(struct shutdown_file *self) {
+struct lib9p_qid shutdown_file_qid(struct shutdown_file *self) {
assert(self);
return (struct lib9p_qid){
.type = LIB9P_QT_FILE | LIB9P_QT_APPEND,
@@ -30,7 +29,7 @@ static struct lib9p_qid shutdown_file_qid(struct shutdown_file *self) {
};
}
-static lib9p_srv_stat_or_error shutdown_file_stat(struct shutdown_file *self, struct lib9p_srv_ctx *ctx) {
+lib9p_srv_stat_or_error shutdown_file_stat(struct shutdown_file *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
return ERROR_NEW_VAL(lib9p_srv_stat, ((struct lib9p_srv_stat){
@@ -46,20 +45,20 @@ static lib9p_srv_stat_or_error shutdown_file_stat(struct shutdown_file *self, st
.extension = lib9p_str(NULL),
}));
}
-static error shutdown_file_wstat(struct shutdown_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) {
+error shutdown_file_wstat(struct shutdown_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) {
assert(self);
assert(ctx);
return error_new(E_POSIX_EROFS, "cannot wstat API file");
}
-static error shutdown_file_remove(struct shutdown_file *self, struct lib9p_srv_ctx *ctx) {
+error shutdown_file_remove(struct shutdown_file *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
return error_new(E_POSIX_EROFS, "cannot remove API file");
}
-LIB9P_SRV_NOTDIR(struct shutdown_file, shutdown_file);
+LIB9P_SRV_NOTDIR(, struct shutdown_file, shutdown_file);
-static lib9p_srv_fio_or_error shutdown_file_fopen(struct shutdown_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) {
+lib9p_srv_fio_or_error shutdown_file_fopen(struct shutdown_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) {
assert(self);
assert(ctx);
@@ -76,7 +75,7 @@ static void shutdown_fio_iofree(struct shutdown_fio *self) {
free(self);
}
-static struct lib9p_qid shutdown_fio_qid(struct shutdown_fio *self) {
+static struct lib9p_qid shutdown_fio_ioqid(struct shutdown_fio *self) {
assert(self);
return shutdown_file_qid(self->parent);
}
@@ -97,7 +96,7 @@ static uint32_t_or_error shutdown_fio_pwrite(struct shutdown_fio *self, struct l
LO_CALL(LO_BOX(net_stream_listener, &self->parent->listeners[i]), close);
return ERROR_NEW_VAL(uint32_t, byte_count);
}
-static iovec_or_error shutdown_fio_pread(struct shutdown_fio *LM_UNUSED(self), struct lib9p_srv_ctx *LM_UNUSED(ctx),
- uint32_t LM_UNUSED(byte_count), uint64_t LM_UNUSED(byte_offset)) {
+static error shutdown_fio_pread(struct shutdown_fio *LM_UNUSED(self), struct lib9p_srv_ctx *LM_UNUSED(ctx),
+ lo_interface io_writer LM_UNUSED(dst), uint64_t LM_UNUSED(src_offset), uint32_t LM_UNUSED(count)) {
assert_notreached("not readable");
}
diff --git a/lib9p/tests/test_server/fs_whoami.c b/lib9p/tests/test_server/fs_whoami.c
index 3cc0683..5a8382a 100644
--- a/lib9p/tests/test_server/fs_whoami.c
+++ b/lib9p/tests/test_server/fs_whoami.c
@@ -12,15 +12,14 @@
#include "fs_whoami.h"
-LO_IMPLEMENTATION_C(lib9p_srv_file, struct whoami_file, whoami_file, static);
+LO_IMPLEMENTATION_C(lib9p_srv_file, struct whoami_file, whoami_file);
struct whoami_fio {
struct whoami_file *parent;
size_t buf_len;
char *buf;
};
-LO_IMPLEMENTATION_H(lib9p_srv_fio, struct whoami_fio, whoami_fio);
-LO_IMPLEMENTATION_C(lib9p_srv_fio, struct whoami_fio, whoami_fio, static);
+LO_IMPLEMENTATION_STATIC(lib9p_srv_fio, struct whoami_fio, whoami_fio);
size_t whoami_len(struct lib9p_srv_ctx *ctx) {
assert(ctx);
@@ -41,10 +40,10 @@ size_t whoami_len(struct lib9p_srv_ctx *ctx) {
/* srv_file *******************************************************************/
-static void whoami_file_free(struct whoami_file *self) {
+void whoami_file_free(struct whoami_file *self) {
assert(self);
}
-static struct lib9p_qid whoami_file_qid(struct whoami_file *self) {
+struct lib9p_qid whoami_file_qid(struct whoami_file *self) {
assert(self);
return (struct lib9p_qid){
.type = LIB9P_QT_FILE,
@@ -53,7 +52,7 @@ static struct lib9p_qid whoami_file_qid(struct whoami_file *self) {
};
}
-static lib9p_srv_stat_or_error whoami_file_stat(struct whoami_file *self, struct lib9p_srv_ctx *ctx) {
+lib9p_srv_stat_or_error whoami_file_stat(struct whoami_file *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
@@ -70,20 +69,20 @@ static lib9p_srv_stat_or_error whoami_file_stat(struct whoami_file *self, struct
.extension = lib9p_str(NULL),
}));
}
-static error whoami_file_wstat(struct whoami_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) {
+error whoami_file_wstat(struct whoami_file *self, struct lib9p_srv_ctx *ctx, struct lib9p_srv_stat) {
assert(self);
assert(ctx);
return error_new(E_POSIX_EROFS, "cannot wstat API file");
}
-static error whoami_file_remove(struct whoami_file *self, struct lib9p_srv_ctx *ctx) {
+error whoami_file_remove(struct whoami_file *self, struct lib9p_srv_ctx *ctx) {
assert(self);
assert(ctx);
return error_new(E_POSIX_EROFS, "cannot remove API file");
}
-LIB9P_SRV_NOTDIR(struct whoami_file, whoami_file);
+LIB9P_SRV_NOTDIR(, struct whoami_file, whoami_file);
-static lib9p_srv_fio_or_error whoami_file_fopen(struct whoami_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) {
+lib9p_srv_fio_or_error whoami_file_fopen(struct whoami_file *self, struct lib9p_srv_ctx *ctx, bool, bool, bool) {
assert(self);
assert(ctx);
@@ -104,7 +103,7 @@ static void whoami_fio_iofree(struct whoami_fio *self) {
free(self);
}
-static struct lib9p_qid whoami_fio_qid(struct whoami_fio *self) {
+static struct lib9p_qid whoami_fio_ioqid(struct whoami_fio *self) {
assert(self);
assert(self->parent);
return whoami_file_qid(self->parent);
@@ -121,8 +120,8 @@ static uint32_t_or_error whoami_fio_pwrite(struct whoami_fio *LM_UNUSED(self),
uint64_t LM_UNUSED(offset)) {
assert_notreached("not writable");
}
-static iovec_or_error whoami_fio_pread(struct whoami_fio *self, struct lib9p_srv_ctx *ctx,
- uint32_t byte_count, uint64_t byte_offset) {
+static error whoami_fio_pread(struct whoami_fio *self, struct lib9p_srv_ctx *ctx,
+ lo_interface io_writer dst, uint64_t byte_offset, uint32_t byte_count) {
assert(self);
assert(ctx);
@@ -135,15 +134,12 @@ static iovec_or_error whoami_fio_pread(struct whoami_fio *self, struct lib9p_srv
ctx->user->num, ctx->user->name.len, ctx->user->name.utf8);
if (byte_offset > (uint64_t)data_size)
- return ERROR_NEW_ERR(iovec, error_new(E_POSIX_EINVAL, "offset is past end-of-file length"));
+ return error_new(E_POSIX_EINVAL, "offset is past end-of-file length");
size_t beg_off = (size_t)byte_offset;
size_t end_off = beg_off + (size_t)byte_count;
if (end_off > data_size)
end_off = data_size;
- return ERROR_NEW_VAL(iovec, ((struct iovec){
- .iov_base = &self->buf[beg_off],
- .iov_len = end_off-beg_off,
- }));
+ return io_write(dst, &self->buf[beg_off], end_off-beg_off).err;
}
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c
index e28d19e..2519372 100644
--- a/lib9p/tests/test_server/main.c
+++ b/lib9p/tests/test_server/main.c
@@ -132,8 +132,7 @@ static COROUTINE init_cr(void *) {
}
struct tstlog_stdout {};
-LO_IMPLEMENTATION_H(fmt_dest, struct tstlog_stdout, tstlog_stdout);
-LO_IMPLEMENTATION_C(fmt_dest, struct tstlog_stdout, tstlog_stdout, static);
+LO_IMPLEMENTATION_STATIC(fmt_dest, struct tstlog_stdout, tstlog_stdout);
static size_t tstlog_bytes = 0;