In Files

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

UDPSocket

Public Class Methods

new(af=Socket::AF_INET) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 310
def initialize(af=Socket::AF_INET)
  super(Socket._socket(af, Socket::SOCK_DGRAM, 0), "r+")
  @af = af
  self
end
            

Public Instance Methods

_sockaddr_in(port, host) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 347
def _sockaddr_in(port, host)
  ai = Addrinfo.getaddrinfo(host, port, @af, Socket::SOCK_DGRAM)[0]
  ai.to_sockaddr
end
            
bind(host, port) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 316
def bind(host, port)
  Socket._bind(self.fileno, _sockaddr_in(port, host))
  0
end
            
connect(host, port) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 321
def connect(host, port)
  Socket._connect(self.fileno, _sockaddr_in(port, host))
  0
end
            
recvfrom_nonblock(*args) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 326
def recvfrom_nonblock(*args)
  s = self
  begin
    self._setnonblock(true)
    self.recvfrom(*args)
  ensure
    # XXX: self is a SystemcallException here! (should be bug)
    s._setnonblock(false)
  end
end
            
send(mesg, flags, host=nil, port=nil) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 337
def send(mesg, flags, host=nil, port=nil)
  if port
    super(mesg, flags, _sockaddr_in(port, host))
  elsif host
    super(mesg, flags, host)
  else
    super(mesg, flags)
  end
end