Class: Net::SSH::Connection::Keepalive

### Home Classes Methods

### In Files

- lib/net/ssh/connection/keepalive.rb

### Parent

Object

### Methods

- ::new
- #enabled?
- #interval
- #keepalive_maxcount
- #options
- #send_as_needed
- #should_send?

### Included Modules

- Net::SSH::Loggable

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Net
- Net::SSH
- Net::SSH::Authentication
- Net::SSH::Authentication::Agent
- Net::SSH::Authentication::Agent::Comment
- Net::SSH::Authentication::AgentError
- Net::SSH::Authentication::AgentNotAvailable
- Net::SSH::Authentication::Constants
- Net::SSH::Authentication::DisallowedMethod
- Net::SSH::Authentication::KeyManager
- Net::SSH::Authentication::KeyManagerError
- Net::SSH::Authentication::Methods
- Net::SSH::Authentication::Methods::Abstract
- Net::SSH::Authentication::Methods::Hostbased
- Net::SSH::Authentication::Methods::KeyboardInteractive
- Net::SSH::Authentication::Methods::None
- Net::SSH::Authentication::Methods::Password
- Net::SSH::Authentication::Methods::Publickey
- Net::SSH::Authentication::Session
- Net::SSH::AuthenticationFailed
- Net::SSH::Buffer
- Net::SSH::ChannelOpenFailed
- Net::SSH::ChannelRequestFailed
- Net::SSH::Compat
- Net::SSH::Config
- Net::SSH::Connection
- Net::SSH::Connection::Channel
- Net::SSH::Connection::Constants
- Net::SSH::Connection::Keepalive
- Net::SSH::Connection::Session
- Net::SSH::Connection::Session::NilChannel
- Net::SSH::Connection::Term
- Net::SSH::ConnectionTimeout
- Net::SSH::Disconnect
- Net::SSH::Exception
- Net::SSH::HostKeyError
- Net::SSH::HostKeyMismatch
- Net::SSH::HostKeyUnknown
- Net::SSH::KeyFactory
- Net::SSH::KnownHosts
- Net::SSH::Loggable
- Net::SSH::Packet
- Net::SSH::PromptMethods
- Net::SSH::PromptMethods::Clear
- Net::SSH::PromptMethods::Highline
- Net::SSH::PromptMethods::Termios
- Net::SSH::Proxy
- Net::SSH::Proxy::Command
- Net::SSH::Proxy::ConnectError
- Net::SSH::Proxy::Error
- Net::SSH::Proxy::HTTP
- Net::SSH::Proxy::SOCKS4
- Net::SSH::Proxy::SOCKS5
- Net::SSH::Proxy::UnauthorizedError
- Net::SSH::Test
- Net::SSH::Test::Channel
- Net::SSH::Test::Extensions
- Net::SSH::Test::Extensions::BufferedIo
- Net::SSH::Test::Extensions::Channel
- Net::SSH::Test::Extensions::IO
- Net::SSH::Test::Extensions::IO::ClassMethods
- Net::SSH::Test::Extensions::PacketStream
- Net::SSH::Test::Kex
- Net::SSH::Test::LocalPacket
- Net::SSH::Test::Packet
- Net::SSH::Test::RemotePacket
- Net::SSH::Test::Script
- Net::SSH::Test::Socket
- Net::SSH::Timeout
- Net::SSH::Transport
- Net::SSH::Transport::Algorithms
- Net::SSH::Transport::CTR
- Net::SSH::Transport::CipherFactory
- Net::SSH::Transport::Constants
- Net::SSH::Transport::HMAC
- Net::SSH::Transport::HMAC::Abstract
- Net::SSH::Transport::HMAC::MD5
- Net::SSH::Transport::HMAC::MD5_96
- Net::SSH::Transport::HMAC::None
- Net::SSH::Transport::HMAC::RIPEMD160
- Net::SSH::Transport::HMAC::SHA1
- Net::SSH::Transport::HMAC::SHA1_96
- Net::SSH::Transport::HMAC::SHA2_256
- Net::SSH::Transport::HMAC::SHA2_256_96
- Net::SSH::Transport::HMAC::SHA2_512
- Net::SSH::Transport::HMAC::SHA2_512_96
- Net::SSH::Transport::IdentityCipher
- Net::SSH::Transport::Kex
- Net::SSH::Transport::Kex::DiffieHellmanGroup14SHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroup1SHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA1
- Net::SSH::Transport::Kex::DiffieHellmanGroupExchangeSHA256
- Net::SSH::Transport::Kex::EcdhSHA2NistP256
- Net::SSH::Transport::Kex::EcdhSHA2NistP384
- Net::SSH::Transport::Kex::EcdhSHA2NistP521
- Net::SSH::Transport::KeyExpander
- Net::SSH::Transport::PacketStream
- Net::SSH::Transport::ServerVersion
- Net::SSH::Transport::Session
- Net::SSH::Transport::State
- Net::SSH::Verifiers
- Net::SSH::Verifiers::Lenient
- Net::SSH::Verifiers::Null
- Net::SSH::Verifiers::Secure
- Net::SSH::Verifiers::Strict
- Net::SSH::Version
- OpenSSL
- OpenSSL::BN
- OpenSSL::PKey
- OpenSSL::PKey::DH
- OpenSSL::PKey::DSA
- OpenSSL::PKey::EC
- OpenSSL::PKey::OpenSSL
- OpenSSL::PKey::OpenSSL::PKey
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL::PKey
- OpenSSL::PKey::OpenSSL::PKey::OpenSSL::PKey::ECError
- OpenSSL::PKey::PKey
- OpenSSL::PKey::RSA
- String

