-
Notifications
You must be signed in to change notification settings - Fork 13
/
io.t
52 lines (43 loc) · 1.36 KB
/
io.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
(use io test)
(= tcp-test-port* 50013)
(def tcp-connect (host port)
(ail-code "(racket-let-values (((i o) (racket-tcp-connect host port)))
(list i o))"))
(with (ready (make-semaphore)
their-ip nil
the-client-ip nil)
(thread
;; todo would like to catch errors here
(w/socket s tcp-test-port*
(racket-semaphore-post ready)
(let (i o ip) (socket-accept s)
(= their-ip ip)
(= the-client-ip (client-ip o))
(disp "foo" o)
(racket-flush-output o)
(close i o))))
(racket-semaphore-wait ready)
(testis (let (i o) (tcp-connect "127.0.0.1" tcp-test-port*)
(string (n-of 3 (readc i))))
"foo")
(testis their-ip "127.0.0.1")
(testis the-client-ip "127.0.0.1"))
(w/foofile
(testis (dir testdir) '()))
(w/testdir
(with (one (+ testdir "/one") two (+ testdir "/two"))
(system (+ "touch " one))
(system (+ "touch " two))
(testis (sort < (dir testdir)) '("one" "two"))))
(with (alive (make-semaphore)
done (make-semaphore))
(let th (thread (racket-semaphore-post alive)
(racket-semaphore-wait done))
(racket-semaphore-wait alive)
(testis (dead th) nil)
(racket-semaphore-post done)
(catch (repeat 5
(if (dead th) (throw nil))
(sleep 0.1))
(err "thread not dead"))
(prn "ok thread dead")))