shithub: mc

Download patch

ref: f37c8970f11e21b0b6f29c4aac10f92101d0c906
parent: cdb2435ea25e9752a0b06f72fd699c46185bb7d1
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Apr 21 20:22:49 EDT 2017

Libhttp is now multithreaded.

--- a/lib/http/server.myr
+++ b/lib/http/server.myr
@@ -29,10 +29,10 @@
 }
 
 const serve = {srv
-	std.put("waiting for connection\n")
 	while true
 		match waitconn(srv)
-		| `std.Ok fd:	communicate(srv, fd)
+		| `std.Ok fd:	
+			thread.spawn({;communicate(srv, fd)})
 		| `std.Err e:	/* eh? */
 		;;
 	;;
@@ -47,7 +47,6 @@
 		| `std.Ok req:
 			dispatch(srv, s, req)
 		| `std.Err e:
-			std.put("failed to parse request: {}\n", e)
 			break
 		;;
 	;;
@@ -57,7 +56,6 @@
 const dispatch = {srv, sess, req
 	var resp : resp#
 
-	std.put("got req: {}\n", req)
 	resp = std.mk([
 		.status=200,
 		.hdrs = [][:],
@@ -64,7 +62,7 @@
 		.len = 0,
 		.err = `std.None,
 		.reason = "",
-		.body = "heard you loud and clear\n",
+		.body = "pong\n",
 		.enc = `Length
 	])
 	respond(srv, sess, resp)
--- a/lib/http/session.myr
+++ b/lib/http/session.myr
@@ -4,7 +4,7 @@
 use "types"
 
 pkg http =
-	const mksession		: (schema : schema, host : byte[:], port : int -> std.result(session#, err))
+	const mksession		: (schema : schema, host : byte[:], port : uint16 -> std.result(session#, err))
 	const mksrvsession	: (fd	: std.fd -> session#)
 	const freesession	: (s : session# -> void)
 
@@ -42,7 +42,7 @@
 	-> std.mk([
 		.err = false,
 		.srvname = std.sldup("Myrfoo HTTP Server"),
-		.f = bio.mkfile(fd, bio.Rw)
+		.f = bio.mkfile(fd, bio.Rw),
 	])
 }