No matching classes.

# Net::SSH::Connection::Keepalive

### Public Class Methods

new(session) click to toggle source

    # File lib/net/ssh/connection/keepalive.rb, line 7
    def initialize(session)
      @last_keepalive_sent_at = nil
      @unresponded_keepalive_count = 0
      @session = session
      self.logger = session.logger
    end

### Public Instance Methods

enabled?() click to toggle source

    # File lib/net/ssh/connection/keepalive.rb, line 18
    def enabled?
      options[:keepalive]
    end

interval() click to toggle source

    # File lib/net/ssh/connection/keepalive.rb, line 22
    def interval
      options[:keepalive_interval] || Session::DEFAULT_IO_SELECT_TIMEOUT
    end

keepalive_maxcount() click to toggle source

    # File lib/net/ssh/connection/keepalive.rb, line 32
    def keepalive_maxcount
      (options[:keepalive_maxcount] || 3).to_i
    end

options() click to toggle source

    # File lib/net/ssh/connection/keepalive.rb, line 14
    def options
      @session.options
    end

send_as_needed(readers, writers) click to toggle source

    # File lib/net/ssh/connection/keepalive.rb, line 36
    def send_as_needed(readers, writers)
      return unless readers.nil? && writers.nil?
      return unless should_send?
      info { "sending keepalive #{@unresponded_keepalive_count}" }

      @unresponded_keepalive_count += 1
      @session.send_global_request("keepalive@openssh.com") { |success, response|
        debug { "keepalive response successful. Missed #{@unresponded_keepalive_count-1} keepalives" }
        @unresponded_keepalive_count = 0
      }
      @last_keepalive_sent_at = Time.now
      if keepalive_maxcount > 0 && @unresponded_keepalive_count > keepalive_maxcount
        error { "Timeout, server #{@session.host} not responding. Missed #{@unresponded_keepalive_count-1} timeouts." }
        @unresponded_keepalive_count = 0
        raise Net::SSH::Timeout, "Timeout, server #{@session.host} not responding."
      end
    end

should_send?() click to toggle source

    # File lib/net/ssh/connection/keepalive.rb, line 26
    def should_send?
      return false unless enabled?
      return true unless @last_keepalive_sent_at
      Time.now - @last_keepalive_sent_at >= interval
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.