summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2017-05-20 21:14:12 -0700
committerOri Bernstein <ori@eigenstate.org>2017-05-20 21:14:12 -0700
commita142a54300c42ed98e21fbcfd4b0cbff1706f49f (patch)
treedee3e619cc329ad5f4451c895af68b032f56fda2
parentf247b6c460cb00e149434174dbd2b8be32a771e9 (diff)
downloadmc-poller.tar.gz
Add fd mux prototype.poller
-rw-r--r--lib/std/bld.sub1
-rw-r--r--lib/std/muxfd+posixy.myr61
2 files changed, 62 insertions, 0 deletions
diff --git a/lib/std/bld.sub b/lib/std/bld.sub
index 4b687b6..f2aec53 100644
--- a/lib/std/bld.sub
+++ b/lib/std/bld.sub
@@ -111,6 +111,7 @@ lib std {inc=.} =
resolve+posixy.myr
wait+plan9.myr
wait+posixy.myr
+ muxfd+posixy.myr
# relatively generic syscall wrappers
syswrap+plan9.myr
diff --git a/lib/std/muxfd+posixy.myr b/lib/std/muxfd+posixy.myr
new file mode 100644
index 0000000..8e88589
--- /dev/null
+++ b/lib/std/muxfd+posixy.myr
@@ -0,0 +1,61 @@
+use sys
+
+use "alloc"
+use "mk"
+use "syswrap"
+use "types"
+use "slpush"
+
+pkg std =
+ type muxflag = int32
+ type fdmux = struct
+ pollfd : sys.pollfd[:]
+ ;;
+
+ const Muxread : muxflag = 1<<0
+ const Muxwrite : muxflag = 1<<1
+ const Forever : time = 0
+
+ const mkmux : (-> fdmux#)
+ const freemux : (w : fdmux# -> void)
+ const muxfd : (w : fdmux#, fd : fd, flg : muxflag -> void)
+ const muxwait : (w : fdmux#, tm : time -> void)
+;;
+
+const mkmux = {
+ -> std.mk([
+ .pollfd = [][:]
+ ])
+}
+
+const freemux = {w
+ std.slfree(w.pollfd)
+ std.free(w)
+}
+
+const muxfd = {w, fd, flg
+ var evt
+
+ evt = 0
+ if flg & Muxread != 0
+ sys.write(1, "reading\n")
+ evt |= sys.Pollin
+ ;;
+ if flg & Muxwrite != 0
+ evt |= sys.Pollout
+ ;;
+ std.slpush(&w.pollfd, [.fd=(fd : sys.fd), .events=evt, .revents=0])
+}
+
+const muxwait = {w, tm
+ var sl, ms
+
+ sl = (&tm : byte#)[:8]
+ if tm < 0
+ ms = -1
+ else
+ ms = (tm / 1000 : int)
+ ;;
+ sys.poll(w.pollfd, ms)
+}
+