@@ -14,7 +14,7 @@ import (
14
14
func newFileFD (f * os.File ) (* netFD , error ) {
15
15
fd , err := dupCloseOnExec (int (f .Fd ()))
16
16
if err != nil {
17
- return nil , os . NewSyscallError ( "dup" , err )
17
+ return nil , err
18
18
}
19
19
20
20
if err = syscall .SetNonblock (fd , true ); err != nil {
@@ -25,16 +25,13 @@ func newFileFD(f *os.File) (*netFD, error) {
25
25
sotype , err := syscall .GetsockoptInt (fd , syscall .SOL_SOCKET , syscall .SO_TYPE )
26
26
if err != nil {
27
27
closeFunc (fd )
28
- return nil , os . NewSyscallError ( "getsockopt" , err )
28
+ return nil , err
29
29
}
30
30
31
31
family := syscall .AF_UNSPEC
32
32
toAddr := sockaddrToTCP
33
33
lsa , _ := syscall .Getsockname (fd )
34
34
switch lsa .(type ) {
35
- default :
36
- closeFunc (fd )
37
- return nil , syscall .EINVAL
38
35
case * syscall.SockaddrInet4 :
39
36
family = syscall .AF_INET
40
37
if sotype == syscall .SOCK_DGRAM {
@@ -57,6 +54,9 @@ func newFileFD(f *os.File) (*netFD, error) {
57
54
} else if sotype == syscall .SOCK_SEQPACKET {
58
55
toAddr = sockaddrToUnixpacket
59
56
}
57
+ default :
58
+ closeFunc (fd )
59
+ return nil , syscall .EPROTONOSUPPORT
60
60
}
61
61
laddr := toAddr (lsa )
62
62
rsa , _ := syscall .Getpeername (fd )
@@ -75,11 +75,7 @@ func newFileFD(f *os.File) (*netFD, error) {
75
75
return netfd , nil
76
76
}
77
77
78
- // FileConn returns a copy of the network connection corresponding to
79
- // the open file f. It is the caller's responsibility to close f when
80
- // finished. Closing c does not affect f, and closing f does not
81
- // affect c.
82
- func FileConn (f * os.File ) (c Conn , err error ) {
78
+ func fileConn (f * os.File ) (Conn , error ) {
83
79
fd , err := newFileFD (f )
84
80
if err != nil {
85
81
return nil , err
@@ -98,11 +94,7 @@ func FileConn(f *os.File) (c Conn, err error) {
98
94
return nil , syscall .EINVAL
99
95
}
100
96
101
- // FileListener returns a copy of the network listener corresponding
102
- // to the open file f. It is the caller's responsibility to close l
103
- // when finished. Closing l does not affect f, and closing f does not
104
- // affect l.
105
- func FileListener (f * os.File ) (l Listener , err error ) {
97
+ func fileListener (f * os.File ) (Listener , error ) {
106
98
fd , err := newFileFD (f )
107
99
if err != nil {
108
100
return nil , err
@@ -117,11 +109,7 @@ func FileListener(f *os.File) (l Listener, err error) {
117
109
return nil , syscall .EINVAL
118
110
}
119
111
120
- // FilePacketConn returns a copy of the packet network connection
121
- // corresponding to the open file f. It is the caller's
122
- // responsibility to close f when finished. Closing c does not affect
123
- // f, and closing f does not affect c.
124
- func FilePacketConn (f * os.File ) (c PacketConn , err error ) {
112
+ func filePacketConn (f * os.File ) (PacketConn , error ) {
125
113
fd , err := newFileFD (f )
126
114
if err != nil {
127
115
return nil , err
0 commit comments