mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-19 16:35:10 +03:00
Linux set interface underlying fd to non-blocking
This commit is contained in:
parent
8c63d7a3c7
commit
4d58427608
2 changed files with 47 additions and 2 deletions
34
ipv4_test.go
34
ipv4_test.go
|
@ -1,6 +1,7 @@
|
|||
package water
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -74,3 +75,36 @@ readFrame:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloseUnblockPendingRead(t *testing.T) {
|
||||
var (
|
||||
self = net.IPv4(192, 168, 150, 1)
|
||||
mask = net.IPv4Mask(255, 255, 255, 0)
|
||||
)
|
||||
|
||||
ifce, err := New(Config{DeviceType: TUN})
|
||||
if err != nil {
|
||||
t.Fatalf("creating TUN error: %v\n", err)
|
||||
}
|
||||
|
||||
setupIfce(t, net.IPNet{IP: self, Mask: mask}, ifce.Name())
|
||||
c := make(chan struct{})
|
||||
go func() {
|
||||
ifce.Read(make([]byte, 1<<16))
|
||||
close(c)
|
||||
}()
|
||||
|
||||
// make sure ifce.Close() happens after ifce.Read()
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
ifce.Close()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
select {
|
||||
case <-c:
|
||||
t.Log("Pending Read unblocked")
|
||||
case <-ctx.Done():
|
||||
t.Fatal("Timeouted, pending read blocked")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue