// addServer : add the proxy server
addServer : add the proxy server
// addServer : add the proxy server
func addServer(svcName string, ports []int32) {
	var ip string
	st := addrByService.getAddrTable(svcName)
	if st != nil {
		if len(ports) == 0 && len(st.ports) == 0 {
			unused = append(unused, st.ip)
			addrByService.delAddrTable(svcName)
			return
		}
		ip = st.ip
	} else {
		if len(ports) == 0 {
			return
		}
		if len(unused) == 0 {
			expandIpPool()
		}
		ip = unused[0]
		unused = unused[1:]
	}
	lns := make([]net.Listener, 0)
	for _, port := range ports {
		addr := ip + ":" + strconv.FormatUint(uint64(port), 10)
		klog.Infof("[L4 Proxy] Start listen %s,%d for proxy", addr, port)
		ln, err := net.Listen("tcp", addr)
		if err != nil {
			klog.Errorf("[L4 Proxy] %s", err)
			continue
		}
		lns = append(lns, ln)
		server := listener{
			ln:          ln,
			serviceName: svcName,
			fd:          int32(getAndSetSocket(ln, true)),
		}
		serve.Store(server.fd, server)
		epoll.EpollCtrlAdd(server.fd)
	}
	if st != nil {
		st.lns = append(st.lns, lns...)
		st.ports = append(st.ports, ports...)
	} else {
		st = &serviceTable{
			ip:    ip,
			lns:   lns,
			ports: ports,
		}
		addrByService.addAddrTable(svcName, st)
	}
}
func addServer ( svcName string , ports [ ] int32 ) { var ip string st := addrByService . getAddrTable ( svcName ) if st != nil { if len ( ports ) == 0 && len ( st . ports ) == 0 { unused = append ( unused , st . ip ) addrByService . delAddrTable ( svcName ) return } ip = st . ip } else { if len ( ports ) == 0 { return } if len ( unused ) == 0 { expandIpPool ( ) } ip = unused [ 0 ] unused = unused [ 1 : ] } lns := make ( [ ] net . Listener , 0 ) for _ , port := range ports { addr := ip + " " + strconv . FormatUint ( uint64 ( port ) , 10 ) klog . Infof ( " " , addr , port ) ln , err := net . Listen ( " " , addr ) if err != nil { klog . Errorf ( " " , err ) continue } lns = append ( lns , ln ) server := listener { ln : ln , serviceName : svcName , fd : int32 ( getAndSetSocket ( ln , true ) ) , } serve . Store ( server . fd , server ) epoll . EpollCtrlAdd ( server . fd ) } if st != nil { st . lns = append ( st . lns , lns ... ) st . ports = append ( st . ports , ports ... ) } else { st = & serviceTable { ip : ip , lns : lns , ports : ports , } addrByService . addAddrTable ( svcName , st ) } }
addServer : add the proxy server
addServer : add the proxy server