Skip to content

Commit

Permalink
🔧 Use client config for open_timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
nevans committed Jun 10, 2024
1 parent 8839be0 commit 6836130
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ class << self
# Seconds to wait until a connection is opened.
# If the IMAP object cannot open a connection within this time,
# it raises a Net::OpenTimeout exception. The default value is 30 seconds.
attr_reader :open_timeout
def open_timeout; config.open_timeout end

# Seconds to wait until an IDLE response is received.
attr_reader :idle_response_timeout
Expand Down Expand Up @@ -825,13 +825,14 @@ class << self
# config object for inheritance. Every Net::IMAP client has its own
# unique #config for overrides.
#
# [open_timeout]
# Seconds to wait until a connection is opened
# [idle_response_timeout]
# Seconds to wait until an IDLE response is received
#
# Any other keyword arguments will be forwarded to Config.new, to create the
# client's #config.
# client's #config. For example:
#
# [open_timeout]
# Seconds to wait until a connection is opened
#
# See DeprecatedClientOptions.new for deprecated arguments.
#
Expand Down Expand Up @@ -889,14 +890,13 @@ class << self
# Connected to the host successfully, but it immediately said goodbye.
#
def initialize(host, port: nil, ssl: nil,
open_timeout: 30, idle_response_timeout: 5,
idle_response_timeout: 5,
config: Config.global, **config_options)
super()
# Config options
@host = host
@config = Config.new(config, **config_options)
@port = port || (ssl ? SSL_PORT : PORT)
@open_timeout = Integer(open_timeout)
@idle_response_timeout = Integer(idle_response_timeout)
@ssl_ctx_params, @ssl_ctx = build_ssl_ctx(ssl)

Expand Down Expand Up @@ -2636,12 +2636,12 @@ def start_receiver_thread
end

def tcp_socket(host, port)
s = Socket.tcp(host, port, :connect_timeout => @open_timeout)
s = Socket.tcp(host, port, :connect_timeout => open_timeout)
s.setsockopt(:SOL_SOCKET, :SO_KEEPALIVE, true)
s
rescue Errno::ETIMEDOUT
raise Net::OpenTimeout, "Timeout to open TCP connection to " +
"#{host}:#{port} (exceeds #{@open_timeout} seconds)"
"#{host}:#{port} (exceeds #{open_timeout} seconds)"
end

def receive_responses
Expand Down Expand Up @@ -2959,7 +2959,7 @@ def start_tls_session
@sock = SSLSocket.new(@sock, ssl_ctx)
@sock.sync_close = true
@sock.hostname = @host if @sock.respond_to? :hostname=
ssl_socket_connect(@sock, @open_timeout)
ssl_socket_connect(@sock, open_timeout)
if ssl_ctx.verify_mode != VERIFY_NONE
@sock.post_connection_check(@host)
@tls_verified = true
Expand Down

0 comments on commit 6836130

Please sign in to comment.