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

Returns a new instance of ClientTransport.

Parameters:



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

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.

Parameters:

  • last (Boolean) (defaults to: false)

Returns:

  • (nil, Array<Boolean,Integer,String>)

    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
    message = unpack(data)
    return message if message
  end
end

#read_data_nonblock(last: false) ⇒ nil, ...

Returns nil when closed, tuple of Length-Prefixed-Message, or :wait_readable.

Parameters:

  • last (Boolean) (defaults to: false)

Returns:

  • (nil, Array<Boolean,Integer,String>, Symbol)

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

Returns:

  • (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.

Parameters:

  • data (String)
  • headers (Hash<String, String>)
  • last (Boolean) (defaults to: false)


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.

Parameters:

  • buf (String)
  • last (Boolean) (defaults to: false)


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