Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Socket.unix
unix(path) { |socket| ... }
ext/socket/lib/socket.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.3.0/ext/socket/lib/socket.rb, line 1081
def self.unix(path) # :yield: socket
addr = Addrinfo.unix(path)
sock = addr.connect
if block_given?
begin
yield sock
ensure
sock.close
end
else
sock
end
end
creates a new socket connected to path using UNIX socket socket.
If a block is given, the block is called with the socket. The value of the block is returned. The socket is closed when this method returns.
If no block is given, the socket is returned.
Example
# talk to /tmp/sock socket. Socket.unix("/tmp/sock") {|sock| t = Thread.new { IO.copy_stream(sock, STDOUT) } IO.copy_stream(STDIN, sock) t.join }
See also
.udp_server_sockets
.unix_server_loop
.udp_server_recv
.unix_server_socket
also in
4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0