Class: GrpcKit::Transport::ClientTransport

Inherits:
Object
  • Object
show all
Includes:
Packable
Defined in:
lib/grpc_kit/transport/client_transport.rb

Instance Method Summary collapse

Methods included from Packable

#pack, #unpack, #unpacker

Constructor Details

#initialize(session) ⇒ 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_flushvoid


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, String


45
46
47
# File 'lib/grpc_kit/transport/client_transport.rb', line 45

def read_data(last: false)
  unpack(recv_data(last: last))
end

#read_data_nonblock(last: false) ⇒ nil, String


51
52
53
54
55
56
57
58
59
# File 'lib/grpc_kit/transport/client_transport.rb', line 51

def read_data_nonblock(last: false)
  data = nonblock_recv_data(last: last)
  if data == :wait_readable
    unpack(nil) # nil is needed read buffered data
    :wait_readable
  else
    unpack(data)
  end
end

#recv_headersHash<String,String>


62
63
64
65
# File 'lib/grpc_kit/transport/client_transport.rb', line 62

def recv_headers
  wait_close
  @stream.headers
end

#start_request(data, headers, last: false) ⇒ void


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


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