Merge pull request #81 from lovedboy/master

fix listenedAddr  bug when TCP or UDP bind dynamic port
This commit is contained in:
Matt Joiner 2016-05-24 19:09:57 +10:00
commit 0a9db65df1
1 changed files with 4 additions and 1 deletions

View File

@ -223,18 +223,21 @@ func listen(tcp, utp bool, networkSuffix, addr string) (tcpL net.Listener, utpSo
if tcp && utp && port == 0 {
return listenBothSameDynamicPort(networkSuffix, host)
}
listenedAddr = addr
if tcp {
tcpL, err = listenTCP(networkSuffix, addr)
if err != nil {
return
}
listenedAddr = tcpL.Addr().String()
}
if utp {
utpSock, err = listenUTP(networkSuffix, addr)
if err != nil && tcp {
tcpL.Close()
return
}
listenedAddr = utpSock.Addr().String()
}
return
}