ref: cdc922649bc14a2e25abd4593b244f36fffff1d0
parent: ca929c334fedc59fc1240b2c64b887082ef331f2
author: Noam Preil <noam@pixelhero.dev>
date: Thu Jul 4 17:07:18 EDT 2024
server: handle each client in a separate proc
--- a/notebook
+++ b/notebook
@@ -1155,3 +1155,46 @@
% dd -if /dev/jasnah/arenas -bs 1024 -count 8 -skip 248
that works. lol.
+
+Okay, config parsing is good. Let's fix multiclient support.
+
+With a foreground proc for handling, I - oh. This is why testing is important! neoventi shuts down on disconnect >_<
+
+Ohhhhh on vthangup we're bouncing() with 2 as the parameter, which triggers exits(). That was easy lmao.
+
+annnnd with that fixed it crashes on hangup with one thread, too!
+
+7.neoventi 55793: suicide: sys: trap: misaligned pc pc=0x5
+mk: ./7.neoventi -c /dev/jasnah/arenas : exit status=7.neoventi 55793:
+
+... huh.
+
+waiting for packet...Received 0 bytes!
+hanging up: unknown control request
+
+unknown control request is not a neoventi error, that's a driver error. Preeeetty sure it's just from the connection dropping, though. Probably. Maybe not.
+
+The trampoline appears to be going to the wrong place... the heck?
+
+inittrampoline calls setjmp(). The longjmp is correctly returning to that setjmp, but the return in inittrampoline is not returning to handleproc a second time??
+
+ Longjmp restores the environment saved by the last call of
+ setjmp. It then causes execution to continue as if the call
+ of setjmp had just returned with value val. The invoker of
+ setjmp must not itself have returned in the interim. All
+ accessible data have values as of the time longjmp was
+ called.
+The invoker of
+ setjmp must not itself have returned in the interim.
+
+ohhhh dumb. duuumb.
+
+manually inlining initrampoline() fixed that. Multithread??
+
+Yep!!! :D
+
+Technically works. Ish. So long as only one actually does anything at a time >_<
+
+Cache not locking right, maybe?
+
+Yep!
--- a/server.c
+++ b/server.c
@@ -17,6 +17,7 @@
msg = vsmprint(msg, args);
werrstr(msg);
free(msg);
+ fprint(2, "error: %r\n");
va_end(args);
if(tbuf != nil){
len = snprint(tbuf+6, 0x10000, "neoventi: %r");
@@ -171,38 +172,31 @@
}
}
-static int
-inittrampoline(VtConn *conn)
+static void
+handleproc(void *fd)
{
- switch(setjmp(conn->bounce)){
+ char buf[MaxPacketSize];
+ VtConn conn;
+ conn.fd = (int)(usize)fd;
+ switch(setjmp(conn.bounce)){
case 0:
- return 1;
+ vthello(conn, buf);
+ vtloop(conn, buf);
+ abort();
case 1:
fprint(2, "abandoning client: %r\n");
+ break;
case 2:
- exits(nil);
- return 0;
+ fprint(2, "hanging up: %r\n");
+ break;
default:
fprint(2, "internal error: unexpected bounce code\n");
- return 0;
+ break;
}
+ close(conn.fd);
}
static void
-handleproc(void *fd)
-{
- char buf[MaxPacketSize];
- VtConn conn;
- conn.fd = (int)(usize)fd;
- if(!inittrampoline(&conn)){
- close(conn.fd);
- return;
- }
- vthello(conn, buf);
- vtloop(conn, buf);
-}
-
-static void
handle(int ctl, char *dir)
{
int fd = accept(ctl, dir);
@@ -210,8 +204,7 @@
fprint(2, "failed to accept connection\n");
return;
}
- handleproc((void*)fd);
-// proccreate(handleproc, (void*)fd, mainstacksize);
+ proccreate(handleproc, (void*)fd, mainstacksize);
}
void