Class: GrpcKit::Transport::ClientTransport
- Inherits:
-
Object
- Object
- GrpcKit::Transport::ClientTransport
- Includes:
- Packable
- Defined in:
- lib/grpc_kit/transport/client_transport.rb
Instance Method Summary collapse
- #close_and_flush ⇒ void
-
#initialize(session) ⇒ ClientTransport
constructor
A new instance of ClientTransport.
-
#read_data(last: false) ⇒ nil, Array<Boolean,Integer,String>
Nil when closed, tuple of Length-Prefixed-Message.
-
#read_data_nonblock(last: false) ⇒ nil, ...
Nil when closed, tuple of Length-Prefixed-Message, or :wait_readable.
- #recv_headers ⇒ Hash<String,String>
- #start_request(data, headers, last: false) ⇒ void
- #write_data(buf, last: false) ⇒ void
Methods included from Packable
Constructor Details
#initialize(session) ⇒ ClientTransport
Returns a new instance of ClientTransport.
11 12 13 14 |
# File 'lib/grpc_kit/transport/client_transport.rb', line 11 def initialize(session) @session = session @stream = nil # set later end |
Instance Method Details
#close_and_flush ⇒ void
This method returns an undefined value.
26 27 28 29 30 31 32 33 |
# File 'lib/grpc_kit/transport/client_transport.rb', line 26 def close_and_flush @stream.end_write send_data @session.start(@stream.stream_id) @stream.end_read @deferred = false end |
#read_data(last: false) ⇒ nil, Array<Boolean,Integer,String>
Returns nil when closed, tuple of Length-Prefixed-Message.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/grpc_kit/transport/client_transport.rb', line 45 def read_data(last: false) data_in_buffer = unpack(nil) return data_in_buffer if data_in_buffer loop do data = recv_data(last: last) return unpack(nil) unless data = unpack(data) return if end end |
#read_data_nonblock(last: false) ⇒ nil, ...
Returns nil when closed, tuple of Length-Prefixed-Message, or :wait_readable.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/grpc_kit/transport/client_transport.rb', line 58 def read_data_nonblock(last: false) data_in_buffer = unpack(nil) return data_in_buffer if data_in_buffer data = nonblock_recv_data(last: last) if data == :wait_readable :wait_readable elsif data == nil return unpack(nil) else unpack(data) || :wait_readable end end |
#recv_headers ⇒ Hash<String,String>
73 74 75 76 |
# File 'lib/grpc_kit/transport/client_transport.rb', line 73 def recv_headers wait_close @stream.headers end |
#start_request(data, headers, last: false) ⇒ void
This method returns an undefined value.
20 21 22 23 |
# File 'lib/grpc_kit/transport/client_transport.rb', line 20 def start_request(data, headers, last: false) @stream = @session.send_request(headers) write_data(data, last: last) end |
#write_data(buf, last: false) ⇒ void
This method returns an undefined value.
38 39 40 41 |
# File 'lib/grpc_kit/transport/client_transport.rb', line 38 def write_data(buf, last: false) write(@stream.pending_send_data, pack(buf), last: last) send_data end |