summaryrefslogtreecommitdiff
path: root/lib9p/tests/test_server/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib9p/tests/test_server/main.c')
-rw-r--r--lib9p/tests/test_server/main.c33
1 files changed, 18 insertions, 15 deletions
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c
index f2a73bf..0431c40 100644
--- a/lib9p/tests/test_server/main.c
+++ b/lib9p/tests/test_server/main.c
@@ -5,10 +5,13 @@
*/
#include <errno.h>
-#include <error.h>
#include <stdio.h>
#include <stdlib.h> /* for atoi() */
+#define error __error
+#include <error.h>
+#undef error
+
#include <lib9p/srv.h>
#include <libcr/coroutine.h>
#include <libhw/generic/alarmclock.h>
@@ -36,7 +39,7 @@
/* globals ********************************************************************/
-static lo_interface lib9p_srv_file get_root(struct lib9p_srv_ctx *, struct lib9p_s);
+static lib9p_srv_file_or_error get_root(struct lib9p_srv_ctx *, struct lib9p_s);
static const char *hexdig = "0123456789abcdef";
@@ -60,11 +63,11 @@ static struct {
#define STATIC_DIR(N, STRNAME, ...) \
UTIL9P_STATIC_DIR(N, STRNAME, __VA_ARGS__)
-#define API_FILE(N, STRNAME, SYMNAME, ...) \
- lo_box_##SYMNAME##_file_as_lib9p_srv_file(&((struct SYMNAME##_file){ \
- .name = STRNAME, \
- .pathnum = N \
- __VA_OPT__(,) __VA_ARGS__ \
+#define API_FILE(N, STRNAME, SYMNAME, ...) \
+ LO_BOX(lib9p_srv_file, &((struct SYMNAME##_file){ \
+ .name = STRNAME, \
+ .pathnum = N \
+ __VA_OPT__(,) __VA_ARGS__ \
}))
static struct lib9p_srv_file root =
@@ -84,8 +87,8 @@ static struct lib9p_srv_file root =
API_FILE(13, "flush-slowread", flush, .flush_cnt=0, .flush_behavior=FLUSH_READ),
);
-static lo_interface lib9p_srv_file get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), struct lib9p_s LM_UNUSED(treename)) {
- return root;
+static lib9p_srv_file_or_error get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), struct lib9p_s LM_UNUSED(treename)) {
+ return ERROR_NEW_VAL(lib9p_srv_file, root);
}
/* main ***********************************************************************/
@@ -96,7 +99,7 @@ static COROUTINE read_cr(void *_i) {
hostnet_tcp_listener_init(&globals.listeners[i], globals.port);
- lib9p_srv_accept_and_read_loop(&globals.srv, lo_box_hostnet_tcplist_as_net_stream_listener(&globals.listeners[i]));
+ lib9p_srv_accept_and_read_loop(&globals.srv, LO_BOX(net_stream_listener, &globals.listeners[i]));
cr_end();
}
@@ -117,12 +120,12 @@ static COROUTINE init_cr(void *) {
for (int i = 0; i < _CONFIG_9P_MAX_CONNS; i++) {
char name[] = {'r', 'e', 'a', 'd', '-', hexdig[i], '\0'};
if (!coroutine_add(name, read_cr, &i))
- error(1, 0, "coroutine_add(read_cr, &i)");
+ __error(1, 0, "coroutine_add(read_cr, &i)");
}
for (int i = 0; i < _CONFIG_9P_MAX_REQS; i++) {
char name[] = {'w', 'r', 'i', 't', 'e', '-', hexdig[i], '\0'};
if (!coroutine_add(name, write_cr, NULL))
- error(1, 0, "coroutine_add(write_cr, NULL)");
+ __error(1, 0, "coroutine_add(write_cr, NULL)");
}
cr_exit();
@@ -153,18 +156,18 @@ static void tstlog_msg(struct lib9p_srv_ctx *ctx, enum lib9p_msg_type typ, void
int main(int argc, char *argv[]) {
if (argc != 3)
- error(2, 0, "usage: %s PORT_NUMBER LOGFILE", argv[0]);
+ __error(2, 0, "usage: %s PORT_NUMBER LOGFILE", argv[0]);
globals.port = atoi(argv[1]);
globals.logstream = fopen(argv[2], "w");
if (!globals.logstream)
- error(2, errno, "fopen");
+ __error(2, errno, "fopen");
globals.srv.msglog = tstlog_msg;
struct hostclock clock_monotonic = {
.clock_id = CLOCK_MONOTONIC,
};
- bootclock = lo_box_hostclock_as_alarmclock(&clock_monotonic);
+ bootclock = LO_BOX(alarmclock, &clock_monotonic);
coroutine_add("init", init_cr, NULL);
coroutine_main();
fclose(globals.logstream);