In Files

  • mrbgems/mruby-socket/mrblib/socket.rb

UNIXSocket

Public Class Methods

new(path, &block) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 471
def initialize(path, &block)
  if self.is_a? UNIXServer
    super(path, "r")
  else
    super(Socket._socket(Socket::AF_UNIX, Socket::SOCK_STREAM, 0), "r+")
    Socket._connect(self.fileno, Socket.sockaddr_un(path))

    if block_given?
      begin
        yield self
      ensure
        begin
          self.close unless self.closed?
        rescue StandardError
        end
      end
    end
  end
end
            
pair(type=Socket::SOCK_STREAM, protocol=0) click to toggle source
Alias for: socketpair
socketpair(type=Socket::SOCK_STREAM, protocol=0) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 491
def self.socketpair(type=Socket::SOCK_STREAM, protocol=0)
  a = Socket.socketpair(Socket::AF_UNIX, type, protocol)
  [ UNIXSocket.for_fd(a[0]), UNIXSocket.for_fd(a[1]) ]
end
            
Also aliased as: pair

Public Instance Methods

addr() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 500
def addr
  [ "AF_UNIX", path ]
end
            
path() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 504
def path
  Addrinfo.new(self.getsockname).unix_path
end
            
peeraddr() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 508
def peeraddr
  [ "AF_UNIX", Addrinfo.new(self.getpeername).unix_path ]
end
            
recvfrom(maxlen, flags=0) click to toggle source

def recv_io

 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 514
def recvfrom(maxlen, flags=0)
  msg, sa = _recvfrom(maxlen, flags)
  path = (sa.size > 0) ? Addrinfo.new(sa).unix_path : ""
  [ msg, [ "AF_UNIX", path ] ]
end