Comparison

net/server_event.lua @ 6819:ffb2b5e31456

net.server_{select,event}: addclient: Use getaddrinfo to detect IP address type if no socket type argument given. (Argument must be given for non-TCP)
author Kim Alvefur <zash@zash.se>
date Mon, 23 Dec 2013 17:57:53 +0100
parent 6818:ae9d1289a868
child 6820:40d50c239564
child 6849:0455b9686e16
comparison
equal deleted inserted replaced
6818:ae9d1289a868 6819:ffb2b5e31456
44 local t_insert = table.insert 44 local t_insert = table.insert
45 local t_concat = table.concat 45 local t_concat = table.concat
46 46
47 local has_luasec, ssl = pcall ( require , "ssl" ) 47 local has_luasec, ssl = pcall ( require , "ssl" )
48 local socket = use "socket" or require "socket" 48 local socket = use "socket" or require "socket"
49 local getaddrinfo = socket.dns.getaddrinfo
49 50
50 local log = require ("util.logger").init("socket") 51 local log = require ("util.logger").init("socket")
51 52
52 local function debug(...) 53 local function debug(...)
53 return log("debug", ("%s "):rep(select('#', ...)), ...) 54 return log("debug", ("%s "):rep(select('#', ...)), ...)
746 if sslctx and not has_luasec then 747 if sslctx and not has_luasec then
747 debug "need luasec, but not available" 748 debug "need luasec, but not available"
748 return nil, "luasec not found" 749 return nil, "luasec not found"
749 end 750 end
750 if not typ then 751 if not typ then
751 typ = "tcp" 752 local addrinfo, err = getaddrinfo(addr)
753 if not addrinfo then return nil, err end
754 if addrinfo[1] and addrinfo[1].family == "inet6" then
755 typ = "tcp6"
756 else
757 typ = "tcp"
758 end
752 end 759 end
753 local create = socket[typ] 760 local create = socket[typ]
754 if type( create ) ~= "function" then 761 if type( create ) ~= "function" then
755 return nil, "invalid socket type" 762 return nil, "invalid socket type"
756 end 763 end