summaryrefslogtreecommitdiff
path: root/cmd/srv9p/main.c
blob: f62617dfa1f401f908c92de2e6259504f9959ae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <error.h>
#include <stdio.h>

#include <libcr/coroutine.h>
#include <libnetio/netio.h>
#include <lib9p/srv.h>

#include "static.h"

#define USE_CONFIG_COROUTINE
#include "config.h"

#define UNUSED(name) /* name __attribute__((unused)) */

static struct static_dir_data root = {
	.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    = "",
	.perm    = 0555,
	.atime   = 1728337904,
	.mtime   = 1728337904,

	.members = {
		NULL,
	},
};

struct lib9p_srv_file fs_root(struct lib9p_srv_ctx *UNUSED(ctx), char *UNUSED(treename)) {
	return (struct lib9p_srv_file){
		.vtable   = static_dir_vtable,
		.impldata = &root,
	};
}

int main() {
	int sock = netio_listen(9000);
	if (sock < 0)
		error(1, -sock, "netio_listen");

	struct lib9p_srv srv = {
		.sockfd  = sock,
		.rootdir = fs_root,
	};

	for (int i = 0; i < CONFIG_NETIO_NUM_CONNS; i++)
		if (!coroutine_add(lib9p_srv_read_cr, &srv))
			error(1, 0, "coroutine_add(lib9p_srv_read_cr, &srv)");
	for (int i = 0; i < 2*CONFIG_NETIO_NUM_CONNS; i++)
		if (!coroutine_add(lib9p_srv_write_cr, &srv))
			error(1, 0, "coroutine_add(lib9p_srv_write_cr, &srv)");

	coroutine_main();
	return 1;
}