LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // +build darwin freebsd linux netbsd openbsd | 5 // +build darwin freebsd linux netbsd openbsd |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "os" | 10 "os" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 if sotype == syscall.SOCK_DGRAM { | 54 if sotype == syscall.SOCK_DGRAM { |
55 toAddr = sockaddrToUnixgram | 55 toAddr = sockaddrToUnixgram |
56 } else if sotype == syscall.SOCK_SEQPACKET { | 56 } else if sotype == syscall.SOCK_SEQPACKET { |
57 toAddr = sockaddrToUnixpacket | 57 toAddr = sockaddrToUnixpacket |
58 } | 58 } |
59 } | 59 } |
60 laddr := toAddr(lsa) | 60 laddr := toAddr(lsa) |
61 rsa, _ := syscall.Getpeername(fd) | 61 rsa, _ := syscall.Getpeername(fd) |
62 raddr := toAddr(rsa) | 62 raddr := toAddr(rsa) |
63 | 63 |
64 » netfd, err := newFD(fd, family, sotype, laddr.Network()) | 64 » err = syscall.SetNonblock(fd, true) |
65 if err != nil { | 65 if err != nil { |
66 closesocket(fd) | 66 closesocket(fd) |
67 return nil, err | 67 return nil, err |
68 } | 68 } |
| 69 netfd := newFD(fd, family, sotype, laddr.Network()) |
69 netfd.setAddr(laddr, raddr) | 70 netfd.setAddr(laddr, raddr) |
70 return netfd, nil | 71 return netfd, nil |
71 } | 72 } |
72 | 73 |
73 // FileConn returns a copy of the network connection corresponding to | 74 // FileConn returns a copy of the network connection corresponding to |
74 // the open file f. It is the caller's responsibility to close f when | 75 // the open file f. It is the caller's responsibility to close f when |
75 // finished. Closing c does not affect f, and closing f does not | 76 // finished. Closing c does not affect f, and closing f does not |
76 // affect c. | 77 // affect c. |
77 func FileConn(f *os.File) (c Conn, err error) { | 78 func FileConn(f *os.File) (c Conn, err error) { |
78 fd, err := newFileFD(f) | 79 fd, err := newFileFD(f) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 } | 124 } |
124 switch fd.laddr.(type) { | 125 switch fd.laddr.(type) { |
125 case *UDPAddr: | 126 case *UDPAddr: |
126 return newUDPConn(fd), nil | 127 return newUDPConn(fd), nil |
127 case *UnixAddr: | 128 case *UnixAddr: |
128 return newUnixConn(fd), nil | 129 return newUnixConn(fd), nil |
129 } | 130 } |
130 fd.Close() | 131 fd.Close() |
131 return nil, syscall.EINVAL | 132 return nil, syscall.EINVAL |
132 } | 133 } |
LEFT | RIGHT |