1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Test use of raw connections.
7 //go:build !plan9 && !js && !wasip1
17 func TestRawConnReadWrite(t *testing.T) {
20 r, w, err := os.Pipe()
27 rconn, err := r.SyscallConn()
31 wconn, err := w.SyscallConn()
37 err = wconn.Write(func(s uintptr) bool {
38 _, operr = syscall.Write(syscallDescriptor(s), []byte{'b'})
39 return operr != syscall.EAGAIN
49 buf := make([]byte, 1)
50 err = rconn.Read(func(s uintptr) bool {
51 n, operr = syscall.Read(syscallDescriptor(s), buf)
52 return operr != syscall.EAGAIN
61 t.Errorf("read %d bytes, expected 1", n)
64 t.Errorf("read %q, expected %q", buf, "b")