commit b75a414686da42330f0c7951203c9be52ff66928
parent 4ee4902d9038772b174405b2b3824acdb7b2a534
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sun, 7 Mar 2021 21:32:52 +0000
fs.c: something useable for async IO on stream file
Diffstat:
M | fs.c | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++------------ |
1 file changed, 53 insertions(+), 12 deletions(-)
diff --git a/fs.c b/fs.c
@@ -4,11 +4,41 @@
#include <thread.h>
#include <9p.h>
+/* TODO: possible replace these with enum in file->aux and switch
+ statement instead of if/else in fsread/fswrite */
+
+File *Fdata;
+File *Fstream;
+Channel *c;
+
+void
+procrespond(void*)
+{
+ Req *r;
+ r = nil;
+ while (recv(c, &r) == 1) {
+ assert(r != nil);
+ respond(r, nil);
+ sleep(5000);
+ }
+}
+
void
fsread(Req *r)
{
-
- respond(r, nil);
+ File *f;
+ f = r->fid->file;
+ if (f == Fdata) {
+ readstr(r, "data\n");
+ respond(r, nil);
+ } else if (f == Fstream) {
+ fprint(2, "stream read\n");
+ readstr(r, "stream\n");
+ send(c, &r);
+ }
+ else {
+ respond(r, "unidentified file");
+ }
}
void
@@ -18,14 +48,28 @@ fswrite(Req *r)
}
void
+fsflush(Req *r)
+{
+ fprint(2, "flush\n");
+ respond(r->oldreq, "when does flush happen?");
+ respond(r, nil);
+}
+
+void
usage(void)
{
fprint(2, "usage: %s [-D][-m /mnt/octree][-s service]\n", argv0);
- exits("usage");
+ threadexits("usage");
}
+Srv fs = {
+ .read = fsread,
+ .write = fswrite,
+ .flush = fsflush,
+};
+
void
-main (int argc, char **argv)
+threadmain (int argc, char **argv)
{
char *srv, *mtpt;
srv = nil;
@@ -45,14 +89,11 @@ main (int argc, char **argv)
usage();
}ARGEND
if (argc > 0) usage();
- Srv fs = {
- .tree = alloctree("octree", "octree", 0777|DMDIR, nil),
- .read = fsread,
- .write = fswrite,
- };
- File *Fdata;
- File *Fstream;
+ c = chancreate(sizeof(Req*), 1024);
+ fs.tree = alloctree("octree", "octree", 0777|DMDIR, nil),
Fdata = createfile(fs.tree->root, "data", "octree", 0666, nil);
Fstream = createfile(fs.tree->root, "stream", "octree", 0666, nil);
- postmountsrv(&fs, srv, mtpt, MREPL);
+ fprint(2, "launching threadpostmountsrv\n");
+ proccreate(procrespond, nil, 1024 * 8);
+ threadpostmountsrv(&fs, srv, mtpt, MREPL);
}