def open_connection
client_props = { :platform => 'Ruby', :product => 'Bunny', :information => 'http://github.com/ruby-amqp/bunny', :version => VERSION }
start_opts = {
:client_properties => client_props,
:mechanism => 'PLAIN',
:response => "\0" + @user + "\0" + @pass,
:locale => 'en_US'
}
send_frame(Qrack::Protocol09::Connection::StartOk.new(start_opts))
frame = next_frame
raise Bunny::ProtocolError, "Connection failed - user: #{@user}" if frame.nil?
method = frame.payload
if method.is_a?(Qrack::Protocol09::Connection::Tune)
send_frame(Qrack::Protocol09::Connection::TuneOk.new(:channel_max => @channel_max, :frame_max => @frame_max, :heartbeat => @heartbeat))
end
send_frame(Qrack::Protocol09::Connection::Open.new(:virtual_host => @vhost, :reserved_1 => 0, :reserved_2 => false))
raise Bunny::ProtocolError, 'Cannot open connection' unless next_method.is_a?(Qrack::Protocol09::Connection::OpenOk)
end