ref: a0e37090b748a9c271dca0d8d972ef61037837d7
parent: 772a5f13549c953b509f0b61448bf162c03cee44
author: Noam Preil <noam@pixelhero.dev>
date: Thu Jul 4 18:05:52 EDT 2024
server: revert multithreading fix. buggy.
--- a/server.c
+++ b/server.c
@@ -17,7 +17,6 @@
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");
@@ -172,31 +171,38 @@
}
}
-static void
-handleproc(void *fd)
+static int
+inittrampoline(VtConn *conn)
{
- char buf[MaxPacketSize];
- VtConn conn;
- conn.fd = (int)(usize)fd;
- switch(setjmp(conn.bounce)){
+ switch(setjmp(conn->bounce)){
case 0:
- vthello(conn, buf);
- vtloop(conn, buf);
- abort();
+ return 1;
case 1:
fprint(2, "abandoning client: %r\n");
- break;
case 2:
- fprint(2, "hanging up: %r\n");
- break;
+ exits(nil);
+ return 0;
default:
fprint(2, "internal error: unexpected bounce code\n");
- break;
+ return 0;
}
- 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);
@@ -204,7 +210,8 @@
fprint(2, "failed to accept connection\n");
return;
}
- proccreate(handleproc, (void*)fd, mainstacksize);
+ handleproc((void*)fd);
+// proccreate(handleproc, (void*)fd, mainstacksize);
}
void