lib/reel/websocket.rb in reel-0.3.0 vs lib/reel/websocket.rb in reel-0.4.0.pre
- old
+ new
@@ -45,11 +45,11 @@
define_method meth do |&proc|
@parser.send __method__, &proc
end
end
- def read_every n, unit = :s
+ def read_every(n, unit = :s)
cancel_timer! # only one timer allowed per stream
seconds = case unit.to_s
when /\Am/
n * 60
when /\Ah/
@@ -63,24 +63,27 @@
alias read_frequency read_every
def read
@parser.append @socket.readpartial(Connection::BUFFER_SIZE) until msg = @parser.next_message
msg
- rescue => e
+ rescue
cancel_timer!
- @on_error ? @on_error.call(e) : raise(e)
+ raise
end
def body
nil
end
def write(msg)
@socket << ::WebSocket::Message.new(msg).to_data
msg
- rescue => e
+ rescue Errno::EPIPE
cancel_timer!
- @on_error ? @on_error.call(e) : raise(e)
+ raise SocketError, "error writing to socket"
+ rescue
+ cancel_timer!
+ raise
end
alias_method :<<, :write
def closed?
@socket.closed?