Comparison

net/server_event.lua @ 5966:958ad646c0f2

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 5965:99d55f12a26f
child 5967:3b7206981317
comparison
equal deleted inserted replaced
5965:99d55f12a26f 5966:958ad646c0f2
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('#', ...)), ...)
740 if sslctx and not has_luasec then 741 if sslctx and not has_luasec then
741 debug "need luasec, but not available" 742 debug "need luasec, but not available"
742 return nil, "luasec not found" 743 return nil, "luasec not found"
743 end 744 end
744 if not typ then 745 if not typ then
745 typ = "tcp" 746 local addrinfo, err = getaddrinfo(addr)
747 if not addrinfo then return nil, err end
748 if addrinfo[1] and addrinfo[1].family == "inet6" then
749 typ = "tcp6"
750 else
751 typ = "tcp"
752 end
746 end 753 end
747 local create = socket[typ] 754 local create = socket[typ]
748 if type( create ) ~= "function" then 755 if type( create ) ~= "function" then
749 return nil, "invalid socket type" 756 return nil, "invalid socket type"
750 end 757 end