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

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

Issue 6873046: code review 6873046: net: change windows netFD finalizer to behave similar t... (Closed)
Patch Set: diff -r 1c823043ffc5 https://go.googlecode.com/hg/ Created 11 years, 3 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 | no next file » | no next file with comments »
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 "errors" 8 "errors"
9 "io" 9 "io"
10 "os" 10 "os"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 293 }
294 294
295 func allocFD(fd syscall.Handle, family, sotype int, net string) *netFD { 295 func allocFD(fd syscall.Handle, family, sotype int, net string) *netFD {
296 netfd := &netFD{ 296 netfd := &netFD{
297 sysfd: fd, 297 sysfd: fd,
298 family: family, 298 family: family,
299 sotype: sotype, 299 sotype: sotype,
300 net: net, 300 net: net,
301 closec: make(chan bool), 301 closec: make(chan bool),
302 } 302 }
303 runtime.SetFinalizer(netfd, (*netFD).Close)
304 return netfd 303 return netfd
305 } 304 }
306 305
307 func newFD(fd syscall.Handle, family, proto int, net string) (*netFD, error) { 306 func newFD(fd syscall.Handle, family, proto int, net string) (*netFD, error) {
308 if initErr != nil { 307 if initErr != nil {
309 return nil, initErr 308 return nil, initErr
310 } 309 }
311 onceStartServer.Do(startServer) 310 onceStartServer.Do(startServer)
312 // Associate our socket with resultsrv.iocp. 311 // Associate our socket with resultsrv.iocp.
313 if _, err := syscall.CreateIoCompletionPort(syscall.Handle(fd), resultsr v.iocp, 0, 0); err != nil { 312 if _, err := syscall.CreateIoCompletionPort(syscall.Handle(fd), resultsr v.iocp, 0, 0); err != nil {
314 return nil, err 313 return nil, err
315 } 314 }
316 return allocFD(fd, family, proto, net), nil 315 return allocFD(fd, family, proto, net), nil
317 } 316 }
318 317
319 func (fd *netFD) setAddr(laddr, raddr Addr) { 318 func (fd *netFD) setAddr(laddr, raddr Addr) {
320 fd.laddr = laddr 319 fd.laddr = laddr
321 fd.raddr = raddr 320 fd.raddr = raddr
321 runtime.SetFinalizer(fd, (*netFD).closesocket)
322 } 322 }
323 323
324 func (fd *netFD) connect(ra syscall.Sockaddr) error { 324 func (fd *netFD) connect(ra syscall.Sockaddr) error {
325 return syscall.Connect(fd.sysfd, ra) 325 return syscall.Connect(fd.sysfd, ra)
326 } 326 }
327 327
328 // Add a reference to this fd. 328 // Add a reference to this fd.
329 // If closing==true, mark the fd as closing. 329 // If closing==true, mark the fd as closing.
330 // Returns an error if the fd cannot be used. 330 // Returns an error if the fd cannot be used.
331 func (fd *netFD) incref(closing bool) error { 331 func (fd *netFD) incref(closing bool) error {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 391 }
392 392
393 func (fd *netFD) CloseRead() error { 393 func (fd *netFD) CloseRead() error {
394 return fd.shutdown(syscall.SHUT_RD) 394 return fd.shutdown(syscall.SHUT_RD)
395 } 395 }
396 396
397 func (fd *netFD) CloseWrite() error { 397 func (fd *netFD) CloseWrite() error {
398 return fd.shutdown(syscall.SHUT_WR) 398 return fd.shutdown(syscall.SHUT_WR)
399 } 399 }
400 400
401 func (fd *netFD) closesocket() error {
402 return closesocket(fd.sysfd)
403 }
404
401 // Read from network. 405 // Read from network.
402 406
403 type readOp struct { 407 type readOp struct {
404 bufOp 408 bufOp
405 } 409 }
406 410
407 func (o *readOp) Submit() error { 411 func (o *readOp) Submit() error {
408 var d, f uint32 412 var d, f uint32
409 return syscall.WSARecv(syscall.Handle(o.fd.sysfd), &o.buf, 1, &d, &f, &o .o, nil) 413 return syscall.WSARecv(syscall.Handle(o.fd.sysfd), &o.buf, 1, &d, &f, &o .o, nil)
410 } 414 }
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 613
610 var errNoSupport = errors.New("address family not supported") 614 var errNoSupport = errors.New("address family not supported")
611 615
612 func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S ockaddr, err error) { 616 func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S ockaddr, err error) {
613 return 0, 0, 0, nil, errNoSupport 617 return 0, 0, 0, nil, errNoSupport
614 } 618 }
615 619
616 func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob n int, err error) { 620 func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob n int, err error) {
617 return 0, 0, errNoSupport 621 return 0, 0, errNoSupport
618 } 622 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

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