Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
net
Commits
9d071032
Commit
9d071032
authored
Jun 16, 2013
by
Mikio Hara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go.net/ipv4: make use of net.PacketConn embedding
R=dave CC=golang-dev
https://golang.org/cl/10319043
parent
c94a7ef8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
31 deletions
+29
-31
endpoint.go
ipv4/endpoint.go
+14
-14
helper_plan9.go
ipv4/helper_plan9.go
+1
-3
helper_unix.go
ipv4/helper_unix.go
+3
-3
helper_windows.go
ipv4/helper_windows.go
+3
-3
payload.go
ipv4/payload.go
+8
-8
No files found.
ipv4/endpoint.go
View file @
9d071032
...
...
@@ -18,15 +18,15 @@ type Conn struct {
}
type
genericOpt
struct
{
c
net
.
Conn
net
.
Conn
}
func
(
c
*
genericOpt
)
ok
()
bool
{
return
c
!=
nil
&&
c
.
c
!=
nil
}
func
(
c
*
genericOpt
)
ok
()
bool
{
return
c
!=
nil
&&
c
.
Conn
!=
nil
}
// NewConn returns a new Conn.
func
NewConn
(
c
net
.
Conn
)
*
Conn
{
return
&
Conn
{
genericOpt
:
genericOpt
{
c
},
genericOpt
:
genericOpt
{
Conn
:
c
},
}
}
...
...
@@ -42,10 +42,10 @@ type PacketConn struct {
}
type
dgramOpt
struct
{
c
net
.
PacketConn
net
.
PacketConn
}
func
(
c
*
dgramOpt
)
ok
()
bool
{
return
c
!=
nil
&&
c
.
c
!=
nil
}
func
(
c
*
dgramOpt
)
ok
()
bool
{
return
c
!=
nil
&&
c
.
PacketConn
!=
nil
}
// SetControlMessage sets the per packet IP-level socket options.
func
(
c
*
PacketConn
)
SetControlMessage
(
cf
ControlFlags
,
on
bool
)
error
{
...
...
@@ -65,7 +65,7 @@ func (c *PacketConn) SetDeadline(t time.Time) error {
if
!
c
.
payloadHandler
.
ok
()
{
return
syscall
.
EINVAL
}
return
c
.
payloadHandler
.
c
.
SetDeadline
(
t
)
return
c
.
payloadHandler
.
PacketConn
.
SetDeadline
(
t
)
}
// SetReadDeadline sets the read deadline associated with the
...
...
@@ -74,7 +74,7 @@ func (c *PacketConn) SetReadDeadline(t time.Time) error {
if
!
c
.
payloadHandler
.
ok
()
{
return
syscall
.
EINVAL
}
return
c
.
payloadHandler
.
c
.
SetReadDeadline
(
t
)
return
c
.
payloadHandler
.
PacketConn
.
SetReadDeadline
(
t
)
}
// SetWriteDeadline sets the write deadline associated with the
...
...
@@ -83,7 +83,7 @@ func (c *PacketConn) SetWriteDeadline(t time.Time) error {
if
!
c
.
payloadHandler
.
ok
()
{
return
syscall
.
EINVAL
}
return
c
.
payloadHandler
.
c
.
SetWriteDeadline
(
t
)
return
c
.
payloadHandler
.
PacketConn
.
SetWriteDeadline
(
t
)
}
// Close closes the endpoint.
...
...
@@ -91,16 +91,16 @@ func (c *PacketConn) Close() error {
if
!
c
.
payloadHandler
.
ok
()
{
return
syscall
.
EINVAL
}
return
c
.
payloadHandler
.
c
.
Close
()
return
c
.
payloadHandler
.
PacketConn
.
Close
()
}
// NewPacketConn returns a new PacketConn using c as its underlying
// transport.
func
NewPacketConn
(
c
net
.
PacketConn
)
*
PacketConn
{
return
&
PacketConn
{
genericOpt
:
genericOpt
{
c
.
(
net
.
Conn
)},
dgramOpt
:
dgramOpt
{
c
},
payloadHandler
:
payloadHandler
{
c
:
c
},
genericOpt
:
genericOpt
{
Conn
:
c
.
(
net
.
Conn
)},
dgramOpt
:
dgramOpt
{
PacketConn
:
c
},
payloadHandler
:
payloadHandler
{
PacketConn
:
c
},
}
}
...
...
@@ -166,8 +166,8 @@ func (c *RawConn) Close() error {
// transport.
func
NewRawConn
(
c
net
.
PacketConn
)
(
*
RawConn
,
error
)
{
r
:=
&
RawConn
{
genericOpt
:
genericOpt
{
c
.
(
net
.
Conn
)},
dgramOpt
:
dgramOpt
{
c
},
genericOpt
:
genericOpt
{
Conn
:
c
.
(
net
.
Conn
)},
dgramOpt
:
dgramOpt
{
PacketConn
:
c
},
packetHandler
:
packetHandler
{
c
:
c
.
(
*
net
.
IPConn
)},
}
fd
,
err
:=
r
.
packetHandler
.
sysfd
()
...
...
ipv4/helper_plan9.go
View file @
9d071032
...
...
@@ -4,9 +4,7 @@
package
ipv4
import
(
"syscall"
)
import
"syscall"
func
(
c
*
genericOpt
)
sysfd
()
(
int
,
error
)
{
// TODO(mikio): Implement this
...
...
ipv4/helper_unix.go
View file @
9d071032
...
...
@@ -12,7 +12,7 @@ import (
)
func
(
c
*
genericOpt
)
sysfd
()
(
int
,
error
)
{
switch
p
:=
c
.
c
.
(
type
)
{
switch
p
:=
c
.
Conn
.
(
type
)
{
case
*
net
.
TCPConn
,
*
net
.
UDPConn
,
*
net
.
IPConn
:
return
sysfd
(
p
)
}
...
...
@@ -20,7 +20,7 @@ func (c *genericOpt) sysfd() (int, error) {
}
func
(
c
*
dgramOpt
)
sysfd
()
(
int
,
error
)
{
switch
p
:=
c
.
c
.
(
type
)
{
switch
p
:=
c
.
PacketConn
.
(
type
)
{
case
*
net
.
UDPConn
,
*
net
.
IPConn
:
return
sysfd
(
p
.
(
net
.
Conn
))
}
...
...
@@ -28,7 +28,7 @@ func (c *dgramOpt) sysfd() (int, error) {
}
func
(
c
*
payloadHandler
)
sysfd
()
(
int
,
error
)
{
return
sysfd
(
c
.
c
.
(
net
.
Conn
))
return
sysfd
(
c
.
PacketConn
.
(
net
.
Conn
))
}
func
(
c
*
packetHandler
)
sysfd
()
(
int
,
error
)
{
...
...
ipv4/helper_windows.go
View file @
9d071032
...
...
@@ -11,7 +11,7 @@ import (
)
func
(
c
*
genericOpt
)
sysfd
()
(
syscall
.
Handle
,
error
)
{
switch
p
:=
c
.
c
.
(
type
)
{
switch
p
:=
c
.
Conn
.
(
type
)
{
case
*
net
.
TCPConn
,
*
net
.
UDPConn
,
*
net
.
IPConn
:
return
sysfd
(
p
)
}
...
...
@@ -19,7 +19,7 @@ func (c *genericOpt) sysfd() (syscall.Handle, error) {
}
func
(
c
*
dgramOpt
)
sysfd
()
(
syscall
.
Handle
,
error
)
{
switch
p
:=
c
.
c
.
(
type
)
{
switch
p
:=
c
.
PacketConn
.
(
type
)
{
case
*
net
.
UDPConn
,
*
net
.
IPConn
:
return
sysfd
(
p
.
(
net
.
Conn
))
}
...
...
@@ -27,7 +27,7 @@ func (c *dgramOpt) sysfd() (syscall.Handle, error) {
}
func
(
c
*
payloadHandler
)
sysfd
()
(
syscall
.
Handle
,
error
)
{
return
sysfd
(
c
.
c
.
(
net
.
Conn
))
return
sysfd
(
c
.
PacketConn
.
(
net
.
Conn
))
}
func
(
c
*
packetHandler
)
sysfd
()
(
syscall
.
Handle
,
error
)
{
...
...
ipv4/payload.go
View file @
9d071032
...
...
@@ -11,11 +11,11 @@ import (
// A payloadHandler represents the IPv4 datagram payload handler.
type
payloadHandler
struct
{
c
net
.
PacketConn
net
.
PacketConn
rawOpt
}
func
(
c
*
payloadHandler
)
ok
()
bool
{
return
c
!=
nil
&&
c
.
c
!=
nil
}
func
(
c
*
payloadHandler
)
ok
()
bool
{
return
c
!=
nil
&&
c
.
PacketConn
!=
nil
}
// ReadFrom reads a payload of the received IPv4 datagram, from the
// endpoint c, copying the payload into b. It returns the number of
...
...
@@ -27,14 +27,14 @@ func (c *payloadHandler) ReadFrom(b []byte) (n int, cm *ControlMessage, src net.
}
oob
:=
newControlMessage
(
&
c
.
rawOpt
)
var
oobn
int
switch
rd
:=
c
.
c
.
(
type
)
{
switch
c
:=
c
.
PacketConn
.
(
type
)
{
case
*
net
.
UDPConn
:
if
n
,
oobn
,
_
,
src
,
err
=
rd
.
ReadMsgUDP
(
b
,
oob
);
err
!=
nil
{
if
n
,
oobn
,
_
,
src
,
err
=
c
.
ReadMsgUDP
(
b
,
oob
);
err
!=
nil
{
return
0
,
nil
,
nil
,
err
}
case
*
net
.
IPConn
:
nb
:=
make
([]
byte
,
maxHeaderLen
+
len
(
b
))
if
n
,
oobn
,
_
,
src
,
err
=
rd
.
ReadMsgIP
(
nb
,
oob
);
err
!=
nil
{
if
n
,
oobn
,
_
,
src
,
err
=
c
.
ReadMsgIP
(
nb
,
oob
);
err
!=
nil
{
return
0
,
nil
,
nil
,
err
}
hdrlen
:=
int
(
nb
[
0
]
&
0x0f
)
<<
2
...
...
@@ -66,11 +66,11 @@ func (c *payloadHandler) WriteTo(b []byte, cm *ControlMessage, dst net.Addr) (n
if
dst
==
nil
{
return
0
,
errMissingAddress
}
switch
wr
:=
c
.
c
.
(
type
)
{
switch
c
:=
c
.
PacketConn
.
(
type
)
{
case
*
net
.
UDPConn
:
n
,
_
,
err
=
wr
.
WriteMsgUDP
(
b
,
oob
,
dst
.
(
*
net
.
UDPAddr
))
n
,
_
,
err
=
c
.
WriteMsgUDP
(
b
,
oob
,
dst
.
(
*
net
.
UDPAddr
))
case
*
net
.
IPConn
:
n
,
_
,
err
=
wr
.
WriteMsgIP
(
b
,
oob
,
dst
.
(
*
net
.
IPAddr
))
n
,
_
,
err
=
c
.
WriteMsgIP
(
b
,
oob
,
dst
.
(
*
net
.
IPAddr
))
default
:
return
0
,
errInvalidConnType
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment