Chore: improve code architecture
This commit is contained in:
@ -6,31 +6,25 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/Dreamacro/clash/adapters/inbound"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"github.com/Dreamacro/clash/log"
|
||||
"github.com/Dreamacro/clash/tunnel"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
tun = tunnel.Instance()
|
||||
)
|
||||
|
||||
func NewHttpProxy(addr string) (*C.ProxySignal, error) {
|
||||
func NewHttpProxy(addr string) (chan<- struct{}, <-chan struct{}, error) {
|
||||
l, err := net.Listen("tcp", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
closed := make(chan struct{})
|
||||
signal := &C.ProxySignal{
|
||||
Done: done,
|
||||
Closed: closed,
|
||||
}
|
||||
|
||||
go func() {
|
||||
log.Infof("HTTP proxy listening at: %s", addr)
|
||||
log.Infoln("HTTP proxy listening at: %s", addr)
|
||||
for {
|
||||
c, err := l.Accept()
|
||||
if err != nil {
|
||||
@ -45,12 +39,11 @@ func NewHttpProxy(addr string) (*C.ProxySignal, error) {
|
||||
|
||||
go func() {
|
||||
<-done
|
||||
close(done)
|
||||
l.Close()
|
||||
closed <- struct{}{}
|
||||
}()
|
||||
|
||||
return signal, nil
|
||||
return done, closed, nil
|
||||
}
|
||||
|
||||
func handleConn(conn net.Conn) {
|
||||
|
Reference in New Issue
Block a user