Left: | ||
Right: |
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" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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() |
129 fd.sysfile.Close() | 129 fd.sysfile.Close() |
130 fd.sysfile = nil | 130 fd.sysfile = nil |
131 fd.sysfd = -1 | 131 fd.sysfd = -1 |
132 } | 132 } |
133 fd.sysmu.Unlock() | 133 fd.sysmu.Unlock() |
134 } | 134 } |
135 | 135 |
136 func (fd *netFD) close() error { | |
dvyukov
2013/04/05 16:30:19
Why can't we use Close() instead of close()?
As fa
mikio
2013/04/06 07:42:12
I just don't want to break Rémy's changeset: 15019
| |
137 fd.pd.Evict() | |
138 fd.pd.Close() | |
139 return closesocket(fd.sysfd) | |
140 } | |
141 | |
136 func (fd *netFD) Close() error { | 142 func (fd *netFD) Close() error { |
137 fd.pd.Lock() // needed for both fd.incref(true) and pollDesc.Evict | 143 fd.pd.Lock() // needed for both fd.incref(true) and pollDesc.Evict |
138 if err := fd.incref(true); err != nil { | 144 if err := fd.incref(true); err != nil { |
139 fd.pd.Unlock() | 145 fd.pd.Unlock() |
140 return err | 146 return err |
141 } | 147 } |
142 // Unblock any I/O. Once it all unblocks and returns, | 148 // Unblock any I/O. Once it all unblocks and returns, |
143 // so that it cannot be referring to fd.sysfd anymore, | 149 // so that it cannot be referring to fd.sysfd anymore, |
144 // the final decref will close fd.sysfd. This should happen | 150 // the final decref will close fd.sysfd. This should happen |
145 // fairly quickly, since all the I/O is non-blocking, and any | 151 // fairly quickly, since all the I/O is non-blocking, and any |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 if err = syscall.SetNonblock(ns, false); err != nil { | 423 if err = syscall.SetNonblock(ns, false); err != nil { |
418 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err} | 424 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err} |
419 } | 425 } |
420 | 426 |
421 return os.NewFile(uintptr(ns), fd.name()), nil | 427 return os.NewFile(uintptr(ns), fd.name()), nil |
422 } | 428 } |
423 | 429 |
424 func closesocket(s int) error { | 430 func closesocket(s int) error { |
425 return syscall.Close(s) | 431 return syscall.Close(s) |
426 } | 432 } |
OLD | NEW |