<commit_before>package proxy

import (
	"net"
	"net/http"
	"sync/atomic"

	"github.com/fagongzi/gateway/pkg/util"
	"github.com/fagongzi/log"
	"github.com/soheilhy/cmux"
	"github.com/valyala/fasthttp"
)

// Start start proxy
func (p *Proxy) Start() {
	go p.listenToStop()

	p.startMetrics()
	p.startReadyTasks()

	if !p.cfg.Option.EnableWebSocket {
		p.startHTTP()
		p.startHTTPS()

		return
	}

	go p.startHTTPSCMUX()
	p.startHTTPCMUX()
}

// Stop stop the proxy
func (p *Proxy) Stop() {
	log.Infof("stop: start to stop gateway proxy")

	p.stopWG.Add(1)
	p.stopC <- struct{}{}
	p.stopWG.Wait()

	log.Infof("stop: gateway proxy stopped")
}

func (p *Proxy) listenToStop() {
	<-p.stopC
	p.doStop()
}

func (p *Proxy) doStop() {
	p.stopOnce.Do(func() {
		defer p.stopWG.Done()
		p.setStopped()<commit_msg>fix start<commit_after>package proxy

import (
	"net"
	"net/http"
	"sync/atomic"

	"github.com/fagongzi/gateway/pkg/util"
	"github.com/fagongzi/log"
	"github.com/soheilhy/cmux"
	"github.com/valyala/fasthttp"
)

// Start start proxy
func (p *Proxy) Start() {
	go p.listenToStop()

	p.startMetrics()
	p.startReadyTasks()

	if !p.cfg.Option.EnableWebSocket {
		go p.startHTTPS()
		p.startHTTP()

		return
	}

	go p.startHTTPSCMUX()
	p.startHTTPCMUX()
}

// Stop stop the proxy
func (p *Proxy) Stop() {
	log.Infof("stop: start to stop gateway proxy")

	p.stopWG.Add(1)
	p.stopC <- struct{}{}
	p.stopWG.Wait()

	log.Infof("stop: gateway proxy stopped")
}

func (p *Proxy) listenToStop() {
	<-p.stopC
	p.doStop()
}

func (p *Proxy) doStop() {
	p.stopOnce.Do(func() {
		defer p.stopWG.Done()
		p.setStopped()
{'fraction_non_alphanumeric': 0.17342482844666252, 'fraction_numerical': 0.0012476606363069245, 'mean_word_length': 3.7038123167155423, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3677540', 'n_tokens_mistral': 729, 'n_tokens_neox': 694, 'n_words': 131}