Add __builtion_unreachable to vector::size(), vector::capacity()
[official-gcc.git] / libgo / go / os / rawconn_test.go
blobfd2038a2332a1688fc5061fc29132107edc5a27e
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
8 package os_test
10 import (
11 "os"
12 "syscall"
13 "testing"
16 func TestRawConnReadWrite(t *testing.T) {
17 t.Parallel()
19 r, w, err := os.Pipe()
20 if err != nil {
21 t.Fatal(err)
23 defer r.Close()
24 defer w.Close()
26 rconn, err := r.SyscallConn()
27 if err != nil {
28 t.Fatal(err)
30 wconn, err := w.SyscallConn()
31 if err != nil {
32 t.Fatal(err)
35 var operr error
36 err = wconn.Write(func(s uintptr) bool {
37 _, operr = syscall.Write(syscallDescriptor(s), []byte{'b'})
38 return operr != syscall.EAGAIN
40 if err != nil {
41 t.Fatal(err)
43 if operr != nil {
44 t.Fatal(err)
47 var n int
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
53 if err != nil {
54 t.Fatal(err)
56 if operr != nil {
57 t.Fatal(operr)
59 if n != 1 {
60 t.Errorf("read %d bytes, expected 1", n)
62 if buf[0] != 'b' {
63 t.Errorf("read %q, expected %q", buf, "b")