Class: UNIXServer

Inherits:
UNIXSocket show all
Defined in:
lib/socket/unix_server.rb

Instance Method Summary collapse

Methods inherited from UNIXSocket

#addr, #local_address, #path, #peeraddr, #recv_io, #recvfrom, #remote_address, socketpair

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, #local_address, #recv, #recv_nonblock, #recvmsg, #recvmsg_nonblock, #remote_address, #send, #sendmsg, #sendmsg_nonblock, #setsockopt, #shutdown

Constructor Details

#initialize(path) ⇒ UNIXServer

Returns a new instance of UNIXServer.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/socket/unix_server.rb', line 2

def initialize(path)
  @no_reverse_lookup = self.class.do_not_reverse_lookup
  @path              = 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.bind(descriptor, sockaddr)

  Errno.handle('bind(2)') if status < 0

  listen(Socket::SOMAXCONN)
end

Instance Method Details

#acceptObject



25
26
27
# File 'lib/socket/unix_server.rb', line 25

def accept
  RubySL::Socket.accept(self, UNIXSocket)[0]
end

#accept_nonblockObject



29
30
31
# File 'lib/socket/unix_server.rb', line 29

def accept_nonblock
  RubySL::Socket.accept_nonblock(self, UNIXSocket)[0]
end

#listen(backlog) ⇒ Object



21
22
23
# File 'lib/socket/unix_server.rb', line 21

def listen(backlog)
  RubySL::Socket.listen(self, backlog)
end

#sysacceptObject



33
34
35
# File 'lib/socket/unix_server.rb', line 33

def sysaccept
  accept.fileno
end