Class: UNIXSocket
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BasicSocket
#close_read, #close_write, #connect_address, do_not_reverse_lookup, #do_not_reverse_lookup, do_not_reverse_lookup=, #do_not_reverse_lookup=, for_fd, #getpeereid, #getpeername, #getsockname, #getsockopt, #recv, #recv_nonblock, #recvmsg, #recvmsg_nonblock, #send, #sendmsg, #sendmsg_nonblock, #setsockopt, #shutdown
Constructor Details
Returns a new instance of UNIXSocket.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/socket/unix_socket.rb', line 17
def initialize(path)
@no_reverse_lookup = self.class.do_not_reverse_lookup
@path = ''
fd = RubySL::Socket::Foreign.socket(Socket::AF_UNIX, Socket::SOCK_STREAM, 0)
Errno.handle('socket(2)') if fd < 0
IO.setup(self, fd, 'r+', true)
binmode
sockaddr = Socket.sockaddr_un(path)
status = RubySL::Socket::Foreign.connect(descriptor, sockaddr)
Errno.handle('connect(2)') if status < 0
end
|
Class Method Details
.socketpair(type = Socket::SOCK_STREAM, protocol = 0) ⇒ Object
Also known as:
pair
Instance Method Details
#addr ⇒ Object
42
43
44
|
# File 'lib/socket/unix_socket.rb', line 42
def addr
['AF_UNIX', path]
end
|
#peeraddr ⇒ Object
46
47
48
49
50
|
# File 'lib/socket/unix_socket.rb', line 46
def peeraddr
path = RubySL::Socket::Foreign.getpeername(descriptor).unpack('SZ*')[1]
['AF_UNIX', path]
end
|
#recv_io(klass = IO, mode = nil) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/socket/unix_socket.rb', line 52
def recv_io(klass = IO, mode = nil)
begin
fd = recv_fd
rescue PrimitiveFailure
raise SocketError, "file descriptor was not passed"
end
return fd unless klass
if klass.is_a?(BasicSocket)
klass.for_fd(fd)
else
klass.for_fd(fd, mode)
end
end
|
#recvfrom(bytes_read, flags = 0) ⇒ Object
34
35
36
|
# File 'lib/socket/unix_socket.rb', line 34
def recvfrom(bytes_read, flags = 0)
socket_recv(bytes_read, flags, 2)
end
|
#remote_address ⇒ Object
74
75
76
77
78
|
# File 'lib/socket/unix_socket.rb', line 74
def remote_address
address = peeraddr
Addrinfo.new(Socket.pack_sockaddr_un(address[1]), :UNIX, :STREAM)
end
|