Beispiel #1
0
func (s *Server) handleConns() {
	ch := make(chan net.Conn, 4096)
	defer close(ch)

	go func() {
		for c := range ch {
			x, ok := s.sessionPool.Get().(*router.Session)
			if !ok || x == nil {
				x = router.NewSessionSize(c, s.conf.passwd, s.conf.maxBufSize, s.conf.maxTimeout)
			} else {
				x.Reset(c, s.conf.passwd, s.conf.maxTimeout)
			}
			go func() {
				x.Serve(s.router, s.conf.maxPipeline)
				s.sessionPool.Put(x)
			}()
		}
	}()

	for {
		c, err := s.listener.Accept()
		if err != nil {
			return
		} else {
			ch <- c
		}
	}
}
Beispiel #2
0
func (s *Server) handleConns() {
	ch := make(chan net.Conn, 4096)
	defer close(ch)

	go func() {
		for c := range ch {
			x := router.NewSessionSize(c, s.conf.passwd, s.conf.maxBufSize, s.conf.maxTimeout)
			go x.Serve(s.router, s.conf.maxPipeline)
		}
	}()

	for {
		c, err := s.listener.Accept()
		if err != nil {
			if ne, ok := err.(net.Error); ok && ne.Temporary() {
				log.WarnErrorf(err, "[%p] proxy accept new connection failed, get temporary error", s)
				time.Sleep(time.Millisecond * 10)
				continue
			}
			log.WarnErrorf(err, "[%p] proxy accept new connection failed, get non-temporary error, must shutdown", s)
			return
		} else {
			ch <- c
		}
	}
}
Beispiel #3
0
func (s *Server) handleConns() {
	ch := make(chan net.Conn, 4096)
	defer close(ch)

	go func() {
		for c := range ch {
			x := router.NewSessionSize(c, s.conf.passwd, s.conf.maxBufSize, s.conf.maxTimeout)
			go x.Serve(s.router, s.conf.maxPipeline)
		}
	}()

	for {
		c, err := s.listener.Accept()
		if err != nil {
			return
		} else {
			ch <- c
		}
	}
}
Beispiel #4
0
func (s *Server) handleConns() {
	ch := make(chan net.Conn, 4096)
	defer close(ch)

	go func() {
		for c := range ch {
			x := router.NewSessionSize(c, s.conf.passwd, s.conf.maxBufSize, s.conf.maxTimeout)
			go x.Serve(s.router, s.conf.maxPipeline)
		}
	}()

	for {
		c, err := s.listener.Accept()
		if err != nil {
			return
		} else {
			/*
				if s.status == SERVER_STATUS_STARTING {
					s.listener.Close()
					for {
						if s.status == SERVER_STATUS_STARTED {
							if l, err := net.Listen("tcp", ":"+strings.Split(s.info.Addr, ":")[1]); err != nil {
								log.ErrorErrorf(err, "open listener failed")
								time.Sleep(5 * time.Second)
							} else {
								s.listener = l
								break
							}
						} else {
							time.Sleep(5 * time.Second)
						}
					}
				} else {
					ch <- c
				}
			*/
			ch <- c
		}
	}
}