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.
6 //go:build !plan9 && !js
16 func TestRawConnReadWrite(t
*testing
.T
) {
19 r
, w
, err
:= os
.Pipe()
26 rconn
, err
:= r
.SyscallConn()
30 wconn
, err
:= w
.SyscallConn()
36 err
= wconn
.Write(func(s
uintptr) bool {
37 _
, operr
= syscall
.Write(syscallDescriptor(s
), []byte{'b'})
38 return operr
!= syscall
.EAGAIN
48 buf
:= make([]byte, 1)
49 err
= rconn
.Read(func(s
uintptr) bool {
50 n
, operr
= syscall
.Read(syscallDescriptor(s
), buf
)
51 return operr
!= syscall
.EAGAIN
60 t
.Errorf("read %d bytes, expected 1", n
)
63 t
.Errorf("read %q, expected %q", buf
, "b")