In Files

  • mrbgems/mruby-socket/mrblib/socket.rb
  • mrbgems/mruby-socket/test/addrinfo.rb
  • mrbgems/mruby-socket/test/socket.rb
  • mrbgems/mruby-socket/test/udpsocket.rb

Socket

Public Class Methods

getaddrinfo(nodename, servname, family=nil, socktype=nil, protocol=nil, flags=0) click to toggle source

def self.accept_loop

 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 360
def self.getaddrinfo(nodename, servname, family=nil, socktype=nil, protocol=nil, flags=0)
  Addrinfo.getaddrinfo(nodename, servname, family, socktype, protocol, flags).map { |ai|
    ary = ai._to_array
    ary[2] = nodename
    ary[4] = ai.afamily
    ary[5] = ai.socktype
    ary[6] = ai.protocol
    ary
  }
end
            
new(domain, type, protocol=0) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 354
def initialize(domain, type, protocol=0)
  super(Socket._socket(domain, type, protocol), "r+")
end
            
open(*args) click to toggle source

def self.getnameinfo def self.ip_address_list

 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 374
def self.open(*args)
  new(args)
end
            
pack_sockaddr_in(port, host) click to toggle source
Alias for: sockaddr_in
sockaddr_in(port, host) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 378
def self.sockaddr_in(port, host)
  ai = Addrinfo.getaddrinfo(host, port, nil, Socket::SOCK_DGRAM)[0]
  ai.to_sockaddr
end
            
Also aliased as: pack_sockaddr_in
unpack_sockaddr_in(sa) click to toggle source

def self.tcp def self.tcp_server_loop def self.tcp_server_sockets def self.udp_server_loop def self.udp_server_loop_on def self.udp_server_recv def self.udp_server_sockets def self.unix(path) def self.unix_server_loop def self.unix_server_socket

 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 394
def self.unpack_sockaddr_in(sa)
  Addrinfo.new(sa).ip_unpack.reverse
end
            
unpack_sockaddr_un(sa) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 398
def self.unpack_sockaddr_un(sa)
  Addrinfo.new(sa).unix_path
end
            

Public Instance Methods

accept() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 408
def accept
  fd, addr = self.sysaccept
  [ Socket.for_fd(fd), addr ]
end
            
accept_nonblock() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 413
def accept_nonblock
  begin
    self._setnonblock(true)
    self.accept
  ensure
    self._setnonblock(false)
  end
end
            
bind(sockaddr) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 422
def bind(sockaddr)
  sockaddr = sockaddr.to_sockaddr if sockaddr.is_a? Addrinfo
  Socket._bind(self.fileno, sockaddr)
  0
end
            
connect(sockaddr) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 428
def connect(sockaddr)
  sockaddr = sockaddr.to_sockaddr if sockaddr.is_a? Addrinfo
  Socket._connect(self.fileno, sockaddr)
  0
end
            
connect_nonblock(sockaddr) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 434
def connect_nonblock(sockaddr)
  begin
    self._setnonblock(true)
    self.connect(sockaddr)
  ensure
    self._setnonblock(false)
  end
end
            
listen(backlog) click to toggle source

def ipv6only!

 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 445
def listen(backlog)
  Socket._listen(self.fileno, backlog)
  0
end
            
recvfrom(maxlen, flags=0) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 450
def recvfrom(maxlen, flags=0)
  msg, sa = _recvfrom(maxlen, flags)
  socktype = self.getsockopt(Socket::SOL_SOCKET, Socket::SO_TYPE).int
  [ msg, Addrinfo.new(sa, Socket::PF_UNSPEC, socktype) ]
end
            
recvfrom_nonblock(*args) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 456
def recvfrom_nonblock(*args)
  begin
    self._setnonblock(true)
    self._recvfrom(*args)
  ensure
    self._setnonblock(false)
  end
end
            
sysaccept() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 465
def sysaccept
  Socket._accept2(self.fileno)
end