summaryrefslogtreecommitdiff
path: root/lib/http/server.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-08-27 16:11:12 -0700
committerOri Bernstein <ori@eigenstate.org>2016-08-27 16:11:12 -0700
commitf6e16f0c9f8d68a66c279059e4185d79a5b665a0 (patch)
tree3da24808759e35316c7d0ff35a786ebdc395efc5 /lib/http/server.myr
parent1d4f6a7925c05705dda39c9fe799c64138d6d02a (diff)
downloadmc-f6e16f0c9f8d68a66c279059e4185d79a5b665a0.tar.gz
Update to new APIs.
Diffstat (limited to 'lib/http/server.myr')
-rw-r--r--lib/http/server.myr37
1 files changed, 35 insertions, 2 deletions
diff --git a/lib/http/server.myr b/lib/http/server.myr
index 0b71c63..6e1aa4c 100644
--- a/lib/http/server.myr
+++ b/lib/http/server.myr
@@ -1,9 +1,42 @@
use std
+use "types"
+
pkg http =
- const announce : (ds : byte[:] -> void)
+ const announce : (ds : byte[:] -> std.result(server#, err))
+ const shutdown : (srv : server# -> void)
+
+ const waitconn : (srv : server# -> std.result(std.fd, err))
+// const readmsg : (srv : server# -> std.option(req#, err))
+// const writemsg : (srv : server# -> std.option(req#, err))
+// const writehdr : (srv : server# -> std.option(req#, err))
;;
const announce = {ds
- std.fatal("announce not yet implemented\n")
+ var afd
+
+ match std.announce(ds)
+ | `std.Ok f: afd = f
+ | `std.Err e: -> `std.Err `Econn
+ ;;
+
+ match std.listen(afd)
+ | `std.Err e: -> `std.Err `Econn
+ | `std.Ok lfd:
+ std.close(afd)
+ -> `std.Ok std.mk([.lfd=lfd])
+ ;;
+}
+
+const shutdown = {srv
+ std.close(srv.lfd)
}
+
+
+const waitconn = {srv
+ match std.accept(srv.lfd)
+ | `std.Ok afd: -> `std.Ok afd
+ | `std.Err e: -> `std.Err `Econn
+ ;;
+}
+