@@ -80,6 +80,17 @@ impl Dispatcher {
8080 self . new_http_stream . set ( Some ( callback) ) ;
8181 }
8282
83+ fn register_callout ( & self , token_id : u32 ) {
84+ if self
85+ . callouts
86+ . borrow_mut ( )
87+ . insert ( token_id, self . active_id . get ( ) )
88+ . is_some ( )
89+ {
90+ panic ! ( "duplicate token_id" )
91+ }
92+ }
93+
8394 fn create_root_context ( & self , context_id : u32 ) {
8495 let new_context = match self . new_root . get ( ) {
8596 Some ( f) => f ( context_id) ,
@@ -96,12 +107,15 @@ impl Dispatcher {
96107 }
97108
98109 fn create_stream_context ( & self , context_id : u32 , root_context_id : u32 ) {
99- if !self . roots . borrow ( ) . contains_key ( & root_context_id) {
100- panic ! ( "invalid root_context_id" )
101- }
102- let new_context = match self . new_stream . get ( ) {
103- Some ( f) => f ( context_id, root_context_id) ,
104- None => panic ! ( "missing constructor" ) ,
110+ let new_context = match self . roots . borrow ( ) . get ( & root_context_id) {
111+ Some ( root_context) => match self . new_stream . get ( ) {
112+ Some ( f) => f ( context_id, root_context_id) ,
113+ None => match root_context. create_stream_context ( context_id) {
114+ Some ( stream_context) => stream_context,
115+ None => panic ! ( "create_stream_context returned None" ) ,
116+ } ,
117+ } ,
118+ None => panic ! ( "invalid root_context_id" ) ,
105119 } ;
106120 if self
107121 . streams
@@ -114,12 +128,15 @@ impl Dispatcher {
114128 }
115129
116130 fn create_http_context ( & self , context_id : u32 , root_context_id : u32 ) {
117- if !self . roots . borrow ( ) . contains_key ( & root_context_id) {
118- panic ! ( "invalid root_context_id" )
119- }
120- let new_context = match self . new_http_stream . get ( ) {
121- Some ( f) => f ( context_id, root_context_id) ,
122- None => panic ! ( "missing constructor" ) ,
131+ let new_context = match self . roots . borrow ( ) . get ( & root_context_id) {
132+ Some ( root_context) => match self . new_http_stream . get ( ) {
133+ Some ( f) => f ( context_id, root_context_id) ,
134+ None => match root_context. create_http_context ( context_id) {
135+ Some ( stream_context) => stream_context,
136+ None => panic ! ( "create_http_context returned None" ) ,
137+ } ,
138+ } ,
139+ None => panic ! ( "invalid root_context_id" ) ,
123140 } ;
124141 if self
125142 . http_streams
@@ -131,26 +148,25 @@ impl Dispatcher {
131148 }
132149 }
133150
134- fn register_callout ( & self , token_id : u32 ) {
135- if self
136- . callouts
137- . borrow_mut ( )
138- . insert ( token_id, self . active_id . get ( ) )
139- . is_some ( )
140- {
141- panic ! ( "duplicate token_id" )
142- }
143- }
144-
145151 fn on_create_context ( & self , context_id : u32 , root_context_id : u32 ) {
146152 if root_context_id == 0 {
147- self . create_root_context ( context_id)
153+ self . create_root_context ( context_id) ;
148154 } else if self . new_http_stream . get ( ) . is_some ( ) {
149155 self . create_http_context ( context_id, root_context_id) ;
150156 } else if self . new_stream . get ( ) . is_some ( ) {
151157 self . create_stream_context ( context_id, root_context_id) ;
158+ } else if let Some ( root_context) = self . roots . borrow ( ) . get ( & root_context_id) {
159+ match root_context. get_type ( ) {
160+ Some ( ContextType :: HttpContext ) => {
161+ self . create_http_context ( context_id, root_context_id)
162+ }
163+ Some ( ContextType :: StreamContext ) => {
164+ self . create_stream_context ( context_id, root_context_id)
165+ }
166+ None => panic ! ( "missing ContextType on root_context" ) ,
167+ }
152168 } else {
153- panic ! ( "missing constructors" )
169+ panic ! ( "invalid root_context_id and missing constructors" ) ;
154170 }
155171 }
156172
0 commit comments