OLD | NEW |
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 | 5 // +build darwin freebsd linux netbsd openbsd |
6 | 6 |
7 package net | 7 package net |
8 | 8 |
9 import ( | 9 import ( |
10 "io" | 10 "io" |
11 "os" | 11 "os" |
12 "runtime" | 12 "runtime" |
13 "sync" | 13 "sync" |
14 "syscall" | 14 "syscall" |
15 "time" | 15 "time" |
16 ) | 16 ) |
17 | 17 |
18 // Network file descriptor. | 18 // Network file descriptor. |
19 type netFD struct { | 19 type netFD struct { |
| 20 // 64 bit atomic operations require the value to be aligned on an |
| 21 // 8 byte boundary. Placing these fields at the top of the struct |
| 22 // guarentees they will be aligned so long as the heap allocator |
| 23 // aligns to 8 byte boundaries. The length of the struct must |
| 24 // also be a multiple of 8 to ensure that an array of netFD |
| 25 // structs is correctly aligned. A test in fd_unix_test.go ensures |
| 26 // this holds true on all architectures. |
| 27 // |
| 28 // TODO(dfc) move these fields back to their original position |
| 29 // when 599 is fixed. |
| 30 |
| 31 // read and write deadlines |
| 32 rdeadline, wdeadline int64 // nsec since 1970, 0 if not set |
| 33 |
20 // locking/lifetime of sysfd | 34 // locking/lifetime of sysfd |
21 sysmu sync.Mutex | 35 sysmu sync.Mutex |
22 sysref int | 36 sysref int |
23 | 37 |
24 // must lock both sysmu and pollserver to write | 38 // must lock both sysmu and pollserver to write |
25 // can lock either to read | 39 // can lock either to read |
26 closing bool | 40 closing bool |
27 | 41 |
28 // immutable until Close | 42 // immutable until Close |
29 sysfd int | 43 sysfd int |
30 family int | 44 family int |
31 sotype int | 45 sotype int |
32 isConnected bool | 46 isConnected bool |
33 sysfile *os.File | 47 sysfile *os.File |
34 cr chan error | 48 cr chan error |
35 cw chan error | 49 cw chan error |
36 net string | 50 net string |
37 laddr Addr | 51 laddr Addr |
38 raddr Addr | 52 raddr Addr |
39 | 53 |
40 » // owned by client | 54 » // serialize access to Read and Write methods |
41 » rdeadline int64 | 55 » rio, wio sync.Mutex |
42 » rio sync.Mutex | |
43 » wdeadline int64 | |
44 » wio sync.Mutex | |
45 | 56 |
46 // owned by fd wait server | 57 // owned by fd wait server |
47 ncr, ncw int | 58 ncr, ncw int |
48 | 59 |
49 // wait server | 60 // wait server |
50 pollServer *pollServer | 61 pollServer *pollServer |
51 } | 62 } |
52 | 63 |
53 // A pollServer helps FDs determine when to retry a non-blocking | 64 // A pollServer helps FDs determine when to retry a non-blocking |
54 // read or write after they get EAGAIN. When an FD needs to wait, | 65 // read or write after they get EAGAIN. When an FD needs to wait, |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 if err = syscall.SetNonblock(ns, false); err != nil { | 683 if err = syscall.SetNonblock(ns, false); err != nil { |
673 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err} | 684 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err} |
674 } | 685 } |
675 | 686 |
676 return os.NewFile(uintptr(ns), fd.name()), nil | 687 return os.NewFile(uintptr(ns), fd.name()), nil |
677 } | 688 } |
678 | 689 |
679 func closesocket(s int) error { | 690 func closesocket(s int) error { |
680 return syscall.Close(s) | 691 return syscall.Close(s) |
681 } | 692 } |
OLD | NEW |