mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Add keepalive function that resets the inactivity timer
Can be used in a streaming loop when we expect more data to arrive and want to prevent an inactivity timeout.
This commit is contained in:
parent
2a08250499
commit
cec3a35b8d
2 changed files with 7 additions and 0 deletions
|
@ -255,6 +255,8 @@ loop(State=#state{parent=Parent, socket=Socket, transport=Transport, opts=Opts,
|
|||
%% Messages pertaining to a stream.
|
||||
{{Pid, StreamID}, Msg} when Pid =:= self() ->
|
||||
loop(info(State, StreamID, Msg));
|
||||
{{Pid, _StreamID}, keepalive} when Pid =:= self() ->
|
||||
loop(State);
|
||||
%% Exit signal from children.
|
||||
Msg = {'EXIT', Pid, _} ->
|
||||
loop(down(State, Pid, Msg));
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
-export([stream_reply/3]).
|
||||
%% @todo stream_body/2 (nofin)
|
||||
-export([stream_body/3]).
|
||||
-export([stream_keepalive/1]).
|
||||
%% @todo stream_events/2 (nofin)
|
||||
-export([stream_events/3]).
|
||||
-export([stream_trailers/2]).
|
||||
|
@ -889,6 +890,10 @@ stream_body(Msg, Req=#{pid := Pid}) ->
|
|||
cast(Msg, Req),
|
||||
receive {data_ack, Pid} -> ok end.
|
||||
|
||||
-spec stream_keepalive(req()) -> ok.
|
||||
stream_keepalive(Req) ->
|
||||
cast(keepalive, Req).
|
||||
|
||||
-spec stream_events(cow_sse:event() | [cow_sse:event()], fin | nofin, req()) -> ok.
|
||||
stream_events(Event, IsFin, Req) when is_map(Event) ->
|
||||
stream_events([Event], IsFin, Req);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue