Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 14 additions & 27 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3515,27 +3515,8 @@ def tcp_socket(host, port)
end

def receive_responses
connection_closed = false
until connection_closed
synchronize do
@exception = nil
end
begin
resp = get_response
rescue Exception => e
synchronize do
state_logout!
@sock.close
@exception = e
end
break
end
unless resp
synchronize do
@exception = EOFError.new("end of file reached")
end
break
end
loop do
resp = get_response or raise EOFError, "end of file reached"
begin
synchronize do
case resp
Expand Down Expand Up @@ -3566,25 +3547,31 @@ def receive_responses
@response_handlers.each do |handler|
handler.call(resp)
end
end
rescue Exception => e
@exception = e
synchronize do
rescue Exception => e
@exception = e
@tagged_response_arrival.broadcast
@continuation_request_arrival.broadcast
ensure
@exception = nil unless connection_closed
end
end
end
ensure
synchronize do
if $!
# Handling exceptions here, not in a rescue clause, so the lock isn't
# released and reacquired between rescue and ensure clauses.
@exception ||= $!
@sock.close
end
state_logout!
@receiver_thread_terminating = true
@tagged_response_arrival.broadcast
@continuation_request_arrival.broadcast
if @idle_done_cond
@idle_done_cond.signal
end
end
ensure
state_logout!
end

def get_response
Expand Down
Loading