func (listener *CarbonlinkListener) Listen(addr *net.TCPAddr) error {
	return listener.StartFunc(func() error {
		tcpListener, err := net.ListenTCP("tcp", addr)
		if err != nil {
			return err
		}

		listener.tcpListener = tcpListener

		listener.Go(func(exit chan bool) {
			select {
			case <-exit:
				tcpListener.Close()
			}
		})

		listener.Go(func(exit chan bool) {
			defer tcpListener.Close()

			for {
				conn, err := tcpListener.Accept()
				if err != nil {
					if strings.Contains(err.Error(), "use of closed network connection") {
						break
					}
					zapwriter.Logger("carbonlink").Error("failed to accept connection", zap.Error(err))
					continue
				}
				framedConn, _ := framing.NewConn(conn, byte(4), binary.BigEndian)
				framedConn.MaxFrameSize = 1048576 // 1MB max frame size for read and write
				go listener.HandleConnection(*framedConn)
			}
		})

		return nil
	})
}
func (listener *CarbonlinkListener) Listen(addr *net.TCPAddr) error {
	return listener.StartFunc(func() error {
		tcpListener, err := net.ListenTCP("tcp", addr)
		if err != nil {
			return err
		}

		listener.tcpListener = tcpListener

		listener.Go(func(exit chan bool) {
			select {
			case <-exit:
				tcpListener.Close()
			}
		})

		listener.Go(func(exit chan bool) {
			defer tcpListener.Close()

			for {
				conn, err := tcpListener.Accept()
				if err != nil {
					if strings.Contains(err.Error(), "use of closed network connection") {
						break
					}
					zapwriter.Logger("carbonlink").Error("failed to accept connection", zap.Error(err))
					continue
				}
				framedConn, _ := framing.NewConn(conn, byte(4), binary.BigEndian)
				framedConn.MaxFrameSize = 1048576 
				go listener.HandleConnection(*framedConn)
			}
		})

		return nil
	})
}
func ( listener * CarbonlinkListener ) Listen ( addr * net . TCPAddr ) error { return listener . StartFunc ( func ( ) error { tcpListener , err := net . ListenTCP ( " " , addr ) if err != nil { return err } listener . tcpListener = tcpListener listener . Go ( func ( exit chan bool ) { select { case <- exit : tcpListener . Close ( ) } } ) listener . Go ( func ( exit chan bool ) { defer tcpListener . Close ( ) for { conn , err := tcpListener . Accept ( ) if err != nil { if strings . Contains ( err . Error ( ) , " " ) { break } zapwriter . Logger ( " " ) . Error ( " " , zap . Error ( err ) ) continue } framedConn , _ := framing . NewConn ( conn , byte ( 4 ) , binary . BigEndian ) framedConn . MaxFrameSize = 1048576 // 1MB max frame size for read and write go listener . HandleConnection ( * framedConn ) } } ) return nil } ) }
// Listen bind port. Receive messages and send to out channel
Listen bind port . Receive messages and send to out channel