Class: Tork::Bridge
- Inherits:
-
Object
- Object
- Tork::Bridge
- Defined in:
- lib/tork/bridge.rb
Overview
whenever the child process terminates extraneously, on its own.
Instance Method Summary collapse
- #disconnect ⇒ Object
-
#initialize(command) ⇒ Bridge
constructor
A new instance of Bridge.
-
#method_missing(*args, &block) ⇒ Object
Allows this object to be treated as IO.
- #reconnect ⇒ Object
-
#to_io ⇒ Object
Allows this object to be passed directly into IO.select() and Tork::Server#tell().
Constructor Details
#initialize(command) ⇒ Bridge
Returns a new instance of Bridge.
6 7 8 9 |
# File 'lib/tork/bridge.rb', line 6 def initialize command @command = command connect end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
Allows this object to be treated as IO.
47 48 49 |
# File 'lib/tork/bridge.rb', line 47 def method_missing *args, &block @io.__send__ *args, &block end |
Instance Method Details
#disconnect ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tork/bridge.rb', line 11 def disconnect return unless @guardian.alive? # prevent guardian from reconnecting bridge while we disconnect it @guardian.exit # this should be enough to stop programs that use Tork::Server#loop # because their IO.select() loop terminates on the closing of STDIN @io.close_write # but some programs like tork-herald(1) need to be killed explicitly # because they do not follow our convention of exiting on STDIN close Process.kill :SIGTERM, @io.pid Process.waitpid @io.pid # this will block until the child process has exited so we must kill it # explicitly (as above) to ensure that this program does not hang here @io.close_read rescue IOError, SystemCallError # IOError happens if the child process' pipes are already closed # SystemCallError happens if the child process is already dead end |
#reconnect ⇒ Object
35 36 37 38 |
# File 'lib/tork/bridge.rb', line 35 def reconnect disconnect connect end |
#to_io ⇒ Object
Allows this object to be passed directly into IO.select() and Tork::Server#tell().
42 43 44 |
# File 'lib/tork/bridge.rb', line 42 def to_io @io end |