Permalink
Browse files

Fix an infinite loop on quit.

  • Loading branch information...
1 parent 51f0928 commit 192a2fd04ad0a5d9aeb22187d9356f453064f248 @meh committed Jul 18, 2011
@@ -47,6 +47,10 @@ def self.debug (argument, options={})
$stderr.puts output
end
+ if ENV['DEBUG']
+ require 'ruby-debug'
+ end
+
module SSLUtils
def self.self_signed_certificate (bits, comment)
rsa = OpenSSL::PKey::RSA.new(bits)
@@ -53,8 +53,6 @@ def receive
begin; loop do
input << @socket.read_nonblock(4096)
-
- ap input
end; rescue Errno::EAGAIN, IO::WaitReadable; end
raise Errno::EPIPE if input.empty?
@@ -78,14 +76,16 @@ def receive
end; alias recv receive
def send (message)
+ return if disconnected?(true)
+
dispatcher.server.dispatch :output, self, message
@output.push(message)
flush
end
def flush
- return if @output.empty?
+ return if @output.empty? or disconnected?(true)
begin
@socket.write_nonblock("#{@last}\r\n") if @last
@@ -115,7 +115,7 @@ def flush
end
def handle
- return if @handling or @input.empty?
+ return if disconnected?(true) or @handling or @input.empty?
@handling = true
@@ -135,24 +135,24 @@ def handle
def disconnect (message, options={})
return if disconnected? and @told
+ @told = true
+
server.fire :disconnect, self, message
IRC.debug "#{self} disconnecting because: #{message}"
connected_to.clients.delete(self)
dispatcher.wakeup reset: true
- @told = true
-
begin
flush
rescue; ensure
@socket.close rescue nil
end
end
- def disconnected?
- return true if @told
+ def disconnected? (real=false)
+ return true if @told and not real
begin
@socket.closed?
@@ -64,7 +64,7 @@ def accept
begin
if ssl?
socket = timeout((self.server.options[:server][:timeout] || 15).to_i) do
- ssl = OpenSSL::SSL::SSLSocket.new(socket, server.context)
+ ssl = OpenSSL::SSL::SSLSocket.new(socket, @context)
ssl.accept
ssl
end
Oops, something went wrong.

0 comments on commit 192a2fd

Please sign in to comment.