libgo: update to go1.9
[official-gcc.git] / libgo / go / net / rawconn.go
blobd67be644a34d165f43959505af8d1c0f054f6b3d
1 // Copyright 2017 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 package net
7 import (
8 "runtime"
9 "syscall"
12 // BUG(mikio): On Windows, the Read and Write methods of
13 // syscall.RawConn are not implemented.
15 // BUG(mikio): On NaCl and Plan 9, the Control, Read and Write methods
16 // of syscall.RawConn are not implemented.
18 type rawConn struct {
19 fd *netFD
22 func (c *rawConn) ok() bool { return c != nil && c.fd != nil }
24 func (c *rawConn) Control(f func(uintptr)) error {
25 if !c.ok() {
26 return syscall.EINVAL
28 err := c.fd.pfd.RawControl(f)
29 runtime.KeepAlive(c.fd)
30 if err != nil {
31 err = &OpError{Op: "raw-control", Net: c.fd.net, Source: nil, Addr: c.fd.laddr, Err: err}
33 return err
36 func (c *rawConn) Read(f func(uintptr) bool) error {
37 if !c.ok() {
38 return syscall.EINVAL
40 err := c.fd.pfd.RawRead(f)
41 runtime.KeepAlive(c.fd)
42 if err != nil {
43 err = &OpError{Op: "raw-read", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
45 return err
48 func (c *rawConn) Write(f func(uintptr) bool) error {
49 if !c.ok() {
50 return syscall.EINVAL
52 err := c.fd.pfd.RawWrite(f)
53 runtime.KeepAlive(c.fd)
54 if err != nil {
55 err = &OpError{Op: "raw-write", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
57 return err
60 func newRawConn(fd *netFD) (*rawConn, error) {
61 return &rawConn{fd: fd}, nil