Left: | ||
Right: |
OLD | NEW |
---|---|
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 24 matching lines...) Expand all Loading... | |
35 if e != nil { | 35 if e != nil { |
36 initErr = os.NewSyscallError("WSAStartup", e) | 36 initErr = os.NewSyscallError("WSAStartup", e) |
37 } | 37 } |
38 canCancelIO = syscall.LoadCancelIoEx() == nil | 38 canCancelIO = syscall.LoadCancelIoEx() == nil |
39 if syscall.LoadGetAddrInfo() == nil { | 39 if syscall.LoadGetAddrInfo() == nil { |
40 lookupPort = newLookupPort | 40 lookupPort = newLookupPort |
41 lookupIP = newLookupIP | 41 lookupIP = newLookupIP |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 func closesocket(s syscall.Handle) error { | |
46 return syscall.Closesocket(s) | |
47 } | |
48 | |
49 func canUseConnectEx(net string) bool { | 45 func canUseConnectEx(net string) bool { |
50 if net == "udp" || net == "udp4" || net == "udp6" { | 46 if net == "udp" || net == "udp4" || net == "udp6" { |
51 // ConnectEx windows API does not support connectionless sockets . | 47 // ConnectEx windows API does not support connectionless sockets . |
52 return false | 48 return false |
53 } | 49 } |
54 return syscall.LoadConnectEx() == nil | 50 return syscall.LoadConnectEx() == nil |
55 } | 51 } |
56 | 52 |
57 func resolveAndDial(net, addr string, localAddr Addr, deadline time.Time) (Conn, error) { | 53 func resolveAndDial(net, addr string, localAddr Addr, deadline time.Time) (Conn, error) { |
58 if !canUseConnectEx(net) { | 54 if !canUseConnectEx(net) { |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 fd.sysref-- | 420 fd.sysref-- |
425 if fd.closing && fd.sysref == 0 && fd.sysfd != syscall.InvalidHandle { | 421 if fd.closing && fd.sysref == 0 && fd.sysfd != syscall.InvalidHandle { |
426 closesocket(fd.sysfd) | 422 closesocket(fd.sysfd) |
427 fd.sysfd = syscall.InvalidHandle | 423 fd.sysfd = syscall.InvalidHandle |
428 // no need for a finalizer anymore | 424 // no need for a finalizer anymore |
429 runtime.SetFinalizer(fd, nil) | 425 runtime.SetFinalizer(fd, nil) |
430 } | 426 } |
431 fd.sysmu.Unlock() | 427 fd.sysmu.Unlock() |
432 } | 428 } |
433 | 429 |
430 // closesocket closes a socket descriptor. | |
431 func closesocket(s syscall.Handle) error { | |
432 return syscall.Closesocket(s) | |
433 } | |
434 | |
435 // closeSocket closes a socket descriptor and an associated runtime | |
436 // integrated poll descriptor. | |
dvyukov
2013/04/07 04:27:39
Explain that "and an associated runtime integrated
mikio
2013/04/07 15:10:26
Done.
| |
437 func (fd *netFD) closeSocket() error { | |
438 return closesocket(fd.sysfd) | |
439 } | |
440 | |
434 func (fd *netFD) Close() error { | 441 func (fd *netFD) Close() error { |
435 if err := fd.incref(true); err != nil { | 442 if err := fd.incref(true); err != nil { |
436 return err | 443 return err |
437 } | 444 } |
438 defer fd.decref() | 445 defer fd.decref() |
439 // unblock pending reader and writer | 446 // unblock pending reader and writer |
440 close(fd.closec) | 447 close(fd.closec) |
441 // wait for both reader and writer to exit | 448 // wait for both reader and writer to exit |
442 fd.rio.Lock() | 449 fd.rio.Lock() |
443 defer fd.rio.Unlock() | 450 defer fd.rio.Unlock() |
(...skipping 15 matching lines...) Expand all Loading... | |
459 } | 466 } |
460 | 467 |
461 func (fd *netFD) CloseRead() error { | 468 func (fd *netFD) CloseRead() error { |
462 return fd.shutdown(syscall.SHUT_RD) | 469 return fd.shutdown(syscall.SHUT_RD) |
463 } | 470 } |
464 | 471 |
465 func (fd *netFD) CloseWrite() error { | 472 func (fd *netFD) CloseWrite() error { |
466 return fd.shutdown(syscall.SHUT_WR) | 473 return fd.shutdown(syscall.SHUT_WR) |
467 } | 474 } |
468 | 475 |
469 func (fd *netFD) closesocket() error { | |
470 return closesocket(fd.sysfd) | |
471 } | |
472 | |
473 // Read from network. | 476 // Read from network. |
474 | 477 |
475 type readOp struct { | 478 type readOp struct { |
476 bufOp | 479 bufOp |
477 } | 480 } |
478 | 481 |
479 func (o *readOp) Submit() error { | 482 func (o *readOp) Submit() error { |
480 var d, f uint32 | 483 var d, f uint32 |
481 return syscall.WSARecv(syscall.Handle(o.fd.sysfd), &o.buf, 1, &d, &f, &o .o, nil) | 484 return syscall.WSARecv(syscall.Handle(o.fd.sysfd), &o.buf, 1, &d, &f, &o .o, nil) |
482 } | 485 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 | 679 |
677 var errNoSupport = errors.New("address family not supported") | 680 var errNoSupport = errors.New("address family not supported") |
678 | 681 |
679 func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S ockaddr, err error) { | 682 func (fd *netFD) ReadMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S ockaddr, err error) { |
680 return 0, 0, 0, nil, errNoSupport | 683 return 0, 0, 0, nil, errNoSupport |
681 } | 684 } |
682 | 685 |
683 func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob n int, err error) { | 686 func (fd *netFD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob n int, err error) { |
684 return 0, 0, errNoSupport | 687 return 0, 0, errNoSupport |
685 } | 688 } |
OLD | NEW |