In Files

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

TCPSocket

Public Class Methods

new(host, service, local_host=nil, local_service=nil) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 231
def initialize(host, service, local_host=nil, local_service=nil)
  if @init_with_fd
    super(host, service)
  else
    s = nil
    e = SocketError
    Addrinfo.foreach(host, service) { |ai|
      begin
        s = Socket._socket(ai.afamily, Socket::SOCK_STREAM, 0)
        if local_host or local_service
          local_host ||= (ai.afamily == Socket::AF_INET) ? "0.0.0.0" : "::"
          local_service ||= "0"
          bi = Addrinfo.getaddrinfo(local_host, local_service, ai.afamily, ai.socktype)[0]
          Socket._bind(s, bi.to_sockaddr)
        end
        Socket._connect(s, ai.to_sockaddr)
        super(s, "r+")
        return
      rescue => e0
        e = e0
      end
    }
    raise e
  end
end
            
new_with_prelude(pre, *args) click to toggle source
 
               # File mrbgems/mruby-socket/mrblib/socket.rb, line 257
def self.new_with_prelude pre, *args
  o = self._allocate
  o.instance_eval(&pre)
  o.initialize(*args)
  o
end