From a738db07c2040461f0fd431f04ecf90b157ead5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Thu, 9 Apr 2015 23:13:57 +0300 Subject: Add gun_up and gun_down messages The flush(Pid) function was enhanced to also discard Websocket messages and the new up/down messages. --- src/gun_http.erl | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/gun_http.erl') diff --git a/src/gun_http.erl b/src/gun_http.erl index 8b176fe..d6a69d1 100644 --- a/src/gun_http.erl +++ b/src/gun_http.erl @@ -15,6 +15,7 @@ -module(gun_http). -export([check_options/1]). +-export([name/0]). -export([init/4]). -export([handle/2]). -export([close/1]). @@ -23,6 +24,7 @@ -export([request/8]). -export([data/4]). -export([cancel/2]). +-export([down/1]). -export([ws_upgrade/7]). -type io() :: head | {body, non_neg_integer()} | body_close | body_chunked. @@ -52,6 +54,8 @@ do_check_options([{version, V}|Opts]) when V =:= 'HTTP/1.1'; V =:= 'HTTP/1.0' -> do_check_options([Opt|_]) -> {error, {options, {http, Opt}}}. +name() -> http. + init(Owner, Socket, Transport, Opts) -> Version = maps:get(version, Opts, 'HTTP/1.1'), #http_state{owner=Owner, socket=Socket, transport=Transport, version=Version}. @@ -286,6 +290,14 @@ cancel(State, StreamRef) -> error_stream_not_found(State) end. +%% HTTP does not provide any way to figure out what streams are unprocessed. +down(#http_state{streams=Streams}) -> + KilledStreams = [case Ref of + {websocket, Ref2, _, _, _} -> Ref2; + _ -> Ref + end || {Ref, _} <- Streams], + {KilledStreams, []}. + error_stream_closed(State=#http_state{owner=Owner}) -> Owner ! {gun_error, self(), {badstate, "The stream has already been closed."}}, -- cgit v1.2.3