module Net::SSH::Connection

Constants

GOOD_LOCAL_MAXIUMUM_WINDOW_SIZE
LOCAL_WINDOW_SIZE_INCREMENT

Public Instance Methods

do_close() click to toggle source

Invokes the on_close callback when the server closes a channel. The channel is the only argument.

# File lib/net/ssh/connection/channel.rb, line 613
def do_close
  @on_close.call(self) if @on_close
end
do_eof() click to toggle source

Invokes the on_eof callback when the server indicates that no further data is forthcoming. The callback is invoked with the channel as the argument.

# File lib/net/ssh/connection/channel.rb, line 607
def do_eof
  @on_eof.call(self) if @on_eof
end
do_extended_data(type, data) click to toggle source

Invokes the on_extended_data callback when the server sends extended data to the channel. This will reduce the available window size on the local end. The callback is invoked with the channel, type, and data.

# File lib/net/ssh/connection/channel.rb, line 599
def do_extended_data(type, data)
  update_local_window_size(data.length)
  @on_extended_data.call(self, type, data) if @on_extended_data
end
do_failure() click to toggle source

Invokes the next pending request callback with false as the second argument.

# File lib/net/ssh/connection/channel.rb, line 619
def do_failure
  if callback = pending_requests.shift
    callback.call(self, false)
  else
    error { "channel failure received with no pending request to handle it (bug?)" }
  end
end
do_open_failed(reason_code, description) click to toggle source

Invoked when the server failed to open the channel. If an on_open_failed callback was specified, it will be invoked with the channel, reason code, and description as arguments. Otherwise, a ChannelOpenFailed exception will be raised.

# File lib/net/ssh/connection/channel.rb, line 544
def do_open_failed(reason_code, description)
  if @on_open_failed
    @on_open_failed.call(self, reason_code, description)
  else
    raise ChannelOpenFailed.new(reason_code, description)
  end
end
do_success() click to toggle source

Invokes the next pending request callback with true as the second argument.

# File lib/net/ssh/connection/channel.rb, line 629
def do_success
  if callback = pending_requests.shift
    callback.call(self, true)
  else
    error { "channel success received with no pending request to handle it (bug?)" }
  end
end

Private Instance Methods

forward_local_env(env_variable_patterns) click to toggle source

Gets an Array of local environment variables in the remote process’ environment. A variable name can either be described by a Regexp or String.

channel.forward_local_env [/^GIT_.*$/, "LANG"]
# File lib/net/ssh/connection/channel.rb, line 671
def forward_local_env(env_variable_patterns)
  Array(env_variable_patterns).each do |env_variable_pattern|
    matched_variables = ENV.find_all do |env_name, _|
      case env_variable_pattern
      when Regexp then env_name =~ env_variable_pattern
      when String then env_name == env_variable_pattern
      end
    end
    matched_variables.each do |env_name, env_value|
      self.env(env_name, env_value)
    end
  end
end
set_remote_env(env) click to toggle source

Set a Hash of environment variables in the remote process’ environment.

channel.set_remote_env foo: 'bar', baz: 'whale'
# File lib/net/ssh/connection/channel.rb, line 688
def set_remote_env(env)
  env.each { |key, value| self.env(key, value) }
end
update_local_window_size(size) click to toggle source

Updates the local window size by the given amount. If the window size drops to less than half of the local maximum (an arbitrary threshold), a CHANNEL_WINDOW_ADJUST message will be sent to the server telling it that the window size has grown.

# File lib/net/ssh/connection/channel.rb, line 652
def update_local_window_size(size)
  @local_window_size -= size
  if local_window_size < local_maximum_window_size / 2
    connection.send_message(
      Buffer.from(:byte, CHANNEL_WINDOW_ADJUST, :long, remote_id, :long, LOCAL_WINDOW_SIZE_INCREMENT)
    )
    @local_window_size += LOCAL_WINDOW_SIZE_INCREMENT

    if @local_maximum_window_size < @local_window_size || @local_maximum_window_size < GOOD_LOCAL_MAXIUMUM_WINDOW_SIZE
      @local_maximum_window_size += LOCAL_WINDOW_SIZE_INCREMENT
    end
  end
end
wait_until_open_confirmed() click to toggle source

Runs the SSH event loop until the remote confirmed channel open experimental api

# File lib/net/ssh/connection/channel.rb, line 641
def wait_until_open_confirmed
  connection.loop { !remote_id }
end