blob: 2399c9f31dd12de96a2a682d1e9a709e20e4134a [file] [log] [blame]
Dan Willemsend2797482017-07-26 13:13:13 -07001// 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.
4
5package net
6
7import (
8 "runtime"
9 "syscall"
10)
11
12// BUG(mikio): On Windows, the Read and Write methods of
13// syscall.RawConn are not implemented.
14
15// BUG(mikio): On NaCl and Plan 9, the Control, Read and Write methods
16// of syscall.RawConn are not implemented.
17
18type rawConn struct {
19 fd *netFD
20}
21
22func (c *rawConn) ok() bool { return c != nil && c.fd != nil }
23
24func (c *rawConn) Control(f func(uintptr)) error {
25 if !c.ok() {
26 return syscall.EINVAL
27 }
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}
32 }
33 return err
34}
35
36func (c *rawConn) Read(f func(uintptr) bool) error {
37 if !c.ok() {
38 return syscall.EINVAL
39 }
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}
44 }
45 return err
46}
47
48func (c *rawConn) Write(f func(uintptr) bool) error {
49 if !c.ok() {
50 return syscall.EINVAL
51 }
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}
56 }
57 return err
58}
59
60func newRawConn(fd *netFD) (*rawConn, error) {
61 return &rawConn{fd: fd}, nil
62}
Dan Willemsena3223282018-02-27 19:41:43 -080063
64type rawListener struct {
65 rawConn
66}
67
68func (l *rawListener) Read(func(uintptr) bool) error {
69 return syscall.EINVAL
70}
71
72func (l *rawListener) Write(func(uintptr) bool) error {
73 return syscall.EINVAL
74}
75
76func newRawListener(fd *netFD) (*rawListener, error) {
77 return &rawListener{rawConn{fd: fd}}, nil
78}