Class: MallCop::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/mallcop/channel.rb,
ext/mallcop/channel.c

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ Channel

Returns a new instance of Channel.



4
5
6
7
8
# File 'lib/mallcop/channel.rb', line 4

def initialize(session)
  @session, @open = session, true

  block { native_initialize }
end

Instance Method Details

#channel_exec(cmd) ⇒ Object



64
65
66
67
# File 'lib/mallcop/channel.rb', line 64

def channel_exec(cmd)
  block { native_channel_exec(cmd) }
  true
end

#closeObject



46
47
48
49
50
51
52
# File 'lib/mallcop/channel.rb', line 46

def close
  return true unless @open
  block { native_channel_close }
  true
ensure
  @open = false
end

#eof?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/mallcop/channel.rb', line 42

def eof?
  native_eof?
end

#flushObject



74
75
76
77
# File 'lib/mallcop/channel.rb', line 74

def flush
  block { native_flush }
  true
end

#readObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/mallcop/channel.rb', line 10

def read
  retval = ERROR_EAGAIN

  until retval != ERROR_EAGAIN
    @session.io_select
    retval = read_nonblock
  end

  retval
end

#read_nonblockObject

Raises:



21
22
23
24
# File 'lib/mallcop/channel.rb', line 21

def read_nonblock
  raise ChannelError, "The channel has been closed" unless @open
  native_channel_read
end

#request_pty(term) ⇒ Object



54
55
56
57
# File 'lib/mallcop/channel.rb', line 54

def request_pty(term)
  block { native_request_pty(term) }
  true
end

#send_eofObject



69
70
71
72
# File 'lib/mallcop/channel.rb', line 69

def send_eof
  block { native_send_eof }
  true
end

#shellObject



59
60
61
62
# File 'lib/mallcop/channel.rb', line 59

def shell
  block { native_shell }
  true
end

#write(cmd) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/mallcop/channel.rb', line 26

def write(cmd)
  retval = ERROR_EAGAIN

  until retval != ERROR_EAGAIN
    @session.io_select(true)
    retval = write_nonblock(cmd)
  end

  retval
end

#write_nonblock(cmd) ⇒ Object

Raises:



37
38
39
40
# File 'lib/mallcop/channel.rb', line 37

def write_nonblock(cmd)
  raise ChannelError, "The channel has been closed" unless @open
  native_channel_write(cmd)
end