Comparison

net/server_select.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
49 --// extern libs //-- 49 --// extern libs //--
50 50
51 local has_luasec, luasec = pcall ( require , "ssl" ) 51 local has_luasec, luasec = pcall ( require , "ssl" )
52 local luasocket = use "socket" or require "socket" 52 local luasocket = use "socket" or require "socket"
53 local luasocket_gettime = luasocket.gettime 53 local luasocket_gettime = luasocket.gettime
54 local getaddrinfo = luasocket.dns.getaddrinfo
54 55
55 --// extern lib methods //-- 56 --// extern lib methods //--
56 57
57 local ssl_wrap = ( has_luasec and luasec.wrap ) 58 local ssl_wrap = ( has_luasec and luasec.wrap )
58 local socket_bind = luasocket.bind 59 local socket_bind = luasocket.bind
940 err = "invalid port" 941 err = "invalid port"
941 elseif sslctx and not has_luasec then 942 elseif sslctx and not has_luasec then
942 err = "luasec not found" 943 err = "luasec not found"
943 end 944 end
944 if not typ then 945 if not typ then
945 typ = "tcp" 946 local addrinfo, err = getaddrinfo(address)
947 if not addrinfo then return nil, err end
948 if addrinfo[1] and addrinfo[1].family == "inet6" then
949 typ = "tcp6"
950 else
951 typ = "tcp"
952 end
946 end 953 end
947 local create = luasocket[typ] 954 local create = luasocket[typ]
948 if type( create ) ~= "function" then 955 if type( create ) ~= "function" then
949 err = "invalid socket type" 956 err = "invalid socket type"
950 end 957 end
958
951 if err then 959 if err then
952 out_error( "server.lua, addclient: ", err ) 960 out_error( "server.lua, addclient: ", err )
953 return nil, err 961 return nil, err
954 end 962 end
955 963