wait_for_message (Net::SSH::Transport::Session)

    # File lib/net/ssh/transport/session.rb, line 250
            def wait_for_message
              buffer = type = nil

              if @saved_message
                type, buffer = @saved_message
                @logger.debug "returning saved message: #{type}" if @logger.debug?
                @saved_message = nil
              else
                loop do
                  if @logger.debug?
                    @logger.debug "waiting for packet from server..."
                  end

                  buffer = @packet_receiver.get
                  next unless buffer

                  type = buffer.read_byte
                  @logger.debug "got packet of type #{type}" if @logger.debug?

                  case type
                    when DISCONNECT
                      reason_code = buffer.read_long
                      description = buffer.read_string
                      language = buffer.read_string
                      raise Net::SSH::Transport::Disconnect,
                        "disconnected: #{description} (#{reason_code})"

                    when IGNORE
                      # do nothing
                      @logger.info "received IGNORE message " +
                        "(#{buffer.read_string.inspect})" if @logger.debug?

                    when DEBUG
                      # do nothing
                      @logger.info "received DEBUG message" if @logger.debug?
                      always_display = buffer.read_bool
                      message = buffer.read_string
                      language = buffer.read_string
                      if always_display
                        @logger.warn "#{message} (#{language})" if @logger.warn?
                      else
                        @logger.debug "#{message} (#{language})" if @logger.debug?
                      end

                    when KEXINIT
                      # unless we're already doing a key-exchange, do key
                      # re-exchange
                      if !@doing_kexinit
                        @logger.info "re-key requested" if @logger.info?
                        @saved_message = [ type, buffer ]
                        kexinit
                      else
                        break
                      end

                    else
                      break
                  end
                end
              end

              return type, buffer
            end