Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 45 lines (35 sloc) 1.16 kB
5f35f5b @vinoski add streamcontent_from_pid capability to allow direct streaming to so…
vinoski authored
1
2 <erl>
3
4 out(A) ->
5 %% Create a random number
6 {_A1, A2, A3} = now(),
7 random:seed(erlang:phash(node(), 100000),
8 erlang:phash(A2, A3),
9 A3),
10 Sz = random:uniform(100000),
11
12 Pid = spawn(fun() ->
13 %% Read random junk
14 S="dd if=/dev/urandom count=1 bs=" ++
15 integer_to_list(Sz) ++ " 2>/dev/null",
16 P = open_port({spawn, S}, [binary,stream, eof]),
17 rec_loop(A#arg.clisock, P)
18 end),
19
20 [{header, {content_length, Sz}},
21 {streamcontent_from_pid, "application/octet-stream", Pid}].
22
23
24 rec_loop(Sock, P) ->
25 receive
26 {discard, YawsPid} ->
27 yaws_api:stream_process_end(Sock, YawsPid);
28 {ok, YawsPid} ->
29 rec_loop(Sock, YawsPid, P)
30 end,
31 port_close(P),
32 exit(normal).
33
34 rec_loop(Sock, YawsPid, P) ->
35 receive
36 {P, {data, BinData}} ->
37 yaws_api:stream_process_deliver(Sock, BinData),
38 rec_loop(Sock, YawsPid, P);
39 {P, eof} ->
40 yaws_api:stream_process_end(Sock, YawsPid)
41 end.
42
43 </erl>
44
Something went wrong with that request. Please try again.