Class: BridgeSocket
- Inherits:
-
Object
- Object
- BridgeSocket
- Defined in:
- lib/bridge_socket.rb,
lib/bridge_socket/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ BridgeSocket
constructor
A new instance of BridgeSocket.
- #start(file1, file2, &block) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ BridgeSocket
Returns a new instance of BridgeSocket.
29 30 31 |
# File 'lib/bridge_socket.rb', line 29 def initialize @retry_interval = 5 end |
Instance Attribute Details
#retry_interval ⇒ Object
Returns the value of attribute retry_interval.
27 28 29 |
# File 'lib/bridge_socket.rb', line 27 def retry_interval @retry_interval end |
Class Method Details
.test(args) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/bridge_socket.rb', line 19 def self.test(args) args.each{|arg| unless arg and (File.stat(arg).chardev? or File.stat(arg).socket?) raise RuntimeError, "character device or socket is required - #{arg}" end } end |
Instance Method Details
#start(file1, file2, &block) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bridge_socket.rb', line 33 def start(file1, file2, &block) files = [file1, file2] @retry = true while @retry begin @socks = files.map{|s| File.open(s, 'w+') rescue UNIXSocket.open(s) } rescue => e return unless @retry yield("retry after #{@retry_interval} sec.", e) if block_given? sleep @retry_interval retry end yield("Starting #{files.join(" <=> ")}.", nil) if block_given? @thread = do_pipe(*@socks) do_pipe(*@socks.reverse) @thread.join @socks.each{|s| s.close rescue nil } yield("disconnected.", nil) if block_given? end end |
#stop ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/bridge_socket.rb', line 54 def stop @retry = false @socks.each{|s| s.close rescue nil } @thread.join rescue nil @socks = [] @thread = nil end |