Commit ac2f84d5 authored by Mikio Hara's avatar Mikio Hara

net: make unexposed methods start with lowercase letters

This change makes unexposed methods start with lowercase letters for
avoiding unnecessary confusion because the net package uses many
embedding structures and intrefaces for controlling exposure of APIs.

Note that this change leaves DNS-related methods as they are.

Change-Id: I253758d1659175c5d0af6b2efcd30ce83f46543d
Reviewed-on: https://go-review.googlesource.com/20784
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 50487b2c
...@@ -34,18 +34,18 @@ const ( ...@@ -34,18 +34,18 @@ const (
mutexWMask = (1<<20 - 1) << 43 mutexWMask = (1<<20 - 1) << 43
) )
// Read operations must do RWLock(true)/RWUnlock(true). // Read operations must do rwlock(true)/rwunlock(true).
// Write operations must do RWLock(false)/RWUnlock(false). // Write operations must do rwlock(false)/rwunlock(false).
// Misc operations must do Incref/Decref. Misc operations include functions like // Misc operations must do incref/decref. Misc operations include functions like
// setsockopt and setDeadline. They need to use Incref/Decref to ensure that // setsockopt and setDeadline. They need to use incref/decref to ensure that
// they operate on the correct fd in presence of a concurrent Close call // they operate on the correct fd in presence of a concurrent close call
// (otherwise fd can be closed under their feet). // (otherwise fd can be closed under their feet).
// Close operation must do IncrefAndClose/Decref. // Close operation must do increfAndClose/decref.
// RWLock/Incref return whether fd is open. // rwlock/incref return whether fd is open.
// RWUnlock/Decref return whether fd is closed and there are no remaining references. // rwunlock/decref return whether fd is closed and there are no remaining references.
func (mu *fdMutex) Incref() bool { func (mu *fdMutex) incref() bool {
for { for {
old := atomic.LoadUint64(&mu.state) old := atomic.LoadUint64(&mu.state)
if old&mutexClosed != 0 { if old&mutexClosed != 0 {
...@@ -61,7 +61,7 @@ func (mu *fdMutex) Incref() bool { ...@@ -61,7 +61,7 @@ func (mu *fdMutex) Incref() bool {
} }
} }
func (mu *fdMutex) IncrefAndClose() bool { func (mu *fdMutex) increfAndClose() bool {
for { for {
old := atomic.LoadUint64(&mu.state) old := atomic.LoadUint64(&mu.state)
if old&mutexClosed != 0 { if old&mutexClosed != 0 {
...@@ -90,7 +90,7 @@ func (mu *fdMutex) IncrefAndClose() bool { ...@@ -90,7 +90,7 @@ func (mu *fdMutex) IncrefAndClose() bool {
} }
} }
func (mu *fdMutex) Decref() bool { func (mu *fdMutex) decref() bool {
for { for {
old := atomic.LoadUint64(&mu.state) old := atomic.LoadUint64(&mu.state)
if old&mutexRefMask == 0 { if old&mutexRefMask == 0 {
...@@ -103,7 +103,7 @@ func (mu *fdMutex) Decref() bool { ...@@ -103,7 +103,7 @@ func (mu *fdMutex) Decref() bool {
} }
} }
func (mu *fdMutex) RWLock(read bool) bool { func (mu *fdMutex) rwlock(read bool) bool {
var mutexBit, mutexWait, mutexMask uint64 var mutexBit, mutexWait, mutexMask uint64
var mutexSema *uint32 var mutexSema *uint32
if read { if read {
...@@ -146,7 +146,7 @@ func (mu *fdMutex) RWLock(read bool) bool { ...@@ -146,7 +146,7 @@ func (mu *fdMutex) RWLock(read bool) bool {
} }
} }
func (mu *fdMutex) RWUnlock(read bool) bool { func (mu *fdMutex) rwunlock(read bool) bool {
var mutexBit, mutexWait, mutexMask uint64 var mutexBit, mutexWait, mutexMask uint64
var mutexSema *uint32 var mutexSema *uint32
if read { if read {
......
...@@ -14,44 +14,44 @@ import ( ...@@ -14,44 +14,44 @@ import (
func TestMutexLock(t *testing.T) { func TestMutexLock(t *testing.T) {
var mu fdMutex var mu fdMutex
if !mu.Incref() { if !mu.incref() {
t.Fatal("broken") t.Fatal("broken")
} }
if mu.Decref() { if mu.decref() {
t.Fatal("broken") t.Fatal("broken")
} }
if !mu.RWLock(true) { if !mu.rwlock(true) {
t.Fatal("broken") t.Fatal("broken")
} }
if mu.RWUnlock(true) { if mu.rwunlock(true) {
t.Fatal("broken") t.Fatal("broken")
} }
if !mu.RWLock(false) { if !mu.rwlock(false) {
t.Fatal("broken") t.Fatal("broken")
} }
if mu.RWUnlock(false) { if mu.rwunlock(false) {
t.Fatal("broken") t.Fatal("broken")
} }
} }
func TestMutexClose(t *testing.T) { func TestMutexClose(t *testing.T) {
var mu fdMutex var mu fdMutex
if !mu.IncrefAndClose() { if !mu.increfAndClose() {
t.Fatal("broken") t.Fatal("broken")
} }
if mu.Incref() { if mu.incref() {
t.Fatal("broken") t.Fatal("broken")
} }
if mu.RWLock(true) { if mu.rwlock(true) {
t.Fatal("broken") t.Fatal("broken")
} }
if mu.RWLock(false) { if mu.rwlock(false) {
t.Fatal("broken") t.Fatal("broken")
} }
if mu.IncrefAndClose() { if mu.increfAndClose() {
t.Fatal("broken") t.Fatal("broken")
} }
} }
...@@ -59,10 +59,10 @@ func TestMutexClose(t *testing.T) { ...@@ -59,10 +59,10 @@ func TestMutexClose(t *testing.T) {
func TestMutexCloseUnblock(t *testing.T) { func TestMutexCloseUnblock(t *testing.T) {
c := make(chan bool) c := make(chan bool)
var mu fdMutex var mu fdMutex
mu.RWLock(true) mu.rwlock(true)
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
go func() { go func() {
if mu.RWLock(true) { if mu.rwlock(true) {
t.Error("broken") t.Error("broken")
return return
} }
...@@ -76,7 +76,7 @@ func TestMutexCloseUnblock(t *testing.T) { ...@@ -76,7 +76,7 @@ func TestMutexCloseUnblock(t *testing.T) {
t.Fatal("broken") t.Fatal("broken")
default: default:
} }
mu.IncrefAndClose() // Must unblock the readers. mu.increfAndClose() // Must unblock the readers.
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
select { select {
case <-c: case <-c:
...@@ -84,10 +84,10 @@ func TestMutexCloseUnblock(t *testing.T) { ...@@ -84,10 +84,10 @@ func TestMutexCloseUnblock(t *testing.T) {
t.Fatal("broken") t.Fatal("broken")
} }
} }
if mu.Decref() { if mu.decref() {
t.Fatal("broken") t.Fatal("broken")
} }
if !mu.RWUnlock(true) { if !mu.rwunlock(true) {
t.Fatal("broken") t.Fatal("broken")
} }
} }
...@@ -103,21 +103,21 @@ func TestMutexPanic(t *testing.T) { ...@@ -103,21 +103,21 @@ func TestMutexPanic(t *testing.T) {
} }
var mu fdMutex var mu fdMutex
ensurePanics(func() { mu.Decref() }) ensurePanics(func() { mu.decref() })
ensurePanics(func() { mu.RWUnlock(true) }) ensurePanics(func() { mu.rwunlock(true) })
ensurePanics(func() { mu.RWUnlock(false) }) ensurePanics(func() { mu.rwunlock(false) })
ensurePanics(func() { mu.Incref(); mu.Decref(); mu.Decref() }) ensurePanics(func() { mu.incref(); mu.decref(); mu.decref() })
ensurePanics(func() { mu.RWLock(true); mu.RWUnlock(true); mu.RWUnlock(true) }) ensurePanics(func() { mu.rwlock(true); mu.rwunlock(true); mu.rwunlock(true) })
ensurePanics(func() { mu.RWLock(false); mu.RWUnlock(false); mu.RWUnlock(false) }) ensurePanics(func() { mu.rwlock(false); mu.rwunlock(false); mu.rwunlock(false) })
// ensure that it's still not broken // ensure that it's still not broken
mu.Incref() mu.incref()
mu.Decref() mu.decref()
mu.RWLock(true) mu.rwlock(true)
mu.RWUnlock(true) mu.rwunlock(true)
mu.RWLock(false) mu.rwlock(false)
mu.RWUnlock(false) mu.rwunlock(false)
} }
func TestMutexStress(t *testing.T) { func TestMutexStress(t *testing.T) {
...@@ -138,16 +138,16 @@ func TestMutexStress(t *testing.T) { ...@@ -138,16 +138,16 @@ func TestMutexStress(t *testing.T) {
for i := 0; i < N; i++ { for i := 0; i < N; i++ {
switch r.Intn(3) { switch r.Intn(3) {
case 0: case 0:
if !mu.Incref() { if !mu.incref() {
t.Error("broken") t.Error("broken")
return return
} }
if mu.Decref() { if mu.decref() {
t.Error("broken") t.Error("broken")
return return
} }
case 1: case 1:
if !mu.RWLock(true) { if !mu.rwlock(true) {
t.Error("broken") t.Error("broken")
return return
} }
...@@ -158,12 +158,12 @@ func TestMutexStress(t *testing.T) { ...@@ -158,12 +158,12 @@ func TestMutexStress(t *testing.T) {
} }
readState[0]++ readState[0]++
readState[1]++ readState[1]++
if mu.RWUnlock(true) { if mu.rwunlock(true) {
t.Error("broken") t.Error("broken")
return return
} }
case 2: case 2:
if !mu.RWLock(false) { if !mu.rwlock(false) {
t.Error("broken") t.Error("broken")
return return
} }
...@@ -174,7 +174,7 @@ func TestMutexStress(t *testing.T) { ...@@ -174,7 +174,7 @@ func TestMutexStress(t *testing.T) {
} }
writeState[0]++ writeState[0]++
writeState[1]++ writeState[1]++
if mu.RWUnlock(false) { if mu.rwunlock(false) {
t.Error("broken") t.Error("broken")
return return
} }
...@@ -186,10 +186,10 @@ func TestMutexStress(t *testing.T) { ...@@ -186,10 +186,10 @@ func TestMutexStress(t *testing.T) {
for p := 0; p < P; p++ { for p := 0; p < P; p++ {
<-done <-done
} }
if !mu.IncrefAndClose() { if !mu.increfAndClose() {
t.Fatal("broken") t.Fatal("broken")
} }
if !mu.Decref() { if !mu.decref() {
t.Fatal("broken") t.Fatal("broken")
} }
} }
...@@ -77,7 +77,7 @@ func (fd *netFD) destroy() { ...@@ -77,7 +77,7 @@ func (fd *netFD) destroy() {
// Add a reference to this fd. // Add a reference to this fd.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) incref() error { func (fd *netFD) incref() error {
if !fd.fdmu.Incref() { if !fd.fdmu.incref() {
return errClosing return errClosing
} }
return nil return nil
...@@ -86,7 +86,7 @@ func (fd *netFD) incref() error { ...@@ -86,7 +86,7 @@ func (fd *netFD) incref() error {
// Remove a reference to this FD and close if we've been asked to do so // Remove a reference to this FD and close if we've been asked to do so
// (and there are no references left). // (and there are no references left).
func (fd *netFD) decref() { func (fd *netFD) decref() {
if fd.fdmu.Decref() { if fd.fdmu.decref() {
fd.destroy() fd.destroy()
} }
} }
...@@ -94,7 +94,7 @@ func (fd *netFD) decref() { ...@@ -94,7 +94,7 @@ func (fd *netFD) decref() {
// Add a reference to this fd and lock for reading. // Add a reference to this fd and lock for reading.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) readLock() error { func (fd *netFD) readLock() error {
if !fd.fdmu.RWLock(true) { if !fd.fdmu.rwlock(true) {
return errClosing return errClosing
} }
return nil return nil
...@@ -102,7 +102,7 @@ func (fd *netFD) readLock() error { ...@@ -102,7 +102,7 @@ func (fd *netFD) readLock() error {
// Unlock for reading and remove a reference to this FD. // Unlock for reading and remove a reference to this FD.
func (fd *netFD) readUnlock() { func (fd *netFD) readUnlock() {
if fd.fdmu.RWUnlock(true) { if fd.fdmu.rwunlock(true) {
fd.destroy() fd.destroy()
} }
} }
...@@ -110,7 +110,7 @@ func (fd *netFD) readUnlock() { ...@@ -110,7 +110,7 @@ func (fd *netFD) readUnlock() {
// Add a reference to this fd and lock for writing. // Add a reference to this fd and lock for writing.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) writeLock() error { func (fd *netFD) writeLock() error {
if !fd.fdmu.RWLock(false) { if !fd.fdmu.rwlock(false) {
return errClosing return errClosing
} }
return nil return nil
...@@ -118,7 +118,7 @@ func (fd *netFD) writeLock() error { ...@@ -118,7 +118,7 @@ func (fd *netFD) writeLock() error {
// Unlock for writing and remove a reference to this FD. // Unlock for writing and remove a reference to this FD.
func (fd *netFD) writeUnlock() { func (fd *netFD) writeUnlock() {
if fd.fdmu.RWUnlock(false) { if fd.fdmu.rwunlock(false) {
fd.destroy() fd.destroy()
} }
} }
...@@ -165,7 +165,7 @@ func (fd *netFD) closeWrite() error { ...@@ -165,7 +165,7 @@ func (fd *netFD) closeWrite() error {
} }
func (fd *netFD) Close() error { func (fd *netFD) Close() error {
if !fd.fdmu.IncrefAndClose() { if !fd.fdmu.increfAndClose() {
return errClosing return errClosing
} }
if !fd.ok() { if !fd.ok() {
......
...@@ -14,44 +14,44 @@ type pollDesc struct { ...@@ -14,44 +14,44 @@ type pollDesc struct {
closing bool closing bool
} }
func (pd *pollDesc) Init(fd *netFD) error { pd.fd = fd; return nil } func (pd *pollDesc) init(fd *netFD) error { pd.fd = fd; return nil }
func (pd *pollDesc) Close() {} func (pd *pollDesc) close() {}
func (pd *pollDesc) Evict() { func (pd *pollDesc) evict() {
pd.closing = true pd.closing = true
if pd.fd != nil { if pd.fd != nil {
syscall.StopIO(pd.fd.sysfd) syscall.StopIO(pd.fd.sysfd)
} }
} }
func (pd *pollDesc) Prepare(mode int) error { func (pd *pollDesc) prepare(mode int) error {
if pd.closing { if pd.closing {
return errClosing return errClosing
} }
return nil return nil
} }
func (pd *pollDesc) PrepareRead() error { return pd.Prepare('r') } func (pd *pollDesc) prepareRead() error { return pd.prepare('r') }
func (pd *pollDesc) PrepareWrite() error { return pd.Prepare('w') } func (pd *pollDesc) prepareWrite() error { return pd.prepare('w') }
func (pd *pollDesc) Wait(mode int) error { func (pd *pollDesc) wait(mode int) error {
if pd.closing { if pd.closing {
return errClosing return errClosing
} }
return errTimeout return errTimeout
} }
func (pd *pollDesc) WaitRead() error { return pd.Wait('r') } func (pd *pollDesc) waitRead() error { return pd.wait('r') }
func (pd *pollDesc) WaitWrite() error { return pd.Wait('w') } func (pd *pollDesc) waitWrite() error { return pd.wait('w') }
func (pd *pollDesc) WaitCanceled(mode int) {} func (pd *pollDesc) waitCanceled(mode int) {}
func (pd *pollDesc) WaitCanceledRead() {} func (pd *pollDesc) waitCanceledRead() {}
func (pd *pollDesc) WaitCanceledWrite() {} func (pd *pollDesc) waitCanceledWrite() {}
func (fd *netFD) setDeadline(t time.Time) error { func (fd *netFD) setDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r'+'w') return setDeadlineImpl(fd, t, 'r'+'w')
......
...@@ -30,7 +30,7 @@ type pollDesc struct { ...@@ -30,7 +30,7 @@ type pollDesc struct {
var serverInit sync.Once var serverInit sync.Once
func (pd *pollDesc) Init(fd *netFD) error { func (pd *pollDesc) init(fd *netFD) error {
serverInit.Do(runtime_pollServerInit) serverInit.Do(runtime_pollServerInit)
ctx, errno := runtime_pollOpen(uintptr(fd.sysfd)) ctx, errno := runtime_pollOpen(uintptr(fd.sysfd))
if errno != 0 { if errno != 0 {
...@@ -40,7 +40,7 @@ func (pd *pollDesc) Init(fd *netFD) error { ...@@ -40,7 +40,7 @@ func (pd *pollDesc) Init(fd *netFD) error {
return nil return nil
} }
func (pd *pollDesc) Close() { func (pd *pollDesc) close() {
if pd.runtimeCtx == 0 { if pd.runtimeCtx == 0 {
return return
} }
...@@ -49,49 +49,49 @@ func (pd *pollDesc) Close() { ...@@ -49,49 +49,49 @@ func (pd *pollDesc) Close() {
} }
// Evict evicts fd from the pending list, unblocking any I/O running on fd. // Evict evicts fd from the pending list, unblocking any I/O running on fd.
func (pd *pollDesc) Evict() { func (pd *pollDesc) evict() {
if pd.runtimeCtx == 0 { if pd.runtimeCtx == 0 {
return return
} }
runtime_pollUnblock(pd.runtimeCtx) runtime_pollUnblock(pd.runtimeCtx)
} }
func (pd *pollDesc) Prepare(mode int) error { func (pd *pollDesc) prepare(mode int) error {
res := runtime_pollReset(pd.runtimeCtx, mode) res := runtime_pollReset(pd.runtimeCtx, mode)
return convertErr(res) return convertErr(res)
} }
func (pd *pollDesc) PrepareRead() error { func (pd *pollDesc) prepareRead() error {
return pd.Prepare('r') return pd.prepare('r')
} }
func (pd *pollDesc) PrepareWrite() error { func (pd *pollDesc) prepareWrite() error {
return pd.Prepare('w') return pd.prepare('w')
} }
func (pd *pollDesc) Wait(mode int) error { func (pd *pollDesc) wait(mode int) error {
res := runtime_pollWait(pd.runtimeCtx, mode) res := runtime_pollWait(pd.runtimeCtx, mode)
return convertErr(res) return convertErr(res)
} }
func (pd *pollDesc) WaitRead() error { func (pd *pollDesc) waitRead() error {
return pd.Wait('r') return pd.wait('r')
} }
func (pd *pollDesc) WaitWrite() error { func (pd *pollDesc) waitWrite() error {
return pd.Wait('w') return pd.wait('w')
} }
func (pd *pollDesc) WaitCanceled(mode int) { func (pd *pollDesc) waitCanceled(mode int) {
runtime_pollWaitCanceled(pd.runtimeCtx, mode) runtime_pollWaitCanceled(pd.runtimeCtx, mode)
} }
func (pd *pollDesc) WaitCanceledRead() { func (pd *pollDesc) waitCanceledRead() {
pd.WaitCanceled('r') pd.waitCanceled('r')
} }
func (pd *pollDesc) WaitCanceledWrite() { func (pd *pollDesc) waitCanceledWrite() {
pd.WaitCanceled('w') pd.waitCanceled('w')
} }
func convertErr(res int) error { func convertErr(res int) error {
......
...@@ -45,7 +45,7 @@ func newFD(sysfd, family, sotype int, net string) (*netFD, error) { ...@@ -45,7 +45,7 @@ func newFD(sysfd, family, sotype int, net string) (*netFD, error) {
} }
func (fd *netFD) init() error { func (fd *netFD) init() error {
if err := fd.pd.Init(fd); err != nil { if err := fd.pd.init(fd); err != nil {
return err return err
} }
return nil return nil
...@@ -124,7 +124,7 @@ func (fd *netFD) connect(la, ra syscall.Sockaddr, deadline time.Time, cancel <-c ...@@ -124,7 +124,7 @@ func (fd *netFD) connect(la, ra syscall.Sockaddr, deadline time.Time, cancel <-c
// SO_ERROR socket option to see if the connection // SO_ERROR socket option to see if the connection
// succeeded or failed. See issue 7474 for further // succeeded or failed. See issue 7474 for further
// details. // details.
if err := fd.pd.WaitWrite(); err != nil { if err := fd.pd.waitWrite(); err != nil {
select { select {
case <-cancel: case <-cancel:
return errCanceled return errCanceled
...@@ -158,7 +158,7 @@ func (fd *netFD) connect(la, ra syscall.Sockaddr, deadline time.Time, cancel <-c ...@@ -158,7 +158,7 @@ func (fd *netFD) connect(la, ra syscall.Sockaddr, deadline time.Time, cancel <-c
func (fd *netFD) destroy() { func (fd *netFD) destroy() {
// Poller may want to unregister fd in readiness notification mechanism, // Poller may want to unregister fd in readiness notification mechanism,
// so this must be executed before closeFunc. // so this must be executed before closeFunc.
fd.pd.Close() fd.pd.close()
closeFunc(fd.sysfd) closeFunc(fd.sysfd)
fd.sysfd = -1 fd.sysfd = -1
runtime.SetFinalizer(fd, nil) runtime.SetFinalizer(fd, nil)
...@@ -167,7 +167,7 @@ func (fd *netFD) destroy() { ...@@ -167,7 +167,7 @@ func (fd *netFD) destroy() {
// Add a reference to this fd. // Add a reference to this fd.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) incref() error { func (fd *netFD) incref() error {
if !fd.fdmu.Incref() { if !fd.fdmu.incref() {
return errClosing return errClosing
} }
return nil return nil
...@@ -176,7 +176,7 @@ func (fd *netFD) incref() error { ...@@ -176,7 +176,7 @@ func (fd *netFD) incref() error {
// Remove a reference to this FD and close if we've been asked to do so // Remove a reference to this FD and close if we've been asked to do so
// (and there are no references left). // (and there are no references left).
func (fd *netFD) decref() { func (fd *netFD) decref() {
if fd.fdmu.Decref() { if fd.fdmu.decref() {
fd.destroy() fd.destroy()
} }
} }
...@@ -184,7 +184,7 @@ func (fd *netFD) decref() { ...@@ -184,7 +184,7 @@ func (fd *netFD) decref() {
// Add a reference to this fd and lock for reading. // Add a reference to this fd and lock for reading.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) readLock() error { func (fd *netFD) readLock() error {
if !fd.fdmu.RWLock(true) { if !fd.fdmu.rwlock(true) {
return errClosing return errClosing
} }
return nil return nil
...@@ -192,7 +192,7 @@ func (fd *netFD) readLock() error { ...@@ -192,7 +192,7 @@ func (fd *netFD) readLock() error {
// Unlock for reading and remove a reference to this FD. // Unlock for reading and remove a reference to this FD.
func (fd *netFD) readUnlock() { func (fd *netFD) readUnlock() {
if fd.fdmu.RWUnlock(true) { if fd.fdmu.rwunlock(true) {
fd.destroy() fd.destroy()
} }
} }
...@@ -200,7 +200,7 @@ func (fd *netFD) readUnlock() { ...@@ -200,7 +200,7 @@ func (fd *netFD) readUnlock() {
// Add a reference to this fd and lock for writing. // Add a reference to this fd and lock for writing.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) writeLock() error { func (fd *netFD) writeLock() error {
if !fd.fdmu.RWLock(false) { if !fd.fdmu.rwlock(false) {
return errClosing return errClosing
} }
return nil return nil
...@@ -208,13 +208,13 @@ func (fd *netFD) writeLock() error { ...@@ -208,13 +208,13 @@ func (fd *netFD) writeLock() error {
// Unlock for writing and remove a reference to this FD. // Unlock for writing and remove a reference to this FD.
func (fd *netFD) writeUnlock() { func (fd *netFD) writeUnlock() {
if fd.fdmu.RWUnlock(false) { if fd.fdmu.rwunlock(false) {
fd.destroy() fd.destroy()
} }
} }
func (fd *netFD) Close() error { func (fd *netFD) Close() error {
if !fd.fdmu.IncrefAndClose() { if !fd.fdmu.increfAndClose() {
return errClosing return errClosing
} }
// Unblock any I/O. Once it all unblocks and returns, // Unblock any I/O. Once it all unblocks and returns,
...@@ -222,7 +222,7 @@ func (fd *netFD) Close() error { ...@@ -222,7 +222,7 @@ func (fd *netFD) Close() error {
// the final decref will close fd.sysfd. This should happen // the final decref will close fd.sysfd. This should happen
// fairly quickly, since all the I/O is non-blocking, and any // fairly quickly, since all the I/O is non-blocking, and any
// attempts to block in the pollDesc will return errClosing. // attempts to block in the pollDesc will return errClosing.
fd.pd.Evict() fd.pd.evict()
fd.decref() fd.decref()
return nil return nil
} }
...@@ -248,7 +248,7 @@ func (fd *netFD) Read(p []byte) (n int, err error) { ...@@ -248,7 +248,7 @@ func (fd *netFD) Read(p []byte) (n int, err error) {
return 0, err return 0, err
} }
defer fd.readUnlock() defer fd.readUnlock()
if err := fd.pd.PrepareRead(); err != nil { if err := fd.pd.prepareRead(); err != nil {
return 0, err return 0, err
} }
for { for {
...@@ -256,7 +256,7 @@ func (fd *netFD) Read(p []byte) (n int, err error) { ...@@ -256,7 +256,7 @@ func (fd *netFD) Read(p []byte) (n int, err error) {
if err != nil { if err != nil {
n = 0 n = 0
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
if err = fd.pd.WaitRead(); err == nil { if err = fd.pd.waitRead(); err == nil {
continue continue
} }
} }
...@@ -275,7 +275,7 @@ func (fd *netFD) readFrom(p []byte) (n int, sa syscall.Sockaddr, err error) { ...@@ -275,7 +275,7 @@ func (fd *netFD) readFrom(p []byte) (n int, sa syscall.Sockaddr, err error) {
return 0, nil, err return 0, nil, err
} }
defer fd.readUnlock() defer fd.readUnlock()
if err := fd.pd.PrepareRead(); err != nil { if err := fd.pd.prepareRead(); err != nil {
return 0, nil, err return 0, nil, err
} }
for { for {
...@@ -283,7 +283,7 @@ func (fd *netFD) readFrom(p []byte) (n int, sa syscall.Sockaddr, err error) { ...@@ -283,7 +283,7 @@ func (fd *netFD) readFrom(p []byte) (n int, sa syscall.Sockaddr, err error) {
if err != nil { if err != nil {
n = 0 n = 0
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
if err = fd.pd.WaitRead(); err == nil { if err = fd.pd.waitRead(); err == nil {
continue continue
} }
} }
...@@ -302,7 +302,7 @@ func (fd *netFD) readMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S ...@@ -302,7 +302,7 @@ func (fd *netFD) readMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S
return 0, 0, 0, nil, err return 0, 0, 0, nil, err
} }
defer fd.readUnlock() defer fd.readUnlock()
if err := fd.pd.PrepareRead(); err != nil { if err := fd.pd.prepareRead(); err != nil {
return 0, 0, 0, nil, err return 0, 0, 0, nil, err
} }
for { for {
...@@ -310,7 +310,7 @@ func (fd *netFD) readMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S ...@@ -310,7 +310,7 @@ func (fd *netFD) readMsg(p []byte, oob []byte) (n, oobn, flags int, sa syscall.S
if err != nil { if err != nil {
// TODO(dfc) should n and oobn be set to 0 // TODO(dfc) should n and oobn be set to 0
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
if err = fd.pd.WaitRead(); err == nil { if err = fd.pd.waitRead(); err == nil {
continue continue
} }
} }
...@@ -329,7 +329,7 @@ func (fd *netFD) Write(p []byte) (nn int, err error) { ...@@ -329,7 +329,7 @@ func (fd *netFD) Write(p []byte) (nn int, err error) {
return 0, err return 0, err
} }
defer fd.writeUnlock() defer fd.writeUnlock()
if err := fd.pd.PrepareWrite(); err != nil { if err := fd.pd.prepareWrite(); err != nil {
return 0, err return 0, err
} }
for { for {
...@@ -342,7 +342,7 @@ func (fd *netFD) Write(p []byte) (nn int, err error) { ...@@ -342,7 +342,7 @@ func (fd *netFD) Write(p []byte) (nn int, err error) {
break break
} }
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
if err = fd.pd.WaitWrite(); err == nil { if err = fd.pd.waitWrite(); err == nil {
continue continue
} }
} }
...@@ -365,13 +365,13 @@ func (fd *netFD) writeTo(p []byte, sa syscall.Sockaddr) (n int, err error) { ...@@ -365,13 +365,13 @@ func (fd *netFD) writeTo(p []byte, sa syscall.Sockaddr) (n int, err error) {
return 0, err return 0, err
} }
defer fd.writeUnlock() defer fd.writeUnlock()
if err := fd.pd.PrepareWrite(); err != nil { if err := fd.pd.prepareWrite(); err != nil {
return 0, err return 0, err
} }
for { for {
err = syscall.Sendto(fd.sysfd, p, 0, sa) err = syscall.Sendto(fd.sysfd, p, 0, sa)
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
if err = fd.pd.WaitWrite(); err == nil { if err = fd.pd.waitWrite(); err == nil {
continue continue
} }
} }
...@@ -391,13 +391,13 @@ func (fd *netFD) writeMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob ...@@ -391,13 +391,13 @@ func (fd *netFD) writeMsg(p []byte, oob []byte, sa syscall.Sockaddr) (n int, oob
return 0, 0, err return 0, 0, err
} }
defer fd.writeUnlock() defer fd.writeUnlock()
if err := fd.pd.PrepareWrite(); err != nil { if err := fd.pd.prepareWrite(); err != nil {
return 0, 0, err return 0, 0, err
} }
for { for {
n, err = syscall.SendmsgN(fd.sysfd, p, oob, sa, 0) n, err = syscall.SendmsgN(fd.sysfd, p, oob, sa, 0)
if err == syscall.EAGAIN { if err == syscall.EAGAIN {
if err = fd.pd.WaitWrite(); err == nil { if err = fd.pd.waitWrite(); err == nil {
continue continue
} }
} }
...@@ -420,7 +420,7 @@ func (fd *netFD) accept() (netfd *netFD, err error) { ...@@ -420,7 +420,7 @@ func (fd *netFD) accept() (netfd *netFD, err error) {
var s int var s int
var rsa syscall.Sockaddr var rsa syscall.Sockaddr
if err = fd.pd.PrepareRead(); err != nil { if err = fd.pd.prepareRead(); err != nil {
return nil, err return nil, err
} }
for { for {
...@@ -432,7 +432,7 @@ func (fd *netFD) accept() (netfd *netFD, err error) { ...@@ -432,7 +432,7 @@ func (fd *netFD) accept() (netfd *netFD, err error) {
} }
switch nerr.Err { switch nerr.Err {
case syscall.EAGAIN: case syscall.EAGAIN:
if err = fd.pd.WaitRead(); err == nil { if err = fd.pd.waitRead(); err == nil {
continue continue
} }
case syscall.ECONNABORTED: case syscall.ECONNABORTED:
......
...@@ -152,7 +152,7 @@ func (s *ioSrv) ProcessRemoteIO() { ...@@ -152,7 +152,7 @@ func (s *ioSrv) ProcessRemoteIO() {
func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) error) (int, error) { func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) error) (int, error) {
fd := o.fd fd := o.fd
// Notify runtime netpoll about starting IO. // Notify runtime netpoll about starting IO.
err := fd.pd.Prepare(int(o.mode)) err := fd.pd.prepare(int(o.mode))
if err != nil { if err != nil {
return 0, err return 0, err
} }
...@@ -180,7 +180,7 @@ func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) erro ...@@ -180,7 +180,7 @@ func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) erro
return 0, err return 0, err
} }
// Wait for our request to complete. // Wait for our request to complete.
err = fd.pd.Wait(int(o.mode)) err = fd.pd.wait(int(o.mode))
if err == nil { if err == nil {
// All is good. Extract our IO results and return. // All is good. Extract our IO results and return.
if o.errno != 0 { if o.errno != 0 {
...@@ -210,7 +210,7 @@ func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) erro ...@@ -210,7 +210,7 @@ func (s *ioSrv) ExecIO(o *operation, name string, submit func(o *operation) erro
<-o.errc <-o.errc
} }
// Wait for cancelation to complete. // Wait for cancelation to complete.
fd.pd.WaitCanceled(int(o.mode)) fd.pd.waitCanceled(int(o.mode))
if o.errno != 0 { if o.errno != 0 {
err = syscall.Errno(o.errno) err = syscall.Errno(o.errno)
if err == syscall.ERROR_OPERATION_ABORTED { // IO Canceled if err == syscall.ERROR_OPERATION_ABORTED { // IO Canceled
...@@ -273,7 +273,7 @@ func newFD(sysfd syscall.Handle, family, sotype int, net string) (*netFD, error) ...@@ -273,7 +273,7 @@ func newFD(sysfd syscall.Handle, family, sotype int, net string) (*netFD, error)
} }
func (fd *netFD) init() error { func (fd *netFD) init() error {
if err := fd.pd.Init(fd); err != nil { if err := fd.pd.init(fd); err != nil {
return err return err
} }
if hasLoadSetFileCompletionNotificationModes { if hasLoadSetFileCompletionNotificationModes {
...@@ -388,7 +388,7 @@ func (fd *netFD) destroy() { ...@@ -388,7 +388,7 @@ func (fd *netFD) destroy() {
} }
// Poller may want to unregister fd in readiness notification mechanism, // Poller may want to unregister fd in readiness notification mechanism,
// so this must be executed before closeFunc. // so this must be executed before closeFunc.
fd.pd.Close() fd.pd.close()
closeFunc(fd.sysfd) closeFunc(fd.sysfd)
fd.sysfd = syscall.InvalidHandle fd.sysfd = syscall.InvalidHandle
// no need for a finalizer anymore // no need for a finalizer anymore
...@@ -398,7 +398,7 @@ func (fd *netFD) destroy() { ...@@ -398,7 +398,7 @@ func (fd *netFD) destroy() {
// Add a reference to this fd. // Add a reference to this fd.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) incref() error { func (fd *netFD) incref() error {
if !fd.fdmu.Incref() { if !fd.fdmu.incref() {
return errClosing return errClosing
} }
return nil return nil
...@@ -407,7 +407,7 @@ func (fd *netFD) incref() error { ...@@ -407,7 +407,7 @@ func (fd *netFD) incref() error {
// Remove a reference to this FD and close if we've been asked to do so // Remove a reference to this FD and close if we've been asked to do so
// (and there are no references left). // (and there are no references left).
func (fd *netFD) decref() { func (fd *netFD) decref() {
if fd.fdmu.Decref() { if fd.fdmu.decref() {
fd.destroy() fd.destroy()
} }
} }
...@@ -415,7 +415,7 @@ func (fd *netFD) decref() { ...@@ -415,7 +415,7 @@ func (fd *netFD) decref() {
// Add a reference to this fd and lock for reading. // Add a reference to this fd and lock for reading.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) readLock() error { func (fd *netFD) readLock() error {
if !fd.fdmu.RWLock(true) { if !fd.fdmu.rwlock(true) {
return errClosing return errClosing
} }
return nil return nil
...@@ -423,7 +423,7 @@ func (fd *netFD) readLock() error { ...@@ -423,7 +423,7 @@ func (fd *netFD) readLock() error {
// Unlock for reading and remove a reference to this FD. // Unlock for reading and remove a reference to this FD.
func (fd *netFD) readUnlock() { func (fd *netFD) readUnlock() {
if fd.fdmu.RWUnlock(true) { if fd.fdmu.rwunlock(true) {
fd.destroy() fd.destroy()
} }
} }
...@@ -431,7 +431,7 @@ func (fd *netFD) readUnlock() { ...@@ -431,7 +431,7 @@ func (fd *netFD) readUnlock() {
// Add a reference to this fd and lock for writing. // Add a reference to this fd and lock for writing.
// Returns an error if the fd cannot be used. // Returns an error if the fd cannot be used.
func (fd *netFD) writeLock() error { func (fd *netFD) writeLock() error {
if !fd.fdmu.RWLock(false) { if !fd.fdmu.rwlock(false) {
return errClosing return errClosing
} }
return nil return nil
...@@ -439,17 +439,17 @@ func (fd *netFD) writeLock() error { ...@@ -439,17 +439,17 @@ func (fd *netFD) writeLock() error {
// Unlock for writing and remove a reference to this FD. // Unlock for writing and remove a reference to this FD.
func (fd *netFD) writeUnlock() { func (fd *netFD) writeUnlock() {
if fd.fdmu.RWUnlock(false) { if fd.fdmu.rwunlock(false) {
fd.destroy() fd.destroy()
} }
} }
func (fd *netFD) Close() error { func (fd *netFD) Close() error {
if !fd.fdmu.IncrefAndClose() { if !fd.fdmu.increfAndClose() {
return errClosing return errClosing
} }
// unblock pending reader and writer // unblock pending reader and writer
fd.pd.Evict() fd.pd.evict()
fd.decref() fd.decref()
return nil return nil
} }
......
...@@ -81,7 +81,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { ...@@ -81,7 +81,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
break break
} }
if err1 == syscall.EAGAIN { if err1 == syscall.EAGAIN {
if err1 = c.pd.WaitWrite(); err1 == nil { if err1 = c.pd.waitWrite(); err1 == nil {
continue continue
} }
} }
......
...@@ -81,7 +81,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { ...@@ -81,7 +81,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
break break
} }
if err1 == syscall.EAGAIN { if err1 == syscall.EAGAIN {
if err1 = c.pd.WaitWrite(); err1 == nil { if err1 = c.pd.waitWrite(); err1 == nil {
continue continue
} }
} }
......
...@@ -57,7 +57,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { ...@@ -57,7 +57,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
break break
} }
if err1 == syscall.EAGAIN { if err1 == syscall.EAGAIN {
if err1 = c.pd.WaitWrite(); err1 == nil { if err1 = c.pd.waitWrite(); err1 == nil {
continue continue
} }
} }
......
...@@ -87,7 +87,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) { ...@@ -87,7 +87,7 @@ func sendFile(c *netFD, r io.Reader) (written int64, err error, handled bool) {
break break
} }
if err1 == syscall.EAGAIN { if err1 == syscall.EAGAIN {
if err1 = c.pd.WaitWrite(); err1 == nil { if err1 = c.pd.waitWrite(); err1 == nil {
continue continue
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment