Skip to content

Commit

Permalink
Fix TestIfSocketCloses
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jul 31, 2022
1 parent 553085a commit 4def38d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions nl/nl_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"reflect"
"testing"
"time"
_ "unsafe"

"golang.org/x/sys/unix"
)
Expand Down Expand Up @@ -63,22 +64,22 @@ func TestIfInfomsgDeserializeSerialize(t *testing.T) {
testDeserializeSerialize(t, orig, safemsg, msg)
}

//go:linkname errFileClosing internal/poll.ErrFileClosing
var errFileClosing error

func TestIfSocketCloses(t *testing.T) {
nlSock, err := Subscribe(unix.NETLINK_ROUTE, unix.RTNLGRP_NEIGH)
if err != nil {
t.Fatalf("Error on creating the socket: %v", err)
}
nlSock.SetReceiveTimeout(&unix.Timeval{Sec: 2, Usec: 0})
endCh := make(chan error)
go func(sk *NetlinkSocket, endCh chan error) {
endCh <- nil
for {
_, _, err := sk.Receive()
// Receive returned because of a timeout and the FD == -1 means that the socket got closed
if err == unix.EAGAIN && nlSock.GetFd() == -1 {
endCh <- err
return
}
_, _, err := sk.Receive()
if err == errFileClosing {
endCh <- err
} else {
endCh <- nil
}
}(nlSock, endCh)

Expand Down

0 comments on commit 4def38d

Please sign in to comment.