diff options
| author | Ian Lance Taylor <iant@golang.org> | 2024-12-11 14:02:28 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-12-11 17:52:03 -0800 |
| commit | 077d51909d3d7bc2d52afd47c9be1de8ee4f0756 (patch) | |
| tree | 5b2350652a896c1b6b6874045979dca734a2a5ce /src/net | |
| parent | fafd4477f3d19f2c11a628e6e407ecf9924309c1 (diff) | |
| download | go-077d51909d3d7bc2d52afd47c9be1de8ee4f0756.tar.xz | |
internal/poll: in SendFile treat ENOTSUP like EOPNOTSUPP
Fixes #70763
Change-Id: Ifb79b5b0529f7977df0fe1b59d224b8b31df2c9b
Reviewed-on: https://go-review.googlesource.com/c/go/+/635396
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/net')
| -rw-r--r-- | src/net/sendfile_unix_test.go | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/net/sendfile_unix_test.go b/src/net/sendfile_unix_test.go new file mode 100644 index 0000000000..79fb23b310 --- /dev/null +++ b/src/net/sendfile_unix_test.go @@ -0,0 +1,86 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build unix + +package net + +import ( + "internal/testpty" + "io" + "os" + "sync" + "syscall" + "testing" +) + +// Issue 70763: test that we don't fail on sendfile from a tty. +func TestCopyFromTTY(t *testing.T) { + pty, ttyName, err := testpty.Open() + if err != nil { + t.Skipf("skipping test because pty open failed: %v", err) + } + defer pty.Close() + + // Use syscall.Open so that the tty is blocking. + ttyFD, err := syscall.Open(ttyName, syscall.O_RDWR, 0) + if err != nil { + t.Skipf("skipping test because tty open failed: %v", err) + } + defer syscall.Close(ttyFD) + + tty := os.NewFile(uintptr(ttyFD), "tty") + defer tty.Close() + + ln := newLocalListener(t, "tcp") + defer ln.Close() + + ch := make(chan bool) + + const data = "data\n" + + var wg sync.WaitGroup + defer wg.Wait() + + wg.Add(1) + go func() { + defer wg.Done() + conn, err := ln.Accept() + if err != nil { + t.Error(err) + return + } + defer conn.Close() + + buf := make([]byte, len(data)) + if _, err := io.ReadFull(conn, buf); err != nil { + t.Error(err) + } + + ch <- true + }() + + conn, err := Dial("tcp", ln.Addr().String()) + if err != nil { + t.Fatal(err) + } + defer conn.Close() + + wg.Add(1) + go func() { + defer wg.Done() + if _, err := pty.Write([]byte(data)); err != nil { + t.Error(err) + } + <-ch + if err := pty.Close(); err != nil { + t.Error(err) + } + }() + + lr := io.LimitReader(tty, int64(len(data))) + if _, err := io.Copy(conn, lr); err != nil { + t.Error(err) + } +} |
