Skip to content

Commit

Permalink
Add support for I/O timeouts on Unix sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
nickamorim committed Jan 20, 2025
1 parent 261c452 commit c37be22
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/dalli/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def initialize(*_args)
end
end
else

##
# UNIX represents a UNIX domain socket, which is an interprocess communication
# mechanism between processes on the same host. Used when the Memcached server
Expand All @@ -171,9 +170,16 @@ def self.open(path, options = {})
Timeout.timeout(options[:socket_timeout]) do
sock = new(path)
sock.options = { path: path }.merge(options)
init_socket_options(sock, options)
sock
end
end

def self.init_socket_options(sock, options)
# Following the options supported in https://man7.org/linux/man-pages/man7/unix.7.html
sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_SNDBUF, options[:sndbuf]) if options[:sndbuf]
sock.timeout = options[:socket_timeout] if options[:socket_timeout] && sock.respond_to?(:timeout=)
end
end
end
end
Expand Down

0 comments on commit c37be22

Please sign in to comment.