Class: Farcall::BossTransport

Inherits:
Transport show all
Includes:
TransportBase
Defined in:
lib/farcall/boss_transport.rb

Overview

Boss transport is more spece-effective than json, supports more data types, and does not need delimiters to separate packets in the stream. Creation parameters are the same as of Farcall::Transport

Instance Attribute Summary

Attributes inherited from Transport

#on_abort, #on_close, #on_data_received

Instance Method Summary collapse

Methods included from TransportBase

#close_connection, #setup_streams

Methods inherited from Transport

#closed?, create, #receive_data

Constructor Details

#initialize(**params) ⇒ BossTransport

Create json transport, see Farcall::Transpor#create for parameters



10
11
12
13
14
# File 'lib/farcall/boss_transport.rb', line 10

def initialize **params
  setup_streams **params
  @formatter = Boss::Formatter.new(@output)
  @formatter.set_stream_mode
end

Instance Method Details

#closeObject



29
30
31
32
33
34
35
36
# File 'lib/farcall/boss_transport.rb', line 29

def close
  if !@closing
    @closing = true
    close_connection
    @thread and @thread.join
    @thread = nil
  end
end

#on_data_received=(block) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/farcall/boss_transport.rb', line 16

def on_data_received= block
  super
  if block && !@thread
    @thread = Thread.start {
      load_loop
    }
  end
end

#send_data(hash) ⇒ Object



25
26
27
# File 'lib/farcall/boss_transport.rb', line 25

def send_data hash
  @formatter << hash
end