diff --git a/Gopkg.lock b/Gopkg.lock index 69e9e82..fdef77e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -30,7 +30,7 @@ "net/mux", "pool" ] - revision = "674e937d2ef03e9ef7798c363071cad128f3c13b" + revision = "416571c55dbc32e13ce82c301a2a4b5a48ad7309" [[projects]] branch = "frp" @@ -169,7 +169,7 @@ "ipv4", "proxy" ] - revision = "57065200b4b034a1c8ad54ff77069408c2218ae6" + revision = "dfa909b99c79129e1100513e5cd36307665e5723" [solve-meta] analyzer-name = "dep" diff --git a/vendor/github.com/fatedier/golib/net/mux/mux.go b/vendor/github.com/fatedier/golib/net/mux/mux.go index ebf5717..07eec58 100644 --- a/vendor/github.com/fatedier/golib/net/mux/mux.go +++ b/vendor/github.com/fatedier/golib/net/mux/mux.go @@ -34,10 +34,13 @@ const ( type Mux struct { ln net.Listener - defaultLn *listener + defaultLn *listener + + // sorted by priority lns []*listener maxNeedBytesNum uint32 - mu sync.RWMutex + + mu sync.RWMutex } func NewMux() (mux *Mux) { @@ -47,10 +50,12 @@ func NewMux() (mux *Mux) { return } +// priority func (mux *Mux) Listen(priority int, needBytesNum uint32, fn MatchFunc) net.Listener { ln := &listener{ c: make(chan net.Conn), mux: mux, + priority: priority, needBytesNum: needBytesNum, matchFn: fn, } @@ -63,7 +68,10 @@ func (mux *Mux) Listen(priority int, needBytesNum uint32, fn MatchFunc) net.List newlns := append(mux.copyLns(), ln) sort.Slice(newlns, func(i, j int) bool { - return newlns[i].needBytesNum < newlns[j].needBytesNum + if newlns[i].priority == newlns[j].priority { + return newlns[i].needBytesNum < newlns[j].needBytesNum + } + return newlns[i].priority < newlns[j].priority }) mux.lns = newlns return ln @@ -99,6 +107,7 @@ func (mux *Mux) release(ln *listener) bool { if l == ln { lns = append(lns[:i], lns[i+1:]...) result = true + break } } mux.lns = lns @@ -186,6 +195,7 @@ func (mux *Mux) handleConn(conn net.Conn) { type listener struct { mux *Mux + priority int needBytesNum uint32 matchFn MatchFunc