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

Side by Side Diff: src/pkg/net/fd_windows.go

Issue 3136042: code review 3136042: net: add ReadFrom and WriteTo windows version. (Closed)
Patch Set: code review 3136042: net: add ReadFrom and WriteTo windows version. Created 14 years, 4 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:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/pkg/syscall/syscall_windows.go » ('j') | src/pkg/syscall/syscall_windows.go » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 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 package net 5 package net
6 6
7 import ( 7 import (
8 "os" 8 "os"
9 "sync" 9 "sync"
10 "syscall" 10 "syscall"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 err = &OpError{"WSARecv", fd.net, fd.laddr, os.Errno(r.errno)} 236 err = &OpError{"WSARecv", fd.net, fd.laddr, os.Errno(r.errno)}
237 } 237 }
238 n = int(r.qty) 238 n = int(r.qty)
239 if err == nil && n == 0 { 239 if err == nil && n == 0 {
240 err = os.EOF 240 err = os.EOF
241 } 241 }
242 return 242 return
243 } 243 }
244 244
245 func (fd *netFD) ReadFrom(p []byte) (n int, sa syscall.Sockaddr, err os.Error) { 245 func (fd *netFD) ReadFrom(p []byte) (n int, sa syscall.Sockaddr, err os.Error) {
246 » var r syscall.Sockaddr 246 » if fd == nil {
247 » return 0, r, nil 247 » » return 0, nil, os.EINVAL
248 » }
249 » if len(p) == 0 {
250 » » return 0, nil, nil
251 » }
252 » fd.rio.Lock()
253 » defer fd.rio.Unlock()
254 » fd.incref()
255 » defer fd.decref()
256 » if fd.sysfile == nil {
257 » » return 0, nil, os.EINVAL
258 » }
259 » // Submit receive request.
260 » var pckt ioPacket
261 » pckt.c = fd.cr
262 » var done uint32
263 » flags := uint32(0)
264 » var rsa syscall.RawSockaddrAny
265 » l := int32(unsafe.Sizeof(rsa))
266 » e := syscall.WSARecvFrom(uint32(fd.sysfd), newWSABuf(p), 1, &done, &flag s, &rsa, &l, &pckt.o, nil)
267 » switch e {
268 » case 0:
269 » » // IO completed immediately, but we need to get our completion m essage anyway.
270 » case syscall.ERROR_IO_PENDING:
271 » » // IO started, and we have to wait for it's completion.
272 » default:
273 » » return 0, nil, &OpError{"WSARecvFrom", fd.net, fd.laddr, os.Errn o(e)}
274 » }
275 » // Wait for our request to complete.
276 » r := <-pckt.c
277 » if r.errno != 0 {
278 » » err = &OpError{"WSARecvFrom", fd.net, fd.laddr, os.Errno(r.errno )}
279 » }
280 » n = int(r.qty)
281 » sa, _ = rsa.Sockaddr()
282 » return
248 } 283 }
249 284
250 func (fd *netFD) Write(p []byte) (n int, err os.Error) { 285 func (fd *netFD) Write(p []byte) (n int, err os.Error) {
251 if fd == nil { 286 if fd == nil {
252 return 0, os.EINVAL 287 return 0, os.EINVAL
253 } 288 }
254 fd.wio.Lock() 289 fd.wio.Lock()
255 defer fd.wio.Unlock() 290 defer fd.wio.Unlock()
256 fd.incref() 291 fd.incref()
257 defer fd.decref() 292 defer fd.decref()
(...skipping 16 matching lines...) Expand all
274 // Wait for our request to complete. 309 // Wait for our request to complete.
275 r := <-pckt.c 310 r := <-pckt.c
276 if r.errno != 0 { 311 if r.errno != 0 {
277 err = &OpError{"WSASend", fd.net, fd.laddr, os.Errno(r.errno)} 312 err = &OpError{"WSASend", fd.net, fd.laddr, os.Errno(r.errno)}
278 } 313 }
279 n = int(r.qty) 314 n = int(r.qty)
280 return 315 return
281 } 316 }
282 317
283 func (fd *netFD) WriteTo(p []byte, sa syscall.Sockaddr) (n int, err os.Error) { 318 func (fd *netFD) WriteTo(p []byte, sa syscall.Sockaddr) (n int, err os.Error) {
284 » return 0, nil 319 » if fd == nil {
320 » » return 0, os.EINVAL
321 » }
322 » if len(p) == 0 {
323 » » return 0, nil
324 » }
325 » fd.wio.Lock()
326 » defer fd.wio.Unlock()
327 » fd.incref()
328 » defer fd.decref()
329 » if fd.sysfile == nil {
330 » » return 0, os.EINVAL
331 » }
332 » // Submit send request.
333 » var pckt ioPacket
334 » pckt.c = fd.cw
335 » var done uint32
336 » e := syscall.WSASendTo(uint32(fd.sysfd), newWSABuf(p), 1, &done, 0, sa, &pckt.o, nil)
337 » switch e {
338 » case 0:
339 » » // IO completed immediately, but we need to get our completion m essage anyway.
340 » case syscall.ERROR_IO_PENDING:
341 » » // IO started, and we have to wait for it's completion.
342 » default:
343 » » return 0, &OpError{"WSASendTo", fd.net, fd.laddr, os.Errno(e)}
344 » }
345 » // Wait for our request to complete.
346 » r := <-pckt.c
347 » if r.errno != 0 {
348 » » err = &OpError{"WSASendTo", fd.net, fd.laddr, os.Errno(r.errno)}
349 » }
350 » n = int(r.qty)
351 » return
285 } 352 }
286 353
287 func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os. Error) { 354 func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os. Error) {
288 if fd == nil || fd.sysfile == nil { 355 if fd == nil || fd.sysfile == nil {
289 return nil, os.EINVAL 356 return nil, os.EINVAL
290 } 357 }
291 fd.incref() 358 fd.incref()
292 defer fd.decref() 359 defer fd.decref()
293 360
294 // Get new socket. 361 // Get new socket.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 e := syscall.WSAStartup(uint32(0x101), &d) 438 e := syscall.WSAStartup(uint32(0x101), &d)
372 if e != 0 { 439 if e != 0 {
373 initErr = os.NewSyscallError("WSAStartup", e) 440 initErr = os.NewSyscallError("WSAStartup", e)
374 } 441 }
375 } 442 }
376 443
377 func (fd *netFD) dup() (f *os.File, err os.Error) { 444 func (fd *netFD) dup() (f *os.File, err os.Error) {
378 // TODO: Implement this 445 // TODO: Implement this
379 return nil, os.NewSyscallError("dup", syscall.EWINDOWS) 446 return nil, os.NewSyscallError("dup", syscall.EWINDOWS)
380 } 447 }
OLDNEW
« no previous file with comments | « no previous file | src/pkg/syscall/syscall_windows.go » ('j') | src/pkg/syscall/syscall_windows.go » ('J')

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