Skip to content

Commit d9fdfbe

Browse files
committed
🔧 Use client config for open_timeout
1 parent f971c6c commit d9fdfbe

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/net/imap.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ class << self
775775
# Seconds to wait until a connection is opened.
776776
# If the IMAP object cannot open a connection within this time,
777777
# it raises a Net::OpenTimeout exception. The default value is 30 seconds.
778-
attr_reader :open_timeout
778+
def open_timeout; config.open_timeout end
779779

780780
# Seconds to wait until an IDLE response is received.
781781
attr_reader :idle_response_timeout
@@ -825,13 +825,14 @@ class << self
825825
# config object for inheritance. Every Net::IMAP client has its own
826826
# unique #config for overrides.
827827
#
828-
# [open_timeout]
829-
# Seconds to wait until a connection is opened
830828
# [idle_response_timeout]
831829
# Seconds to wait until an IDLE response is received
832830
#
833831
# Any other keyword arguments will be forwarded to Config.new, to create the
834-
# client's #config.
832+
# client's #config. For example:
833+
#
834+
# [open_timeout]
835+
# Seconds to wait until a connection is opened
835836
#
836837
# See DeprecatedClientOptions.new for deprecated arguments.
837838
#
@@ -889,14 +890,13 @@ class << self
889890
# Connected to the host successfully, but it immediately said goodbye.
890891
#
891892
def initialize(host, port: nil, ssl: nil,
892-
open_timeout: 30, idle_response_timeout: 5,
893+
idle_response_timeout: 5,
893894
config: Config.global, **config_options)
894895
super()
895896
# Config options
896897
@host = host
897898
@config = Config.new(config, **config_options)
898899
@port = port || (ssl ? SSL_PORT : PORT)
899-
@open_timeout = Integer(open_timeout)
900900
@idle_response_timeout = Integer(idle_response_timeout)
901901
@ssl_ctx_params, @ssl_ctx = build_ssl_ctx(ssl)
902902

@@ -2636,12 +2636,12 @@ def start_receiver_thread
26362636
end
26372637

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

26472647
def receive_responses
@@ -2959,7 +2959,7 @@ def start_tls_session
29592959
@sock = SSLSocket.new(@sock, ssl_ctx)
29602960
@sock.sync_close = true
29612961
@sock.hostname = @host if @sock.respond_to? :hostname=
2962-
ssl_socket_connect(@sock, @open_timeout)
2962+
ssl_socket_connect(@sock, open_timeout)
29632963
if ssl_ctx.verify_mode != VERIFY_NONE
29642964
@sock.post_connection_check(@host)
29652965
@tls_verified = true

0 commit comments

Comments
 (0)