diff --git a/src/chatterbox_static_stream.erl b/src/chatterbox_static_stream.erl index 0246b821..1f8e61b8 100644 --- a/src/chatterbox_static_stream.erl +++ b/src/chatterbox_static_stream.erl @@ -5,7 +5,7 @@ -behaviour(h2_stream). -export([ - init/2, + init/3, on_receive_request_headers/2, on_send_push_promise/2, on_receive_request_data/2, @@ -18,7 +18,7 @@ stream_id :: stream_id() }). -init(ConnPid, StreamId) -> +init(ConnPid, StreamId, _) -> %% You need to pull settings here from application:env or something {ok, #cb_static{connection_pid=ConnPid, stream_id=StreamId}}. diff --git a/src/h2_connection.erl b/src/h2_connection.erl index 32af3459..25ad96aa 100644 --- a/src/h2_connection.erl +++ b/src/h2_connection.erl @@ -89,6 +89,7 @@ next_available_stream_id = 2 :: stream_id(), streams :: h2_stream_set:stream_set(), stream_callback_mod = application:get_env(chatterbox, stream_callback_mod, chatterbox_static_stream) :: module(), + stream_callback_opts = application:get_env(chatterbox, stream_callback_opts, []) :: list(), buffer = empty :: empty | {binary, binary()} | {frame, h2_frame:header(), binary()}, continuation = undefined :: undefined | #continuation_state{}, flow_control = auto :: auto | manual, @@ -598,6 +599,7 @@ route_frame({#frame_header{type=?HEADERS}=FH, _Payload}=Frame, StreamId, self(), Conn#connection.stream_callback_mod, + Conn#connection.stream_callback_opts, Conn#connection.socket, (Conn#connection.peer_settings)#settings.initial_window_size, (Conn#connection.self_settings)#settings.initial_window_size, @@ -715,6 +717,7 @@ route_frame({H=#frame_header{ PSID, NotifyPid, Conn#connection.stream_callback_mod, + Conn#connection.stream_callback_opts, Conn#connection.socket, (Conn#connection.peer_settings)#settings.initial_window_size, (Conn#connection.self_settings)#settings.initial_window_size, @@ -1103,6 +1106,7 @@ handle_sync_event({new_stream, NotifyPid}, _F, StateName, NextId, NotifyPid, Conn#connection.stream_callback_mod, + Conn#connection.stream_callback_opts, Conn#connection.socket, Conn#connection.peer_settings#settings.initial_window_size, Conn#connection.self_settings#settings.initial_window_size, @@ -1659,6 +1663,7 @@ send_request(NextId, NotifyPid, Conn, Streams, Headers, Body) -> NextId, NotifyPid, Conn#connection.stream_callback_mod, + Conn#connection.stream_callback_opts, Conn#connection.socket, Conn#connection.peer_settings#settings.initial_window_size, Conn#connection.self_settings#settings.initial_window_size, diff --git a/src/h2_stream.erl b/src/h2_stream.erl index 1d739758..35672a3b 100644 --- a/src/h2_stream.erl +++ b/src/h2_stream.erl @@ -3,7 +3,7 @@ %% Public API -export([ - start_link/4, + start_link/5, send_pp/2, send_data/2, stream_id/0, @@ -71,7 +71,9 @@ -callback init( Conn :: pid(), - StreamId :: stream_id()) -> + StreamId :: stream_id(), + CallbackOptions :: list() + ) -> {ok, callback_state()}. -callback on_receive_request_headers( @@ -98,14 +100,16 @@ StreamId :: stream_id(), Connection :: pid(), CallbackModule :: module(), + CallbackOptions :: list(), Socket :: sock:socket() ) -> {ok, pid()} | ignore | {error, term()}. -start_link(StreamId, Connection, CallbackModule, Socket) -> +start_link(StreamId, Connection, CallbackModule, CallbackOptions, Socket) -> gen_fsm:start_link(?MODULE, [StreamId, Connection, CallbackModule, + CallbackOptions, Socket], []). @@ -146,10 +150,11 @@ init([ StreamId, ConnectionPid, CB, + CBOptions, Socket ]) -> %% TODO: Check for CB implementing this behaviour - {ok, CallbackState} = CB:init(ConnectionPid, StreamId), + {ok, CallbackState} = CB:init(ConnectionPid, StreamId, CBOptions), {ok, idle, #stream_state{ callback_mod=CB, diff --git a/src/h2_stream_set.erl b/src/h2_stream_set.erl index 1081b9a9..8f69e3da 100644 --- a/src/h2_stream_set.erl +++ b/src/h2_stream_set.erl @@ -122,7 +122,7 @@ -export( [ new/1, - new_stream/7, + new_stream/8, get/2, upsert/2, sort/1 @@ -202,6 +202,7 @@ new(server) -> StreamId :: stream_id(), NotifyPid :: pid(), CBMod :: module(), + CBOpts :: list(), Socket :: sock:socket(), InitialSendWindow :: integer(), InitialRecvWindow :: integer(), @@ -212,6 +213,7 @@ new_stream( StreamId, NotifyPid, CBMod, + CBOpts, Socket, InitialSendWindow, InitialRecvWindow, @@ -227,6 +229,7 @@ new_stream( StreamId, self(), CBMod, + CBOpts, Socket ), NewStream = #active_stream{ diff --git a/test/double_body_handler.erl b/test/double_body_handler.erl index ef3a6c3f..5fb1b117 100644 --- a/test/double_body_handler.erl +++ b/test/double_body_handler.erl @@ -5,7 +5,7 @@ -behaviour(h2_stream). -export([ - init/2, + init/3, on_receive_request_headers/2, on_send_push_promise/2, on_receive_request_data/2, @@ -16,9 +16,10 @@ stream_id :: stream_id() }). --spec init(pid(), stream_id()) -> {ok, any()}. -init(ConnPid, StreamId) -> {ok, #state{conn_pid=ConnPid, - stream_id=StreamId}}. +-spec init(pid(), stream_id(), list()) -> {ok, any()}. +init(ConnPid, StreamId, _Opts) -> + {ok, #state{conn_pid=ConnPid, + stream_id=StreamId}}. -spec on_receive_request_headers( Headers :: hpack:headers(), diff --git a/test/echo_handler.erl b/test/echo_handler.erl index 64c68371..8db32af2 100644 --- a/test/echo_handler.erl +++ b/test/echo_handler.erl @@ -5,7 +5,7 @@ -behaviour(h2_stream). -export([ - init/2, + init/3, on_receive_request_headers/2, on_send_push_promise/2, on_receive_request_data/2, @@ -17,9 +17,10 @@ buffer = <<>> :: binary() }). --spec init(pid(), stream_id()) -> {ok, any()}. -init(ConnPid, StreamId) -> {ok, #state{conn_pid=ConnPid, - stream_id=StreamId}}. +-spec init(pid(), stream_id(), list()) -> {ok, any()}. +init(ConnPid, StreamId, _Opts) -> + {ok, #state{conn_pid=ConnPid, + stream_id=StreamId}}. -spec on_receive_request_headers( Headers :: hpack:headers(), diff --git a/test/flow_control_SUITE.erl b/test/flow_control_SUITE.erl index b5c4d35f..9282d6cd 100644 --- a/test/flow_control_SUITE.erl +++ b/test/flow_control_SUITE.erl @@ -16,6 +16,9 @@ init_per_suite(Config) -> application:ensure_started(crypto), Config. +end_per_suite(_Config) -> + ok. + init_per_testcase( exceed_server_connection_receive_window, Config) -> diff --git a/test/flow_control_handler.erl b/test/flow_control_handler.erl index 3612f0ac..18ef4b63 100644 --- a/test/flow_control_handler.erl +++ b/test/flow_control_handler.erl @@ -7,7 +7,7 @@ -behaviour(h2_stream). -export([ - init/2, + init/3, on_receive_request_headers/2, on_send_push_promise/2, on_receive_request_data/2, @@ -18,8 +18,8 @@ stream_id :: stream_id() }). --spec init(pid(), stream_id()) -> {ok, any()}. -init(ConnPid, StreamId) -> +-spec init(pid(), stream_id(), list()) -> {ok, any()}. +init(ConnPid, StreamId, _Opts) -> {ok, #state{conn_pid=ConnPid, stream_id=StreamId}}. diff --git a/test/http2_spec_5_1_SUITE.erl b/test/http2_spec_5_1_SUITE.erl index afcd76bf..f1791001 100644 --- a/test/http2_spec_5_1_SUITE.erl +++ b/test/http2_spec_5_1_SUITE.erl @@ -19,6 +19,8 @@ init_per_suite(Config) -> application:ensure_started(crypto), Config. +end_per_suite(_Config) -> + ok. init_per_testcase(total_streams_above_max_concurrent, Config) -> chatterbox_test_buddy:start( diff --git a/test/peer_test_handler.erl b/test/peer_test_handler.erl index 3bf20394..3e95747b 100644 --- a/test/peer_test_handler.erl +++ b/test/peer_test_handler.erl @@ -5,7 +5,7 @@ -behaviour(h2_stream). -export([ - init/2, + init/3, on_receive_request_headers/2, on_send_push_promise/2, on_receive_request_data/2, @@ -18,9 +18,10 @@ inet:port_number()} }). --spec init(pid(), stream_id()) -> {ok, any()}. -init(ConnPid, StreamId) -> {ok, #state{conn_pid=ConnPid, - stream_id=StreamId}}. +-spec init(pid(), stream_id(), list()) -> {ok, any()}. +init(ConnPid, StreamId, _Opts) -> + {ok, #state{conn_pid=ConnPid, + stream_id=StreamId}}. -spec on_receive_request_headers( Headers :: hpack:headers(), diff --git a/test/server_connection_receive_window.erl b/test/server_connection_receive_window.erl index 1f69207b..4535538f 100644 --- a/test/server_connection_receive_window.erl +++ b/test/server_connection_receive_window.erl @@ -3,7 +3,7 @@ -behaviour(h2_stream). -export([ - init/2, + init/3, on_receive_request_headers/2, on_send_push_promise/2, on_receive_request_data/2, @@ -14,7 +14,7 @@ req_headers=[] }). -init(_ConnPid, _StreamId) -> +init(_ConnPid, _StreamId, _Opts) -> %% You need to pull settings here from application:env or something {ok, #cb_static{}}. diff --git a/test/server_stream_receive_window.erl b/test/server_stream_receive_window.erl index 60e149ad..3007ccea 100644 --- a/test/server_stream_receive_window.erl +++ b/test/server_stream_receive_window.erl @@ -3,7 +3,7 @@ -behaviour(h2_stream). -export([ - init/2, + init/3, on_receive_request_headers/2, on_send_push_promise/2, on_receive_request_data/2, @@ -14,7 +14,7 @@ req_headers=[] }). -init(_ConnPid, _StreamId) -> +init(_ConnPid, _StreamId, _Opts) -> %% You need to pull settings here from application:env or something {ok, #cb_static{}}.