Module: Denko::Connection::FlowControl

Defined in:
lib/denko/connection/flow_control.rb

Constant Summary collapse

SLEEP_TIME =
0.001

Instance Method Summary collapse

Instance Method Details

#initialize(*args) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/denko/connection/flow_control.rb', line 11

def initialize(*args)
  super(*args)
  # Start with minimum known buffer size. Board will update after handshake.
  # WARNING: If not updated, and ack threshold on the board is > minimum,
  # FlowControl will stop sending data, and appear to hang. Fix this.
  @remote_buffer_size = 63
  reset_flow_control
  tx_resume
end

#remote_buffer_size=(size) ⇒ Object

Let Board object tell us the remote buffer size after parsing handshake.



7
8
9
# File 'lib/denko/connection/flow_control.rb', line 7

def remote_buffer_size=(size)
  @transit_mutex.synchronize { @remote_buffer_size = size }
end

#write(message, tx_halt_after = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/denko/connection/flow_control.rb', line 21

def write(message, tx_halt_after=nil)
  @write_buffer_mutex.synchronize do
    @write_buffer << message

    # Optionally halt transmission after this message.
    # See comments on Board#write_and_halt for more info.
    @tx_halt_points << @write_buffer.length if tx_halt_after
  end
end

#writing?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/denko/connection/flow_control.rb', line 31

def writing?
  @write_buffer_mutex.synchronize { !@write_buffer.empty? }
end