Inspired by some Comet-related messages I've seen here lately, I added a feature to Yaws over the weekend that allows you to stream content from an application process. This is somewhat different from the current streaming capabilities, where delivery is always HTTP chunked mode transfer. With the new capability, you can do either direct writes to the socket of non-chunked data or still send chunked data, as you wish.
If you return {streamcontent_from_pid, MimeType, Pid} from your out/1 function, it tells yaws that process Pid wants to write to the client socket. Yaws does some housekeeping and then sends a message to Pid, either {ok, YawsPid} to inform it that it can start delivering data, or {discard, YawsPid} to tell it that it should not send any data (for example, if the request was a HEAD request, there's no response body needed). From then Pid can call yaws_api:stream_process_deliver(Socket, IoList) to send data to the socket for non-chunked delivery, which basically just calls gen_tcp:send, or it can call yaws_api:stream_process_deliver_chunk(Socket, IoList) for chunked transfer, and yaws will do all the HTTP chunk formatting. If performing chunked transfer, Pid has to call yaws_api:stream_process_deliver_final_chunk(Socket, IoList) at the end so that yaws knows to send the final chunk as required by HTTP. When Pid has finished with the socket (even for the discard case), it must call yaws_api:stream_process_end(Socket, YawsPid) to let yaws know that it's finished with the socket. YawsPid refers to what yaws sent to Pid in its initial message as described above. The app gets Socket from Arg#arg.clisock.
Related to Comet, in this mode yaws will just hang out waiting for Pid to call stream_process_end/2, which means Pid essentially controls the connection lifetime and can send data down the connection whenever it wants to during that time.
It's all on trunk now on github, and it's all documented in the yaws PDF file as well as in the examples and man pages. If you have any interest in this feature, please kick the tires and send along any feedback you might have.
--steve
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf_______________________________________________
Erlyaws-list mailing list
Erlyaws-list@...
https://lists.sourceforge.net/lists/listinfo/erlyaws-list