Skip to content

Commit 541e97f

Browse files
committed
chore: add comments
1 parent d0b7168 commit 541e97f

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

connstate/conn_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,17 @@ func (r *mockRawConn) Control(f func(fd uintptr)) error {
9595
func TestListenConnState_Err(t *testing.T) {
9696
testMutex.Lock()
9797
defer testMutex.Unlock()
98-
var expectDetach bool
99-
pollInitOnce.Do(func() {})
98+
// replace poll
99+
pollInitOnce.Do(createPoller)
100100
oldPoll := poll
101+
defer func() {
102+
poll = oldPoll
103+
}()
104+
// test detach
105+
var expectDetach bool
106+
defer func() {
107+
assert.True(t, expectDetach)
108+
}()
101109
cases := []struct {
102110
name string
103111
connControlFunc func(f func(fd uintptr)) error
@@ -151,12 +159,6 @@ func TestListenConnState_Err(t *testing.T) {
151159
assert.Equal(t, c.expectErr, err)
152160
})
153161
}
154-
assert.True(t, expectDetach)
155-
if oldPoll != nil {
156-
poll = oldPoll
157-
} else {
158-
createPoller()
159-
}
160162
}
161163

162164
func BenchmarkListenConnState(b *testing.B) {

connstate/poll_linux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ type epoller struct {
3232
func (p *epoller) wait() error {
3333
events := make([]syscall.EpollEvent, 1024)
3434
for {
35+
// epoll wait is a blocking syscall, so we need to call entersyscallblock to handoff P,
36+
// and let the P run other goroutines.
3537
n, err := isyscall.EpollWait(p.epfd, events, -1)
3638
if err != nil && err != syscall.EINTR {
3739
return err

0 commit comments

Comments
 (0)