libgo: update to Go 1.11
[official-gcc.git] / libgo / go / net / rawconn.go
blobc40ea4a2e1248996acd8111dae59950c3a5329a5
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(tmm1): On Windows, the Write method of syscall.RawConn
13 // does not integrate with the runtime's network poller. It cannot
14 // wait for the connection to become writeable, and does not respect
15 // deadlines. If the user-provided callback returns false, the Write
16 // method will fail immediately.
18 // BUG(mikio): On JS, NaCl and Plan 9, the Control, Read and Write
19 // methods of syscall.RawConn are not implemented.
21 type rawConn struct {
22 fd *netFD
25 func (c *rawConn) ok() bool { return c != nil && c.fd != nil }
27 func (c *rawConn) Control(f func(uintptr)) error {
28 if !c.ok() {
29 return syscall.EINVAL
31 err := c.fd.pfd.RawControl(f)
32 runtime.KeepAlive(c.fd)
33 if err != nil {
34 err = &OpError{Op: "raw-control", Net: c.fd.net, Source: nil, Addr: c.fd.laddr, Err: err}
36 return err
39 func (c *rawConn) Read(f func(uintptr) bool) error {
40 if !c.ok() {
41 return syscall.EINVAL
43 err := c.fd.pfd.RawRead(f)
44 runtime.KeepAlive(c.fd)
45 if err != nil {
46 err = &OpError{Op: "raw-read", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
48 return err
51 func (c *rawConn) Write(f func(uintptr) bool) error {
52 if !c.ok() {
53 return syscall.EINVAL
55 err := c.fd.pfd.RawWrite(f)
56 runtime.KeepAlive(c.fd)
57 if err != nil {
58 err = &OpError{Op: "raw-write", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
60 return err
63 func newRawConn(fd *netFD) (*rawConn, error) {
64 return &rawConn{fd: fd}, nil
67 type rawListener struct {
68 rawConn
71 func (l *rawListener) Read(func(uintptr) bool) error {
72 return syscall.EINVAL
75 func (l *rawListener) Write(func(uintptr) bool) error {
76 return syscall.EINVAL
79 func newRawListener(fd *netFD) (*rawListener, error) {
80 return &rawListener{rawConn{fd: fd}}, nil