@@ -61,7 +61,7 @@ struct Dispatcher {
61
61
active_id : Cell < u32 > ,
62
62
callouts : RefCell < HashMap < u32 , u32 > > ,
63
63
grpc_callouts : RefCell < HashMap < u32 , u32 > > ,
64
- grpc_stream_tokens : RefCell < HashMap < u32 , u32 > > ,
64
+ grpc_streams : RefCell < HashMap < u32 , u32 > > ,
65
65
}
66
66
67
67
impl Dispatcher {
@@ -76,7 +76,7 @@ impl Dispatcher {
76
76
active_id : Cell :: new ( 0 ) ,
77
77
callouts : RefCell :: new ( HashMap :: new ( ) ) ,
78
78
grpc_callouts : RefCell :: new ( HashMap :: new ( ) ) ,
79
- grpc_stream_tokens : RefCell :: new ( HashMap :: new ( ) ) ,
79
+ grpc_streams : RefCell :: new ( HashMap :: new ( ) ) ,
80
80
}
81
81
}
82
82
@@ -103,9 +103,9 @@ impl Dispatcher {
103
103
}
104
104
}
105
105
106
- fn register_grpc_stream_tokens ( & self , token_id : u32 ) {
106
+ fn register_grpc_stream ( & self , token_id : u32 ) {
107
107
if self
108
- . grpc_stream_tokens
108
+ . grpc_streams
109
109
. borrow_mut ( )
110
110
. insert ( token_id, self . active_id . get ( ) )
111
111
. is_some ( )
@@ -416,6 +416,29 @@ impl Dispatcher {
416
416
}
417
417
}
418
418
419
+ fn on_grpc_receive_initial_metadata ( & self , token_id : u32 , headers : u32 ) {
420
+ let context_id = self
421
+ . grpc_streams
422
+ . borrow_mut ( )
423
+ . get ( & token_id)
424
+ . expect ( "invalid token_id" )
425
+ . clone ( ) ;
426
+
427
+ if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
428
+ self . active_id . set ( context_id) ;
429
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
430
+ http_stream. on_grpc_stream_initial_metadata ( token_id, headers) ;
431
+ } else if let Some ( stream) = self . streams . borrow_mut ( ) . get_mut ( & context_id) {
432
+ self . active_id . set ( context_id) ;
433
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
434
+ stream. on_grpc_stream_initial_metadata ( token_id, headers) ;
435
+ } else if let Some ( root) = self . roots . borrow_mut ( ) . get_mut ( & context_id) {
436
+ self . active_id . set ( context_id) ;
437
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
438
+ root. on_grpc_stream_initial_metadata ( token_id, headers) ;
439
+ }
440
+ }
441
+
419
442
fn on_grpc_receive ( & self , token_id : u32 , response_size : usize ) {
420
443
if let Some ( context_id) = self . grpc_callouts . borrow_mut ( ) . remove ( & token_id) {
421
444
if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
@@ -431,26 +454,49 @@ impl Dispatcher {
431
454
hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
432
455
root. on_grpc_call_response ( token_id, 0 , response_size) ;
433
456
}
434
- } else if let Some ( context_id) = self . grpc_callouts . borrow_mut ( ) . get ( & token_id) {
457
+ } else if let Some ( context_id) = self . grpc_streams . borrow_mut ( ) . get ( & token_id) {
435
458
let context_id = context_id. clone ( ) ;
436
459
if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
437
460
self . active_id . set ( context_id) ;
438
461
hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
439
- http_stream. on_grpc_stream_receive_body ( token_id, response_size) ;
462
+ http_stream. on_grpc_stream_message ( token_id, response_size) ;
440
463
} else if let Some ( stream) = self . streams . borrow_mut ( ) . get_mut ( & context_id) {
441
464
self . active_id . set ( context_id) ;
442
465
hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
443
- stream. on_grpc_stream_receive_body ( token_id, response_size) ;
466
+ stream. on_grpc_stream_message ( token_id, response_size) ;
444
467
} else if let Some ( root) = self . roots . borrow_mut ( ) . get_mut ( & context_id) {
445
468
self . active_id . set ( context_id) ;
446
469
hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
447
- root. on_grpc_stream_receive_body ( token_id, response_size) ;
470
+ root. on_grpc_stream_message ( token_id, response_size) ;
448
471
}
449
472
} else {
450
473
panic ! ( "invalid token_id" )
451
474
}
452
475
}
453
476
477
+ fn on_grpc_receive_trailing_metadata ( & self , token_id : u32 , trailers : u32 ) {
478
+ let context_id = self
479
+ . grpc_streams
480
+ . borrow_mut ( )
481
+ . get ( & token_id)
482
+ . expect ( "invalid token_id" )
483
+ . clone ( ) ;
484
+
485
+ if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
486
+ self . active_id . set ( context_id) ;
487
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
488
+ http_stream. on_grpc_stream_initial_metadata ( token_id, trailers) ;
489
+ } else if let Some ( stream) = self . streams . borrow_mut ( ) . get_mut ( & context_id) {
490
+ self . active_id . set ( context_id) ;
491
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
492
+ stream. on_grpc_stream_initial_metadata ( token_id, trailers) ;
493
+ } else if let Some ( root) = self . roots . borrow_mut ( ) . get_mut ( & context_id) {
494
+ self . active_id . set ( context_id) ;
495
+ hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
496
+ root. on_grpc_stream_initial_metadata ( token_id, trailers) ;
497
+ }
498
+ }
499
+
454
500
fn on_grpc_close ( & self , token_id : u32 , status_code : u32 ) {
455
501
if let Some ( context_id) = self . grpc_callouts . borrow_mut ( ) . remove ( & token_id) {
456
502
if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
@@ -466,7 +512,7 @@ impl Dispatcher {
466
512
hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
467
513
root. on_grpc_call_response ( token_id, status_code, 0 ) ;
468
514
}
469
- } else if let Some ( context_id) = self . grpc_stream_tokens . borrow_mut ( ) . remove ( & token_id) {
515
+ } else if let Some ( context_id) = self . grpc_streams . borrow_mut ( ) . remove ( & token_id) {
470
516
if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
471
517
self . active_id . set ( context_id) ;
472
518
hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
@@ -484,52 +530,6 @@ impl Dispatcher {
484
530
panic ! ( "invalid token_id" )
485
531
}
486
532
}
487
-
488
- fn on_grpc_receive_initial_metadata ( & self , token_id : u32 , headers : u32 ) {
489
- let context_id = self
490
- . grpc_stream_tokens
491
- . borrow_mut ( )
492
- . get ( & token_id)
493
- . expect ( "invalid token_id" )
494
- . clone ( ) ;
495
-
496
- if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
497
- self . active_id . set ( context_id) ;
498
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
499
- http_stream. on_grpc_stream_receive_initial_metadata ( token_id, headers) ;
500
- } else if let Some ( stream) = self . streams . borrow_mut ( ) . get_mut ( & context_id) {
501
- self . active_id . set ( context_id) ;
502
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
503
- stream. on_grpc_stream_receive_initial_metadata ( token_id, headers) ;
504
- } else if let Some ( root) = self . roots . borrow_mut ( ) . get_mut ( & context_id) {
505
- self . active_id . set ( context_id) ;
506
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
507
- root. on_grpc_stream_receive_initial_metadata ( token_id, headers) ;
508
- }
509
- }
510
-
511
- fn on_grpc_receive_trailing_metadata ( & self , token_id : u32 , trailers : u32 ) {
512
- let context_id = self
513
- . grpc_stream_tokens
514
- . borrow_mut ( )
515
- . get ( & token_id)
516
- . expect ( "invalid token_id" )
517
- . clone ( ) ;
518
-
519
- if let Some ( http_stream) = self . http_streams . borrow_mut ( ) . get_mut ( & context_id) {
520
- self . active_id . set ( context_id) ;
521
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
522
- http_stream. on_grpc_stream_receive_trailing_metadata ( token_id, trailers) ;
523
- } else if let Some ( stream) = self . streams . borrow_mut ( ) . get_mut ( & context_id) {
524
- self . active_id . set ( context_id) ;
525
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
526
- stream. on_grpc_stream_receive_trailing_metadata ( token_id, trailers) ;
527
- } else if let Some ( root) = self . roots . borrow_mut ( ) . get_mut ( & context_id) {
528
- self . active_id . set ( context_id) ;
529
- hostcalls:: set_effective_context ( context_id) . unwrap ( ) ;
530
- root. on_grpc_stream_receive_trailing_metadata ( token_id, trailers) ;
531
- }
532
- }
533
533
}
534
534
535
535
#[ no_mangle]
@@ -659,11 +659,25 @@ pub extern "C" fn proxy_on_http_call_response(
659
659
} )
660
660
}
661
661
662
+ #[ no_mangle]
663
+ pub extern "C" fn proxy_on_grpc_receive_initial_metadata (
664
+ _context_id : u32 ,
665
+ token_id : u32 ,
666
+ headers : u32 ,
667
+ ) {
668
+ DISPATCHER . with ( |dispatcher| dispatcher. on_grpc_receive_initial_metadata ( token_id, headers) )
669
+ }
670
+
662
671
#[ no_mangle]
663
672
pub extern "C" fn proxy_on_grpc_receive ( _context_id : u32 , token_id : u32 , response_size : usize ) {
664
673
DISPATCHER . with ( |dispatcher| dispatcher. on_grpc_receive ( token_id, response_size) )
665
674
}
666
675
676
+ #[ no_mangle]
677
+ pub extern "C" fn proxy_on_grpc_trailing_metadata ( _context_id : u32 , token_id : u32 , trailers : u32 ) {
678
+ DISPATCHER . with ( |dispatcher| dispatcher. on_grpc_receive_trailing_metadata ( token_id, trailers) )
679
+ }
680
+
667
681
#[ no_mangle]
668
682
pub extern "C" fn proxy_on_grpc_close ( _context_id : u32 , token_id : u32 , status_code : u32 ) {
669
683
DISPATCHER . with ( |dispatcher| dispatcher. on_grpc_close ( token_id, status_code) )
0 commit comments