In Files

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

TCPServer

Public Class Methods

new(host=nil, service) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 268
def initialize(host=nil, service)
  ai = Addrinfo.getaddrinfo(host, service, nil, nil, nil, Socket::AI_PASSIVE)[0]
  @init_with_fd = true
  super(Socket._socket(ai.afamily, Socket::SOCK_STREAM, 0), "r+")
  if Socket.const_defined?(:SO_REUSEADDR)
    self.setsockopt(Socket::SOL_SOCKET, Socket::SO_REUSEADDR, true)
  end
  Socket._bind(self.fileno, ai.to_sockaddr)
  listen(5)
  self
end
            

Public Instance Methods

accept() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 280
def accept
  fd = self.sysaccept
  begin
    TCPSocket.new_with_prelude(proc { @init_with_fd = true }, fd, "r+")
  rescue
    IO._sysclose(fd) rescue nil
    raise
  end
end
            
accept_nonblock() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 290
def accept_nonblock
  begin
    self._setnonblock(true)
    self.accept
  ensure
    self._setnonblock(false)
  end
end
            
listen(backlog) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 299
def listen(backlog)
  Socket._listen(self.fileno, backlog)
  0
end
            
sysaccept() click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 304
def sysaccept
  Socket._accept(self.fileno)
end