summaryrefslogtreecommitdiff
path: root/lib/net/ssh/multi/channel.rb
blob: 8d33fa3c0bbd99d6aa1546962c169351e2d15eb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
module Net; module SSH; module Multi
  class Channel
    include Enumerable

    attr_reader :connection
    attr_reader :channels
    attr_reader :properties

    def initialize(connection, channels)
      @connection = connection
      @channels = channels
      @properties = {}
    end

    def each
      @channels.each { |channel| yield channel }
    end

    def [](key)
      @properties[key]
    end

    def []=(key, value)
      @properties[key] = value
    end

    def exec(command, &block)
      channels.each { |channel| channel.exec(command, &block) }
      self
    end

    def subsystem(subsystem, &block)
      channels.each { |channel| channel.subsystem(subsystem, &block) }
      self
    end

    def request_pty(opts={}, &block)
      channels.each { |channel| channel.request_pty(opts, &block) }
      self
    end

    def send_data(data)
      channels.each { |channel| channel.send_data(data) }
      self
    end

    def active?
      channels.any? { |channel| channel.active? }
    end

    def wait
      connection.loop { active? }
      self
    end

    def close
      channels.each { |channel| channel.close }
      self
    end

    def eof!
      channels.each { |channel| channel.eof! }
      self
    end

    def on_data(&block)
      channels.each { |channel| channel.on_data(&block) }
      self
    end

    def on_extended_data(&block)
      channels.each { |channel| channel.on_extended_data(&block) }
      self
    end

    def on_process(&block)
      channels.each { |channel| channel.on_process(&block) }
      self
    end

    def on_close(&block)
      channels.each { |channel| channel.on_close(&block) }
      self
    end

    def on_eof(&block)
      channels.each { |channel| channel.on_eof(&block) }
      self
    end

    def on_request(type, &block)
      channels.each { |channel| channel.on_request(type, &block) }
      self
    end
  end
end; end; end