@ -97,7 +97,7 @@ module GRPC
# @param gen_each_reply [Proc] generates the BiDi stream replies.
# @param gen_each_reply [Proc] generates the BiDi stream replies.
def run_on_server ( gen_each_reply )
def run_on_server ( gen_each_reply )
replys = gen_each_reply . call ( each_queued_msg )
replys = gen_each_reply . call ( each_queued_msg )
@loop_th = start_read_loop
@loop_th = start_read_loop ( is_client : false )
write_loop ( replys , is_client : false )
write_loop ( replys , is_client : false )
end
end
@ -125,7 +125,7 @@ module GRPC
count += 1
count += 1
req = @readq . pop
req = @readq . pop
GRPC . logger . debug ( " each_queued_msg: req = #{ req } " )
GRPC . logger . debug ( " each_queued_msg: req = #{ req } " )
throw req if req . is_a? StandardError
fail req if req . is_a? StandardError
break if req . equal? ( END_OF_READS )
break if req . equal? ( END_OF_READS )
yield req
yield req
end
end
@ -145,12 +145,9 @@ module GRPC
GRPC . logger . debug ( " bidi-write-loop: #{ count } writes done " )
GRPC . logger . debug ( " bidi-write-loop: #{ count } writes done " )
if is_client
if is_client
GRPC . logger . debug ( " bidi-write-loop: client sent #{ count } , waiting " )
GRPC . logger . debug ( " bidi-write-loop: client sent #{ count } , waiting " )
batch_result = @call . run_batch ( @cq , write_tag , INFINITE_FUTURE ,
@call . run_batch ( @cq , write_tag , INFINITE_FUTURE ,
SEND_CLOSE_FROM_CLIENT = > nil ,
SEND_CLOSE_FROM_CLIENT = > nil )
RECV_STATUS_ON_CLIENT = > nil )
GRPC . logger . debug ( 'bidi-write-loop: done' )
@call . status = batch_result . status
batch_result . check_status
GRPC . logger . debug ( " bidi-write-loop: done status #{ @call . status } " )
notify_done
notify_done
end
end
GRPC . logger . debug ( 'bidi-write-loop: finished' )
GRPC . logger . debug ( 'bidi-write-loop: finished' )
@ -162,7 +159,7 @@ module GRPC
end
end
# starts the read loop
# starts the read loop
def start_read_loop
def start_read_loop ( is_client : true )
Thread . new do
Thread . new do
GRPC . logger . debug ( 'bidi-read-loop: starting' )
GRPC . logger . debug ( 'bidi-read-loop: starting' )
begin
begin
@ -175,9 +172,19 @@ module GRPC
# TODO: ensure metadata is read if available, currently it's not
# TODO: ensure metadata is read if available, currently it's not
batch_result = @call . run_batch ( @cq , read_tag , INFINITE_FUTURE ,
batch_result = @call . run_batch ( @cq , read_tag , INFINITE_FUTURE ,
RECV_MESSAGE = > nil )
RECV_MESSAGE = > nil )
# handle the next message
# handle the next message
if batch_result . message . nil?
if batch_result . message . nil?
GRPC . logger . debug ( " bidi-read-loop: null batch #{ batch_result } " )
GRPC . logger . debug ( " bidi-read-loop: null batch #{ batch_result } " )
if is_client
batch_result = @call . run_batch ( @cq , read_tag , INFINITE_FUTURE ,
RECV_STATUS_ON_CLIENT = > nil )
@call . status = batch_result . status
batch_result . check_status
GRPC . logger . debug ( " bidi-read-loop: done status #{ @call . status } " )
end
@readq . push ( END_OF_READS )
@readq . push ( END_OF_READS )
GRPC . logger . debug ( 'bidi-read-loop: done reading!' )
GRPC . logger . debug ( 'bidi-read-loop: done reading!' )
break
break