summaryrefslogtreecommitdiff
path: root/cmd/srv9p/main.c
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-11 23:33:44 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-11 23:33:44 -0700
commit7eda822ef31a15d22de03fc1eec7d995f661b26d (patch)
tree0f00fdf307cfa78337c50a43e2ff842942922af5 /cmd/srv9p/main.c
parent8573ec62fe175edc73c6c54d24e520ee6aba3f96 (diff)
parentd29cb3f3deda2ae55fbccfdaae3b2481410a0894 (diff)
Merge branch 'lukeshu/9p-tests'
Diffstat (limited to 'cmd/srv9p/main.c')
-rw-r--r--cmd/srv9p/main.c129
1 files changed, 0 insertions, 129 deletions
diff --git a/cmd/srv9p/main.c b/cmd/srv9p/main.c
deleted file mode 100644
index b5cb122..0000000
--- a/cmd/srv9p/main.c
+++ /dev/null
@@ -1,129 +0,0 @@
-/* srv9p/main.c - Main entry point for test 9P server
- *
- * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com>
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-
-#include <error.h>
-
-#include <lib9p/srv.h>
-#include <libcr/coroutine.h>
-#include <libhw/generic/net.h>
-#include <libhw/generic/alarmclock.h>
-#include <libhw/host_net.h>
-#include <libmisc/macro.h>
-#include <util9p/static.h>
-
-#include "static.h"
-
-/* configuration **************************************************************/
-
-#include "config.h"
-
-#ifndef CONFIG_SRV9P_NUM_CONNS
- #error config.h must define CONFIG_SRV9P_NUM_CONNS
-#endif
-
-/* implementation *************************************************************/
-
-/* file tree ******************************************************************/
-
-#define FILE_COMMON(NAME) { \
- .vtable = &util9p_static_file_vtable, \
- \
- .u_name = "root", .u_num = 0, /* owner user */ \
- .g_name = "root", .g_num = 0, /* owner group */ \
- .m_name = "root", .m_num = 0, /* last-modified-by user */ \
- \
- .pathnum = __COUNTER__, \
- .name = NAME, \
- .perm = 0444, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
-
-#define DIR_COMMON(NAME) { \
- .vtable = &util9p_static_dir_vtable, \
- \
- .u_name = "root", .u_num = 0, /* owner user */ \
- .g_name = "root", .g_num = 0, /* owner group */ \
- .m_name = "root", .m_num = 0, /* last-modified-by user */ \
- \
- .pathnum = __COUNTER__, \
- .name = NAME, \
- .perm = 0555, \
- .atime = 1728337905, \
- .mtime = 1728337904, \
- }
-
-#define STATIC_FILE(STRNAME, SYMNAME) \
- &((static struct util9p_static_file){ \
- ._util9p_static_common = FILE_COMMON(STRNAME), \
- .data_start = _binary_static_##SYMNAME##_start, \
- .data_end = _binary_static_##SYMNAME##_end, \
- })
-
-static struct util9p_static_dir root = {
- ._util9p_static_common = DIR_COMMON(""),
- .members = {
- &((static struct util9p_static_dir){
- ._util9p_static_common = DIR_COMMON("Documentation"),
- .members = {
- STATIC_FILE("x", Documentation_x),
- NULL
- },
- }),
- STATIC_FILE("README.md", README_md),
- NULL,
- },
-};
-
-static implements_lib9p_srv_file *get_root(struct lib9p_srv_ctx *LM_UNUSED(ctx), char *LM_UNUSED(treename)) {
- return &root;
-}
-
-/* main ***********************************************************************/
-
-static COROUTINE read_cr(void *_srv) {
- struct lib9p_srv *srv = _srv;
- assert(srv);
-
- cr_begin();
-
- struct hostnet_tcp_listener listener;
- hostnet_tcp_listener_init(&listener, 9000);
-
- lib9p_srv_read_cr(srv, &listener);
-
- cr_end();
-}
-
-const char *hexdig = "0123456789abcdef";
-
-struct lib9p_srv srv = {
- .rootdir = get_root,
-};
-
-static COROUTINE init_cr(void *) {
- cr_begin();
-
- for (int i = 0; i < CONFIG_SRV9P_NUM_CONNS; i++) {
- char name[] = {'r', 'e', 'a', 'd', '-', hexdig[i], '\0'};
- if (!coroutine_add(name, read_cr, &srv))
- error(1, 0, "coroutine_add(read_cr, &srv)");
- sleep_for_s(1);
- }
- for (int i = 0; i < 2*CONFIG_SRV9P_NUM_CONNS; i++) {
- char name[] = {'w', 'r', 'i', 't', 'e', '-', hexdig[i], '\0'};
- if (!coroutine_add(name, lib9p_srv_write_cr, &srv))
- error(1, 0, "coroutine_add(lib9p_srv_write_cr, &srv)");
- sleep_for_s(1);
- }
-
- cr_exit();
-}
-
-int main() {
- coroutine_add("init", init_cr, NULL);
- coroutine_main();
-}