summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-01-02 00:22:40 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-01-02 00:22:40 +0000
commit21f3dfcaa958a2ab807e60165130e2f7650ea325 (patch)
treeae050836f5729e4d6c2254227312486c0433d2e1 /lib
parentc6af7de45f49f74d4ff6f85eb61b27f7b7275335 (diff)
Fix reconnect errors
Diffstat (limited to 'lib')
-rw-r--r--lib/rbot/ircsocket.rb46
1 files changed, 27 insertions, 19 deletions
diff --git a/lib/rbot/ircsocket.rb b/lib/rbot/ircsocket.rb
index 53182195..e70528ea 100644
--- a/lib/rbot/ircsocket.rb
+++ b/lib/rbot/ircsocket.rb
@@ -318,13 +318,13 @@ module Irc
@sock=TCPSocket.new(@server, @port)
end
if(@ssl)
- require 'openssl'
- ssl_context = OpenSSL::SSL::SSLContext.new()
- ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
- @rawsock = @sock
- @sock = OpenSSL::SSL::SSLSocket.new(@sock, ssl_context)
- @sock.sync_close = true
- @sock.connect
+ require 'openssl'
+ ssl_context = OpenSSL::SSL::SSLContext.new()
+ ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ @rawsock = @sock
+ @sock = OpenSSL::SSL::SSLSocket.new(@rawsock, ssl_context)
+ @sock.sync_close = true
+ @sock.connect
end
@qthread = false
@qmutex = Mutex.new
@@ -362,6 +362,15 @@ module Irc
end
end
+ def handle_socket_error(string, err)
+ error "#{string} failed: #{err.inspect}"
+ debug err.backtrace.join("\n")
+ # We assume that an error means that there are connection
+ # problems and that we should reconnect, so we
+ shutdown
+ raise SocketError.new(err.inspect)
+ end
+
# get the next line from the server (blocks)
def gets
if @sock.nil?
@@ -375,9 +384,7 @@ module Irc
debug "RECV: #{reply.inspect}"
return reply
rescue => e
- warning "socket get failed: #{e.inspect}"
- debug e.backtrace.join("\n")
- return nil
+ handle_socket_error(:RECV, e)
end
end
@@ -414,7 +421,7 @@ module Irc
end
@flood_send = now if @flood_send < now
debug "can send #{@sendq_burst - @burst} lines, there are #{@sendq.length} to send"
- while !@sendq.empty? and @burst < @sendq_burst and @flood_send - now < MAX_IRC_SEND_PENALTY
+ while !@sendq.empty? and @burst < @sendq_burst and @flood_send - now < MAX_IRC_SEND_PENALTY
debug "sending message (#{@flood_send - now} < #{MAX_IRC_SEND_PENALTY})"
puts_critical(@sendq.shift, true)
end
@@ -452,13 +459,15 @@ module Irc
# shutdown the connection to the server
def shutdown(how=2)
- if(@ssl)
- @rawsock.shutdown(how) unless @rawsock.nil?
- @rawsock = nil
- else
- @sock.shutdown(how) unless @sock.nil?
- @sock = nil
+ return unless connected?
+ begin
+ @sock.close
+ rescue => err
+ error "error while shutting down: #{err.inspect}"
+ debug err.backtrace.join("\n")
end
+ @rawsock = nil if @ssl
+ @sock = nil
@burst = 0
end
@@ -479,8 +488,7 @@ module Irc
@burst += 1
end
rescue => e
- error "SEND failed: #{e.inspect}"
- raise
+ handle_socket_error(:SEND, e)
end
end