Commit 38409f5f authored by Mikio Hara's avatar Mikio Hara

internal/poll: code cleanup

This change adds missing docs, collapses single-line import paths,
removes unsed method placeholders and renames str.go to strconv.go.

Change-Id: I2d155c838935cd8427abd142a462ff4c56829703
Reviewed-on: https://go-review.googlesource.com/37814
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 d50f892a
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
// runtime scheduler. // runtime scheduler.
package poll package poll
import ( import "errors"
"errors"
)
// ErrClosing is returned when a descriptor is used after it has been closed. // ErrClosing is returned when a descriptor is used after it has been closed.
var ErrClosing = errors.New("use of closed file or network connection") var ErrClosing = errors.New("use of closed file or network connection")
......
...@@ -90,14 +90,17 @@ func (fd *FD) Write(fn func([]byte) (int, error), b []byte) (int, error) { ...@@ -90,14 +90,17 @@ func (fd *FD) Write(fn func([]byte) (int, error), b []byte) (int, error) {
return n, err return n, err
} }
// SetDeadline sets the read and write deadlines associated with fd.
func (fd *FD) SetDeadline(t time.Time) error { func (fd *FD) SetDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r'+'w') return setDeadlineImpl(fd, t, 'r'+'w')
} }
// SetReadDeadline sets the read deadline associated with fd.
func (fd *FD) SetReadDeadline(t time.Time) error { func (fd *FD) SetReadDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r') return setDeadlineImpl(fd, t, 'r')
} }
// SetWriteDeadline sets the write deadline associated with fd.
func (fd *FD) SetWriteDeadline(t time.Time) error { func (fd *FD) SetWriteDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'w') return setDeadlineImpl(fd, t, 'w')
} }
...@@ -163,10 +166,12 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error { ...@@ -163,10 +166,12 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
// On Plan 9 only, expose the locking for the net code. // On Plan 9 only, expose the locking for the net code.
// ReadLock wraps FD.readLock.
func (fd *FD) ReadLock() error { func (fd *FD) ReadLock() error {
return fd.readLock() return fd.readLock()
} }
// ReadUnlock wraps FD.readUnlock.
func (fd *FD) ReadUnlock() { func (fd *FD) ReadUnlock() {
fd.readUnlock() fd.readUnlock()
} }
...@@ -179,6 +184,8 @@ func isInterrupted(err error) bool { ...@@ -179,6 +184,8 @@ func isInterrupted(err error) bool {
return err != nil && stringsHasSuffix(err.Error(), "interrupted") return err != nil && stringsHasSuffix(err.Error(), "interrupted")
} }
// PollDescriptor returns the descriptor being used by the poller,
// or ^uintptr(0) if there isn't one. This is only used for testing.
func PollDescriptor() uintptr { func PollDescriptor() uintptr {
return ^uintptr(0) return ^uintptr(0)
} }
...@@ -49,18 +49,17 @@ func (pd *pollDesc) waitWrite() error { return pd.wait('w') } ...@@ -49,18 +49,17 @@ 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() {} // SetDeadline sets the read and write deadlines associated with fd.
func (pd *pollDesc) waitCanceledWrite() {}
func (fd *FD) SetDeadline(t time.Time) error { func (fd *FD) SetDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r'+'w') return setDeadlineImpl(fd, t, 'r'+'w')
} }
// SetReadDeadline sets the read deadline associated with fd.
func (fd *FD) SetReadDeadline(t time.Time) error { func (fd *FD) SetReadDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r') return setDeadlineImpl(fd, t, 'r')
} }
// SetWriteDeadline sets the write deadline associated with fd.
func (fd *FD) SetWriteDeadline(t time.Time) error { func (fd *FD) SetWriteDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'w') return setDeadlineImpl(fd, t, 'w')
} }
...@@ -86,6 +85,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error { ...@@ -86,6 +85,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
return nil return nil
} }
// PollDescriptor returns the descriptor being used by the poller,
// or ^uintptr(0) if there isn't one. This is only used for testing.
func PollDescriptor() uintptr { func PollDescriptor() uintptr {
return ^uintptr(0) return ^uintptr(0)
} }
...@@ -114,14 +114,17 @@ func convertErr(res int) error { ...@@ -114,14 +114,17 @@ func convertErr(res int) error {
panic("unreachable") panic("unreachable")
} }
// SetDeadline sets the read and write deadlines associated with fd.
func (fd *FD) SetDeadline(t time.Time) error { func (fd *FD) SetDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r'+'w') return setDeadlineImpl(fd, t, 'r'+'w')
} }
// SetReadDeadline sets the read deadline associated with fd.
func (fd *FD) SetReadDeadline(t time.Time) error { func (fd *FD) SetReadDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r') return setDeadlineImpl(fd, t, 'r')
} }
// SetWriteDeadline sets the write deadline associated with fd.
func (fd *FD) SetWriteDeadline(t time.Time) error { func (fd *FD) SetWriteDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'w') return setDeadlineImpl(fd, t, 'w')
} }
......
...@@ -313,11 +313,6 @@ func (fd *FD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (int, int, err ...@@ -313,11 +313,6 @@ func (fd *FD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (int, int, err
} }
} }
// WaitWrite waits until data can be written to fd.
func (fd *FD) WaitWrite() error {
return fd.pd.waitWrite()
}
// Accept wraps the accept network call. // Accept wraps the accept network call.
func (fd *FD) Accept() (int, syscall.Sockaddr, string, error) { func (fd *FD) Accept() (int, syscall.Sockaddr, string, error) {
if err := fd.readLock(); err != nil { if err := fd.readLock(); err != nil {
...@@ -397,3 +392,10 @@ func (fd *FD) Fstat(s *syscall.Stat_t) error { ...@@ -397,3 +392,10 @@ func (fd *FD) Fstat(s *syscall.Stat_t) error {
defer fd.decref() defer fd.decref()
return syscall.Fstat(fd.Sysfd, s) return syscall.Fstat(fd.Sysfd, s)
} }
// On Unix variants only, expose the IO event for the net code.
// WaitWrite waits until data can be read from fd.
func (fd *FD) WaitWrite() error {
return fd.pd.waitWrite()
}
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
package poll package poll
import ( import "syscall"
"syscall"
)
// CloseFunc is used to hook the close call. // CloseFunc is used to hook the close call.
var CloseFunc func(int) error = syscall.Close var CloseFunc func(int) error = syscall.Close
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
package poll package poll
import ( import "syscall"
"syscall"
)
// CloseFunc is used to hook the close call. // CloseFunc is used to hook the close call.
var CloseFunc func(syscall.Handle) error = syscall.Closesocket var CloseFunc func(syscall.Handle) error = syscall.Closesocket
......
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
package poll package poll
import ( import "syscall"
"syscall"
)
// Wrapper around the accept system call that marks the returned file // Wrapper around the accept system call that marks the returned file
// descriptor as nonblocking and close-on-exec. // descriptor as nonblocking and close-on-exec.
......
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
package poll package poll
import ( import "syscall"
"syscall"
)
// SetsockoptInt wraps the setsockopt network call with an int argument. // SetsockoptInt wraps the setsockopt network call with an int argument.
func (fd *FD) SetsockoptInt(level, name, arg int) error { func (fd *FD) SetsockoptInt(level, name, arg int) error {
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
package poll package poll
import ( import "syscall"
"syscall"
)
// SetsockoptIPMreqn wraps the setsockopt network call with a IPMreqn argument. // SetsockoptIPMreqn wraps the setsockopt network call with a IPMreqn argument.
func (fd *FD) SetsockoptIPMreqn(level, name int, mreq *syscall.IPMreqn) error { func (fd *FD) SetsockoptIPMreqn(level, name int, mreq *syscall.IPMreqn) error {
......
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
package poll package poll
import ( import "syscall"
"syscall"
)
// Setsockopt wraps the Windows setsockopt network call. // Setsockopt wraps the Windows setsockopt network call.
func (fd *FD) Setsockopt(level, optname int32, optval *byte, optlen int32) error { func (fd *FD) Setsockopt(level, optname int32, optval *byte, optlen int32) error {
......
// +build plan9
// Copyright 2009 The Go Authors. All rights reserved. // Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// +build plan9
// Simple conversions to avoid depending on strconv. // Simple conversions to avoid depending on strconv.
package poll package poll
......
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