浏览代码

update golib

fatedier 7 年之前
父节点
当前提交
aeb9f2b64d
共有 2 个文件被更改,包括 15 次插入5 次删除
  1. 2 2
      Gopkg.lock
  2. 13 3
      vendor/github.com/fatedier/golib/net/mux/mux.go

+ 2 - 2
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"

+ 13 - 3
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