add test code

This commit is contained in:
ffdfgdfg
2019-10-23 23:35:39 +08:00
parent 23b023c562
commit 442354db17
4 changed files with 300 additions and 161 deletions

View File

@@ -41,7 +41,7 @@ func NewMux(c net.Conn, connType string) *Mux {
connMap: NewConnMap(),
id: 0,
closeChan: make(chan struct{}, 3),
newConnCh: make(chan *conn),
newConnCh: make(chan *conn, 10),
bw: new(bandwidth),
IsClose: false,
connType: connType,
@@ -321,11 +321,11 @@ func (s *Mux) Close() error {
func (s *Mux) getId() (id int32) {
//Avoid going beyond the scope
if (math.MaxInt32 - s.id) < 10000 {
atomic.SwapInt32(&s.id, 0)
atomic.StoreInt32(&s.id, 0)
}
id = atomic.AddInt32(&s.id, 1)
if _, ok := s.connMap.Get(id); ok {
s.getId()
return s.getId()
}
return
}