2018-23-01 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libgo / go / net / rawconn.go
blob2399c9f31dd12de96a2a682d1e9a709e20e4134a
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
64 type rawListener struct {
65 rawConn
68 func (l *rawListener) Read(func(uintptr) bool) error {
69 return syscall.EINVAL
72 func (l *rawListener) Write(func(uintptr) bool) error {
73 return syscall.EINVAL
76 func newRawListener(fd *netFD) (*rawListener, error) {
77 return &rawListener{rawConn{fd: fd}}, nil