Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(51)

Delta Between Two Patch Sets: src/pkg/net/unixsock_posix.go

Issue 7058062: code review 7058062: syscall: handle empty address in ReadFrom better (Closed)
Left Patch Set: diff -r 7f25ce26f38f http://code.google.com/p/go Created 11 years, 2 months ago
Right Patch Set: diff -r f6172d444cc0 http://code.google.com/p/go Created 11 years, 2 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/net/unix_test.go ('k') | src/pkg/syscall/syscall_bsd.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 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 windows 5 // +build darwin freebsd linux netbsd openbsd windows
6 6
7 // Unix domain sockets 7 // Unix domain sockets
8 8
9 package net 9 package net
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // ReadFromUnix can be made to time out and return an error with 117 // ReadFromUnix can be made to time out and return an error with
118 // Timeout() == true after a fixed time limit; see SetDeadline and 118 // Timeout() == true after a fixed time limit; see SetDeadline and
119 // SetReadDeadline. 119 // SetReadDeadline.
120 func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *UnixAddr, err error) { 120 func (c *UnixConn) ReadFromUnix(b []byte) (n int, addr *UnixAddr, err error) {
121 if !c.ok() { 121 if !c.ok() {
122 return 0, nil, syscall.EINVAL 122 return 0, nil, syscall.EINVAL
123 } 123 }
124 n, sa, err := c.fd.ReadFrom(b) 124 n, sa, err := c.fd.ReadFrom(b)
125 switch sa := sa.(type) { 125 switch sa := sa.(type) {
126 case *syscall.SockaddrUnix: 126 case *syscall.SockaddrUnix:
127 » » addr = &UnixAddr{sa.Name, sotypeToNet(c.fd.sotype)} 127 » » if sa.Name != "" {
128 » » » addr = &UnixAddr{sa.Name, sotypeToNet(c.fd.sotype)}
129 » » }
128 } 130 }
129 return 131 return
130 } 132 }
131 133
132 // ReadFrom implements the PacketConn ReadFrom method. 134 // ReadFrom implements the PacketConn ReadFrom method.
133 func (c *UnixConn) ReadFrom(b []byte) (n int, addr Addr, err error) { 135 func (c *UnixConn) ReadFrom(b []byte) (int, Addr, error) {
134 if !c.ok() { 136 if !c.ok() {
135 return 0, nil, syscall.EINVAL 137 return 0, nil, syscall.EINVAL
136 } 138 }
137 » n, uaddr, err := c.ReadFromUnix(b) 139 » n, addr, err := c.ReadFromUnix(b)
138 » return n, uaddr.toAddr(), err 140 » return n, addr.toAddr(), err
139 } 141 }
140 142
141 // ReadMsgUnix reads a packet from c, copying the payload into b and 143 // ReadMsgUnix reads a packet from c, copying the payload into b and
142 // the associated out-of-band data into oob. It returns the number of 144 // the associated out-of-band data into oob. It returns the number of
143 // bytes copied into b, the number of bytes copied into oob, the flags 145 // bytes copied into b, the number of bytes copied into oob, the flags
144 // that were set on the packet, and the source address of the packet. 146 // that were set on the packet, and the source address of the packet.
145 func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAdd r, err error) { 147 func (c *UnixConn) ReadMsgUnix(b, oob []byte) (n, oobn, flags int, addr *UnixAdd r, err error) {
146 if !c.ok() { 148 if !c.ok() {
147 return 0, 0, 0, nil, syscall.EINVAL 149 return 0, 0, 0, nil, syscall.EINVAL
148 } 150 }
149 n, oobn, flags, sa, err := c.fd.ReadMsg(b, oob) 151 n, oobn, flags, sa, err := c.fd.ReadMsg(b, oob)
150 switch sa := sa.(type) { 152 switch sa := sa.(type) {
151 case *syscall.SockaddrUnix: 153 case *syscall.SockaddrUnix:
152 » » addr = &UnixAddr{sa.Name, sotypeToNet(c.fd.sotype)} 154 » » if sa.Name != "" {
155 » » » addr = &UnixAddr{sa.Name, sotypeToNet(c.fd.sotype)}
156 » » }
153 } 157 }
154 return 158 return
155 } 159 }
156 160
157 // WriteToUnix writes a packet to addr via c, copying the payload from b. 161 // WriteToUnix writes a packet to addr via c, copying the payload from b.
158 // 162 //
159 // WriteToUnix can be made to time out and return an error with 163 // WriteToUnix can be made to time out and return an error with
160 // Timeout() == true after a fixed time limit; see SetDeadline and 164 // Timeout() == true after a fixed time limit; see SetDeadline and
161 // SetWriteDeadline. On packet-oriented connections, write timeouts 165 // SetWriteDeadline. On packet-oriented connections, write timeouts
162 // are rare. 166 // are rare.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 } 350 }
347 if laddr == nil { 351 if laddr == nil {
348 return nil, &OpError{"listen", net, nil, errMissingAddress} 352 return nil, &OpError{"listen", net, nil, errMissingAddress}
349 } 353 }
350 fd, err := unixSocket(net, laddr, nil, "listen", noDeadline) 354 fd, err := unixSocket(net, laddr, nil, "listen", noDeadline)
351 if err != nil { 355 if err != nil {
352 return nil, err 356 return nil, err
353 } 357 }
354 return newUnixConn(fd), nil 358 return newUnixConn(fd), nil
355 } 359 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b