Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 return errClosing | 110 return errClosing |
111 } | 111 } |
112 fd.sysref++ | 112 fd.sysref++ |
113 if closing { | 113 if closing { |
114 fd.closing = true | 114 fd.closing = true |
115 } | 115 } |
116 fd.sysmu.Unlock() | 116 fd.sysmu.Unlock() |
117 return nil | 117 return nil |
118 } | 118 } |
119 | 119 |
120 // Remove a reference to this FD and close if we've been asked to do so. | 120 // Remove a reference to this FD and close if we've been asked to do so (and |
121 // (and there are no references left.) | 121 // there are no references left. |
dfc
2013/04/08 07:19:29
please revert this documentation change, just clos
mikio
2013/04/09 02:06:34
i'll leave it to you.
feel free to send a cl at th
| |
122 func (fd *netFD) decref() { | 122 func (fd *netFD) decref() { |
123 fd.sysmu.Lock() | 123 fd.sysmu.Lock() |
124 fd.sysref-- | 124 fd.sysref-- |
125 if fd.closing && fd.sysref == 0 { | 125 if fd.closing && fd.sysref == 0 { |
dfc
2013/04/08 07:19:29
in the previous version fd.sysfile != nil was the
| |
126 // Poller may want to unregister fd in readiness notification me chanism, | 126 // Poller may want to unregister fd in readiness notification me chanism, |
127 // so this must be executed before sysfile.Close(). | 127 // so this must be executed before sysfile.Close(). |
128 fd.pd.Close() | 128 fd.pd.Close() |
dvyukov
2013/04/09 04:07:48
This can not be called twice, right?
| |
129 if fd.sysfile != nil { | 129 if fd.sysfile != nil { |
130 fd.sysfile.Close() | 130 fd.sysfile.Close() |
131 fd.sysfile = nil | 131 fd.sysfile = nil |
132 } else { | 132 } else { |
dfc
2013/04/08 07:19:29
could you please add a comment explaining why fd.s
mikio
2013/04/09 02:06:34
thanks but no thanks.
it's obvious that that's a c
| |
133 closesocket(fd.sysfd) | 133 closesocket(fd.sysfd) |
134 } | 134 } |
135 fd.sysfd = -1 | 135 fd.sysfd = -1 |
136 } | 136 } |
137 fd.sysmu.Unlock() | 137 fd.sysmu.Unlock() |
138 } | 138 } |
139 | 139 |
140 func (fd *netFD) Close() error { | 140 func (fd *netFD) Close() error { |
141 fd.pd.Lock() // needed for both fd.incref(true) and pollDesc.Evict | 141 fd.pd.Lock() // needed for both fd.incref(true) and pollDesc.Evict |
142 if err := fd.incref(true); err != nil { | 142 if err := fd.incref(true); err != nil { |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 if err = syscall.SetNonblock(ns, false); err != nil { | 421 if err = syscall.SetNonblock(ns, false); err != nil { |
422 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err} | 422 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err} |
423 } | 423 } |
424 | 424 |
425 return os.NewFile(uintptr(ns), fd.name()), nil | 425 return os.NewFile(uintptr(ns), fd.name()), nil |
426 } | 426 } |
427 | 427 |
428 func closesocket(s int) error { | 428 func closesocket(s int) error { |
429 return syscall.Close(s) | 429 return syscall.Close(s) |
430 } | 430 } |
LEFT | RIGHT |