forked from erlyaws/yaws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurandom.yaws
38 lines (28 loc) · 971 Bytes
/
urandom.yaws
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
<erl>
out(A) ->
Self = self(),
spawn(fun() ->
%% Create a random number
{_A1, A2, A3} = now(),
random:seed(erlang:phash(node(), 100000),
erlang:phash(A2, A3),
A3),
Sz = random:uniform(100000),
%% Read random junk
S="dd if=/dev/urandom count=1 bs=" ++
integer_to_list(Sz) ++ " 2>/dev/null",
P = open_port({spawn, S}, [binary,stream, eof]),
rec_loop(Self, P)
end),
{streamcontent, "application/octet-stream", <<>>}.
rec_loop(YawsPid, P) ->
receive
{P, {data, BinData}} ->
yaws_api:stream_chunk_deliver(YawsPid, BinData),
rec_loop(YawsPid, P);
{P, eof} ->
port_close(P),
yaws_api:stream_chunk_end(YawsPid),
exit(normal)
end.
</erl>