Permalink
Browse files

support for streamed large content from yaws code

git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk/yaws@162 9fbdc01b-0d2c-0410-bfb7-fb27d70d8b52
  • Loading branch information...
1 parent 9309215 commit 1686c86a882a0c343c738b3a0731504bd332fcda @klacke committed Sep 13, 2002
Showing with 48 additions and 4 deletions.
  1. +2 −1 include/yaws_api.hrl
  2. +9 −0 src/yaws.erl
  3. +37 −3 src/yaws_server.erl
View
@@ -17,7 +17,8 @@
docroot, %% where's the data
fullpath, %% full path to yaws file
cont, %% Continuation for chunked multipart uploads
- state %% State for use by users of the out/1 callback
+ state, %% State for use by users of the out/1 callback
+ pid %% pid of the yaws process
}).
View
@@ -613,3 +613,12 @@ oct_to_dig([H|T], D) -> oct_to_dig(T, D*8 + H - $0).
printversion() ->
io:format("Yaws ~s~n", [yaws_vsn:version()]),
init:stop().
+
+
+
+stream_chunk_deliver(Arg, Data) ->
+ Arg#arg.pid ! {streamcontent, Data}.
+
+stream_chunk_end(Arg) ->
+ Arg#arg.pid ! endofstreamcontent.
+
View
@@ -358,7 +358,7 @@ gserv(GS, Ready, Rnum) ->
Rnum < 8 ->
gserv(GS2, [From | Ready], Rnum+1)
end;
- {'EXIT', Pid, _} ->
+ {'EXIT', _Pid, _} ->
gserv(GS, Ready, Rnum)
end.
@@ -810,6 +810,7 @@ make_arg(CliSock, Head, Req, _GC, SC) ->
#arg{clisock = CliSock,
headers = Head,
req = Req,
+ pid = self(),
docroot = SC#sconf.docroot}.
handle_request(CliSock, GC, SC, Req, H, ARG, N) ->
@@ -1087,6 +1088,22 @@ deliver_dyn_file(CliSock, GC, SC, Req, Head, UT, DCC, Bin, Fd, [H|T],ARG,N) ->
break ->
deliver_dyn_file(CliSock, GC, SC, Req, Head,
UT, DCC, Bin, Fd, [],ARG,N) ;
+
+ {streamcontent, MimeType, FirstChunk} ->
+ put(content_type, MimeType),
+ accumulate_chunk(DCC, FirstChunk),
+ set_status_code(200),
+ deliver_accumulated(DCC, CliSock, GC, SC),
+ put(stream, true),
+ stream_loop(DCC, CliSock, GC, SC),
+ case DCC#dcc.chunked of
+ true ->
+ gen_tcp_send(CliSock, [crnl(), "0", crnl2()], GC,SC),
+ continue;
+ false ->
+ done
+ end;
+
_ ->
deliver_dyn_file(CliSock, GC, SC, Req, Head,
UT, DCC, Bin2,Fd,T,ARG,0)
@@ -1130,6 +1147,19 @@ deliver_dyn_file(CliSock, GC, SC, _Req, _Head,_UT, DCC, _Bin, _Fd, [], _ARG,_N)
Ret.
+
+stream_loop(DCC, CliSock, GC, SC) ->
+ receive
+ {streamcontent, Cont} ->
+ accumulate_chunk(DCC, Cont),
+ gen_tcp_send(CliSock, erase(acc_content), SC, GC),
+ stream_loop(DCC, CliSock, GC, SC) ;
+ endofstreamcontent ->
+ ok
+ end.
+
+
+
%% what about trailers ??
skip_data(List, Fd, Sz) when list(List) ->
@@ -1211,14 +1241,18 @@ handle_out_reply({html, Html}, DCC, _LineNo, _YawsFile, _SC, _A) ->
handle_out_reply({ehtml, E}, DCC, _LineNo, _YawsFile, _SC, _A) ->
accumulate_chunk(DCC, safe_ehtml_expand(E));
-handle_out_reply({content, MimeType, Cont}, DCC, _LineNo, _YawsFile, _SC, _A) ->
+handle_out_reply({content, MimeType, Cont}, DCC, _LineNo,_YawsFile, _SC, _A) ->
put(content_type, MimeType),
accumulate_chunk(DCC, Cont);
+handle_out_reply({streamcontent, MimeType, First},
+ _DCC, _LineNo,_YawsFile, _SC, _A) ->
+ {streamcontent, MimeType, First};
+
+
handle_out_reply({header, H}, _DCC, _LineNo, _YawsFile, _SC, _A) ->
accumulate_header(H);
-
handle_out_reply({allheaders, Hs}, _DCC, _LineNo, _YawsFile, _SC, _A) ->
erase(acc_headers),
lists:foreach(fun({header, Head}) -> accumulate_header(Head) end, Hs);

0 comments on commit 1686c86

Please sign in to comment.