Source file
src/net/rawconn.go
1
2
3
4
5 package net
6
7 import (
8 "internal/poll"
9 "runtime"
10 "syscall"
11 )
12
13
14
15
16
17
18
19
20
21
22 type rawConn struct {
23 fd *netFD
24 }
25
26 func (c *rawConn) ok() bool { return c != nil && c.fd != nil }
27
28 func (c *rawConn) Control(f func(uintptr)) error {
29 if !c.ok() {
30 return syscall.EINVAL
31 }
32 err := c.fd.pfd.RawControl(f)
33 runtime.KeepAlive(c.fd)
34 if err != nil {
35 err = &OpError{Op: "raw-control", Net: c.fd.net, Source: nil, Addr: c.fd.laddr, Err: err}
36 }
37 return err
38 }
39
40 func (c *rawConn) Read(f func(uintptr) bool) error {
41 if !c.ok() {
42 return syscall.EINVAL
43 }
44 err := c.fd.pfd.RawRead(f)
45 runtime.KeepAlive(c.fd)
46 if err != nil {
47 err = &OpError{Op: "raw-read", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
48 }
49 return err
50 }
51
52 func (c *rawConn) Write(f func(uintptr) bool) error {
53 if !c.ok() {
54 return syscall.EINVAL
55 }
56 err := c.fd.pfd.RawWrite(f)
57 runtime.KeepAlive(c.fd)
58 if err != nil {
59 err = &OpError{Op: "raw-write", Net: c.fd.net, Source: c.fd.laddr, Addr: c.fd.raddr, Err: err}
60 }
61 return err
62 }
63
64
65
66
67
68
69
70
71 func (c *rawConn) PollFD() *poll.FD {
72 if !c.ok() {
73 return nil
74 }
75 return &c.fd.pfd
76 }
77
78 func newRawConn(fd *netFD) *rawConn {
79 return &rawConn{fd: fd}
80 }
81
82
83
84
85
86
87
88
89 func (c *rawConn) Network() poll.String {
90 return poll.String(c.fd.net)
91 }
92
93 type rawListener struct {
94 rawConn
95 }
96
97 func (l *rawListener) Read(func(uintptr) bool) error {
98 return syscall.EINVAL
99 }
100
101 func (l *rawListener) Write(func(uintptr) bool) error {
102 return syscall.EINVAL
103 }
104
105 func newRawListener(fd *netFD) *rawListener {
106 return &rawListener{rawConn{fd: fd}}
107 }
108
View as plain text