Class: Child

Inherits:
Forkme show all
Defined in:
lib/forkme/child.rb

Instance Attribute Summary collapse

Attributes inherited from Forkme

#child_count, #max_forks, #on_child_exit_blk, #on_child_start_blk, #suppress_exceptions

Instance Method Summary collapse

Methods inherited from Forkme

#interrupt, logger, logger=, #on_child_exit, #on_child_start, start, #start, #stop, #terminate

Methods included from DefaultLogger

debug, error, info

Constructor Details

#initialize(pid, from, to) ⇒ Child

Returns a new instance of Child.



2
3
4
5
# File 'lib/forkme/child.rb', line 2

def initialize(pid, from, to)
  @pid, @from, @to = pid, from, to
  @status = :idle
end

Instance Attribute Details

#fromObject

status is one of :idle, :connect, :close, :exit



8
9
10
# File 'lib/forkme/child.rb', line 8

def from
  @from
end

#pidObject

status is one of :idle, :connect, :close, :exit



8
9
10
# File 'lib/forkme/child.rb', line 8

def pid
  @pid
end

#toObject

status is one of :idle, :connect, :close, :exit



8
9
10
# File 'lib/forkme/child.rb', line 8

def to
  @to
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/forkme/child.rb', line 44

def active?()
  @status == :idle or @status == :connect
end

#closeObject



29
30
31
32
# File 'lib/forkme/child.rb', line 29

def close()
  @to.close unless @to.closed?
  @status = :close
end

#event(s) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/forkme/child.rb', line 10

def event(s)
  if s == nil then
    #Forkme.logger.debug "p: child #{pid} terminated"
    self.exit
  else
    case s.chomp
    when "connect" then @status = :connect
    when "disconnect" then @status = :idle
    else
      begin
        Forkme.logger.error "unknown status: #{s}"
      rescue NoMethodError
      end

      return "unknown status: #{s}"
    end
  end
end

#exitObject



34
35
36
37
38
# File 'lib/forkme/child.rb', line 34

def exit()
  @from.close unless @from.closed?
  @to.close unless @to.closed?
  @status = :exit
end

#idle?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/forkme/child.rb', line 40

def idle?()
  @status == :idle
end