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 @@
// runtime scheduler.
package poll
import (
"errors"
)
import "errors"
// ErrClosing is returned when a descriptor is used after it has been closed.
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) {
return n, err
}
// SetDeadline sets the read and write deadlines associated with fd.
func (fd *FD) SetDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r'+'w')
}
// SetReadDeadline sets the read deadline associated with fd.
func (fd *FD) SetReadDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r')
}
// SetWriteDeadline sets the write deadline associated with fd.
func (fd *FD) SetWriteDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'w')
}
......@@ -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.
// ReadLock wraps FD.readLock.
func (fd *FD) ReadLock() error {
return fd.readLock()
}
// ReadUnlock wraps FD.readUnlock.
func (fd *FD) ReadUnlock() {
fd.readUnlock()
}
......@@ -179,6 +184,8 @@ func isInterrupted(err error) bool {
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 {
return ^uintptr(0)
}
......@@ -49,18 +49,17 @@ func (pd *pollDesc) waitWrite() error { return pd.wait('w') }
func (pd *pollDesc) waitCanceled(mode int) {}
func (pd *pollDesc) waitCanceledRead() {}
func (pd *pollDesc) waitCanceledWrite() {}
// SetDeadline sets the read and write deadlines associated with fd.
func (fd *FD) SetDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r'+'w')
}
// SetReadDeadline sets the read deadline associated with fd.
func (fd *FD) SetReadDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r')
}
// SetWriteDeadline sets the write deadline associated with fd.
func (fd *FD) SetWriteDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'w')
}
......@@ -86,6 +85,8 @@ func setDeadlineImpl(fd *FD, t time.Time, mode int) error {
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 {
return ^uintptr(0)
}
......@@ -114,14 +114,17 @@ func convertErr(res int) error {
panic("unreachable")
}
// SetDeadline sets the read and write deadlines associated with fd.
func (fd *FD) SetDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r'+'w')
}
// SetReadDeadline sets the read deadline associated with fd.
func (fd *FD) SetReadDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'r')
}
// SetWriteDeadline sets the write deadline associated with fd.
func (fd *FD) SetWriteDeadline(t time.Time) error {
return setDeadlineImpl(fd, t, 'w')
}
......
......@@ -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.
func (fd *FD) Accept() (int, syscall.Sockaddr, string, error) {
if err := fd.readLock(); err != nil {
......@@ -397,3 +392,10 @@ func (fd *FD) Fstat(s *syscall.Stat_t) error {
defer fd.decref()
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 @@
package poll
import (
"syscall"
)
import "syscall"
// CloseFunc is used to hook the close call.
var CloseFunc func(int) error = syscall.Close
......
......@@ -4,9 +4,7 @@
package poll
import (
"syscall"
)
import "syscall"
// CloseFunc is used to hook the close call.
var CloseFunc func(syscall.Handle) error = syscall.Closesocket
......
......@@ -9,9 +9,7 @@
package poll
import (
"syscall"
)
import "syscall"
// Wrapper around the accept system call that marks the returned file
// descriptor as nonblocking and close-on-exec.
......
......@@ -6,9 +6,7 @@
package poll
import (
"syscall"
)
import "syscall"
// SetsockoptInt wraps the setsockopt network call with an int argument.
func (fd *FD) SetsockoptInt(level, name, arg int) error {
......
......@@ -4,9 +4,7 @@
package poll
import (
"syscall"
)
import "syscall"
// SetsockoptIPMreqn wraps the setsockopt network call with a IPMreqn argument.
func (fd *FD) SetsockoptIPMreqn(level, name int, mreq *syscall.IPMreqn) error {
......
......@@ -4,9 +4,7 @@
package poll
import (
"syscall"
)
import "syscall"
// Setsockopt wraps the Windows setsockopt network call.
func (fd *FD) Setsockopt(level, optname int32, optval *byte, optlen int32) error {
......
// +build plan9
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build plan9
// Simple conversions to avoid depending on strconv.
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