Comparison

net/server_select.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 7041:aff786e7b4ce
comparison
equal deleted inserted replaced
6818:ae9d1289a868 6819:ffb2b5e31456
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
952 err = "invalid port" 953 err = "invalid port"
953 elseif sslctx and not has_luasec then 954 elseif sslctx and not has_luasec then
954 err = "luasec not found" 955 err = "luasec not found"
955 end 956 end
956 if not typ then 957 if not typ then
957 typ = "tcp" 958 local addrinfo, err = getaddrinfo(address)
959 if not addrinfo then return nil, err end
960 if addrinfo[1] and addrinfo[1].family == "inet6" then
961 typ = "tcp6"
962 else
963 typ = "tcp"
964 end
958 end 965 end
959 local create = luasocket[typ] 966 local create = luasocket[typ]
960 if type( create ) ~= "function" then 967 if type( create ) ~= "function" then
961 err = "invalid socket type" 968 err = "invalid socket type"
962 end 969 end
970
963 if err then 971 if err then
964 out_error( "server.lua, addclient: ", err ) 972 out_error( "server.lua, addclient: ", err )
965 return nil, err 973 return nil, err
966 end 974 end
967 975