Skip to content

Commit ad3f664

Browse files
committed
simplification
1 parent 3671a44 commit ad3f664

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

conn.go

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewConnPool(cpus int, sel Selector) *ConnPool {
4747
_ = conns.Add()
4848
}
4949

50-
go conns.rotations()
50+
//go conns.rotations()
5151
return conns
5252
}
5353

@@ -59,51 +59,53 @@ func (r *ConnPool) Close() {
5959
close(r.done)
6060
for _, c := range r.conns {
6161
close(c.done)
62+
_ = c.conn.Close()
6263
}
6364
r.conns = nil
6465
}
6566
}
6667

67-
func (r *ConnPool) rotations() {
68-
t := time.NewTicker(10 * time.Second)
69-
defer t.Stop()
70-
71-
for {
72-
select {
73-
case <-r.done:
74-
return
75-
case <-t.C:
76-
r.rotate()
68+
/*
69+
func (r *ConnPool) rotations() {
70+
t := time.NewTicker(10 * time.Second)
71+
defer t.Stop()
72+
73+
for {
74+
select {
75+
case <-r.done:
76+
return
77+
case <-t.C:
78+
r.rotate()
79+
}
7780
}
7881
}
79-
}
8082
81-
func (r *ConnPool) rotate() {
82-
r.Lock()
83-
defer r.Unlock()
83+
func (r *ConnPool) rotate() {
84+
r.Lock()
85+
defer r.Unlock()
8486
85-
old := make([]*connection, len(r.conns))
86-
copy(old, r.conns)
87+
old := make([]*connection, len(r.conns))
88+
copy(old, r.conns)
8789
88-
r.conns = []*connection{}
89-
for i := 0; i < r.cpus; i++ {
90-
_ = r.Add()
91-
}
90+
r.conns = []*connection{}
91+
for i := 0; i < r.cpus; i++ {
92+
_ = r.Add()
93+
}
9294
93-
go closeOldConnections(old, 3*time.Second)
94-
}
95+
go closeOldConnections(old, 3*time.Second)
96+
}
9597
96-
func closeOldConnections(old []*connection, delay time.Duration) {
97-
t := time.NewTimer(delay)
98-
defer t.Stop()
98+
func closeOldConnections(old []*connection, delay time.Duration) {
99+
t := time.NewTimer(delay)
100+
defer t.Stop()
99101
100-
<-t.C
101-
for _, c := range old {
102-
close(c.done)
103-
_ = c.conn.Close()
102+
<-t.C
103+
for _, c := range old {
104+
close(c.done)
105+
_ = c.conn.Close()
106+
}
104107
}
105-
}
106-
108+
*/
107109
func (r *ConnPool) Next() net.PacketConn {
108110
r.Lock()
109111
defer r.Unlock()

0 commit comments

Comments
 (0)