# HG changeset patch # User Kim Alvefur # Date 1387817873 -3600 # Node ID ffb2b5e314568dda5629cbcbce062fc1f555097f # Parent ae9d1289a8682385cc5c961e7e4d9a0e15d369aa 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) diff -r ae9d1289a868 -r ffb2b5e31456 net/server_event.lua --- a/net/server_event.lua Mon Dec 23 17:55:41 2013 +0100 +++ b/net/server_event.lua Mon Dec 23 17:57:53 2013 +0100 @@ -46,6 +46,7 @@ local has_luasec, ssl = pcall ( require , "ssl" ) local socket = use "socket" or require "socket" +local getaddrinfo = socket.dns.getaddrinfo local log = require ("util.logger").init("socket") @@ -748,7 +749,13 @@ return nil, "luasec not found" end if not typ then - typ = "tcp" + local addrinfo, err = getaddrinfo(addr) + if not addrinfo then return nil, err end + if addrinfo[1] and addrinfo[1].family == "inet6" then + typ = "tcp6" + else + typ = "tcp" + end end local create = socket[typ] if type( create ) ~= "function" then diff -r ae9d1289a868 -r ffb2b5e31456 net/server_select.lua --- a/net/server_select.lua Mon Dec 23 17:55:41 2013 +0100 +++ b/net/server_select.lua Mon Dec 23 17:57:53 2013 +0100 @@ -51,6 +51,7 @@ local has_luasec, luasec = pcall ( require , "ssl" ) local luasocket = use "socket" or require "socket" local luasocket_gettime = luasocket.gettime +local getaddrinfo = luasocket.dns.getaddrinfo --// extern lib methods //-- @@ -954,12 +955,19 @@ err = "luasec not found" end if not typ then - typ = "tcp" + local addrinfo, err = getaddrinfo(address) + if not addrinfo then return nil, err end + if addrinfo[1] and addrinfo[1].family == "inet6" then + typ = "tcp6" + else + typ = "tcp" + end end local create = luasocket[typ] if type( create ) ~= "function" then err = "invalid socket type" end + if err then out_error( "server.lua, addclient: ", err ) return nil, err