lib/blather/stream.rb in blather-0.5.8 vs lib/blather/stream.rb in blather-0.5.9
- old
+ new
@@ -48,10 +48,11 @@
# client = Blather::Stream.start MyClient.new, "jid@domain/res", "pass"
# client.write "[pure xml over the wire]"
class Stream < EventMachine::Connection
# Connection not found
class NoConnection < RuntimeError; end
+ class ConnectionFailed < RuntimeError; end
# @private
STREAM_NS = 'http://etherx.jabber.org/streams'
attr_accessor :password
attr_reader :jid
@@ -141,10 +142,11 @@
# Called when EM completes the connection to the server
# this kicks off the starttls/authorize/bind process
# @private
def connection_completed
+ @connected = true
# @keepalive = EM::PeriodicTimer.new(60) { send_data ' ' }
start
end
# Called by EM with data from the wire
@@ -176,16 +178,17 @@
end
# Called by EM after the connection has started
# @private
def post_init
- @connected = true
+ @inited = true
end
# Called by EM when the connection is closed
# @private
def unbind
- raise NoConnection unless @connected
+ raise NoConnection unless @inited
+ raise ConnectionFailed unless @connected
# @keepalive.cancel
@state = :stopped
@client.receive_data @error if @error
@client.unbind