Class: Arf::Wire::Client

Inherits:
BaseConnection show all
Defined in:
lib/arf/wire/client.rb

Instance Method Summary collapse

Methods inherited from BaseConnection

#arf_close_after_writing?, #cancel_streams, #close_connection, #close_connection_after_writing, #dispatch, #dispatch_frame, #fetch_stream, #flush_write_buffer, #go_away!, #handle_frame, #initialize, #ping, #protocol_error!, #recv, #registered!, #registered?, #send_data, #wait_configuration, #wait_pong

Constructor Details

This class inherits a constructor from Arf::Wire::BaseConnection

Instance Method Details

#closeObject



93
94
95
96
97
98
# File 'lib/arf/wire/client.rb', line 93

def close
  wait_configuration
  @streams_monitor.synchronize do
    close_connection
  end
end

#handle_configuration(fr) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/arf/wire/client.rb', line 53

def handle_configuration(fr)
  return protocol_error! if !fr.ack? || @configured

  @configured = true
  @configuration_ready_lock.synchronize do
    @configuration_ready_signal.broadcast
  end
end

#handle_data(fr) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/arf/wire/client.rb', line 62

def handle_data(fr)
  return protocol_error! unless @configured

  str = fetch_stream(fr.stream_id)
  return reset_stream(fr.stream_id, ERROR_CODE_PROTOCOL_ERROR) unless str

  str.handle_data(fr)
end

#handle_go_away(fr) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/arf/wire/client.rb', line 36

def handle_go_away(fr)
  return protocol_error! unless @configured

  # server intends to disconnect
  cancel_streams(fr.error_code)
  close_connection_after_writing
end

#handle_ping(fr) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/arf/wire/client.rb', line 22

def handle_ping(fr)
  return protocol_error! unless @configured

  if fr.ack?
    @pong_signal.broadcast
    return
  end

  dispatch_frame(PingFrame) do |p|
    p.ack!
    p.payload = fr.payload
  end
end

#handle_reset_stream(fr) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/arf/wire/client.rb', line 44

def handle_reset_stream(fr)
  return protocol_error! unless @configured

  str = fetch_stream(fr.stream_id)
  return protocol_error! unless str

  str.handle_reset_stream(fr)
end

#new_streamObject



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/arf/wire/client.rb', line 71

def new_stream
  wait_configuration
  id = nil
  @streams_monitor.synchronize do
    @last_stream_id += 1
    id = @last_stream_id
    @streams[id] = Stream.new(id, self)
    dispatch_frame(MakeStreamFrame) do |fr|
      fr.stream_id = id
    end
  end
  @streams[id]
end

#post_initObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/arf/wire/client.rb', line 6

def post_init
  dispatch_frame(ConfigurationFrame) do |fr|
    compression = Arf.config.client_compression
    case compression
    when :brotli
      fr.compression_brotli!
    when :gzip
      fr.compression_gzip!
    else
      Arf.config.client_compression = :none
    end

    @compression = Arf.config.client_compression
  end
end

#terminate(reason) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/arf/wire/client.rb', line 85

def terminate(reason)
  dispatch_frame(GoAwayFrame) do |g|
    g.error_code = reason
    g.last_stream_id = @last_stream_id
  end
  close_connection_after_writing
end