...
Run Format

Package poll

import "internal/poll"
Overview
Index

Overview ▾

Package poll supports non-blocking I/O on file descriptors with polling. This supports I/O operations that block only a goroutine, not a thread. This is used by the net and os packages. It uses a poller built into the runtime, with support from the runtime scheduler.

Index ▾

Variables
func PollDescriptor() uintptr
func SendFile(dstFD *FD, src int, remain int64) (int64, error)
type FD
    func (fd *FD) Accept() (int, syscall.Sockaddr, string, error)
    func (fd *FD) Close() error
    func (fd *FD) Fchdir() error
    func (fd *FD) Fchmod(mode uint32) error
    func (fd *FD) Fchown(uid, gid int) error
    func (fd *FD) Fstat(s *syscall.Stat_t) error
    func (fd *FD) Fsync() error
    func (fd *FD) Ftruncate(size int64) error
    func (fd *FD) Init(net string, pollable bool) error
    func (fd *FD) Pread(p []byte, off int64) (int, error)
    func (fd *FD) Pwrite(p []byte, off int64) (int, error)
    func (fd *FD) RawControl(f func(uintptr)) error
    func (fd *FD) RawRead(f func(uintptr) bool) error
    func (fd *FD) RawWrite(f func(uintptr) bool) error
    func (fd *FD) Read(p []byte) (int, error)
    func (fd *FD) ReadDirent(buf []byte) (int, error)
    func (fd *FD) ReadFrom(p []byte) (int, syscall.Sockaddr, error)
    func (fd *FD) ReadMsg(p []byte, oob []byte) (int, int, int, syscall.Sockaddr, error)
    func (fd *FD) Seek(offset int64, whence int) (int64, error)
    func (fd *FD) SetBlocking() error
    func (fd *FD) SetDeadline(t time.Time) error
    func (fd *FD) SetReadDeadline(t time.Time) error
    func (fd *FD) SetWriteDeadline(t time.Time) error
    func (fd *FD) SetsockoptByte(level, name int, arg byte) error
    func (fd *FD) SetsockoptIPMreq(level, name int, mreq *syscall.IPMreq) error
    func (fd *FD) SetsockoptIPMreqn(level, name int, mreq *syscall.IPMreqn) error
    func (fd *FD) SetsockoptIPv6Mreq(level, name int, mreq *syscall.IPv6Mreq) error
    func (fd *FD) SetsockoptInet4Addr(level, name int, arg [4]byte) error
    func (fd *FD) SetsockoptInt(level, name, arg int) error
    func (fd *FD) SetsockoptLinger(level, name int, l *syscall.Linger) error
    func (fd *FD) Shutdown(how int) error
    func (fd *FD) WaitWrite() error
    func (fd *FD) Write(p []byte) (int, error)
    func (fd *FD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (int, int, error)
    func (fd *FD) WriteOnce(p []byte) (int, error)
    func (fd *FD) WriteTo(p []byte, sa syscall.Sockaddr) (int, error)
    func (fd *FD) Writev(v *[][]byte) (int64, error)
type TimeoutError
    func (e *TimeoutError) Error() string
    func (e *TimeoutError) Temporary() bool
    func (e *TimeoutError) Timeout() bool

Package files

fd.go fd_mutex.go fd_poll_runtime.go fd_posix.go fd_unix.go hook_cloexec.go hook_unix.go sendfile_linux.go sock_cloexec.go sockopt.go sockopt_linux.go sockopt_unix.go sockoptip.go writev.go

Variables

Accept4Func is used to hook the accept4 call.

var Accept4Func func(int, int) (int, syscall.Sockaddr, error) = syscall.Accept4

AcceptFunc is used to hook the accept call.

var AcceptFunc func(int) (int, syscall.Sockaddr, error) = syscall.Accept

CloseFunc is used to hook the close call.

var CloseFunc func(int) error = syscall.Close

ErrFileClosing is returned when a file descriptor is used after it has been closed.

var ErrFileClosing = errors.New("use of closed file")

ErrNetClosing is returned when a network descriptor is used after it has been closed. Keep this string consistent because of issue #4373: since historically programs have not been able to detect this error, they look for the string.

var ErrNetClosing = errors.New("use of closed network connection")

ErrNoDeadline is returned when a request is made to set a deadline on a file type that does not use the poller.

var ErrNoDeadline = errors.New("file type does not support deadline")

ErrTimeout is returned for an expired deadline.

var ErrTimeout error = &TimeoutError{}

TestHookDidWritev is a hook for testing writev.

var TestHookDidWritev = func(wrote int) {}

func PollDescriptor

func PollDescriptor() uintptr

PollDescriptor returns the descriptor being used by the poller, or ^uintptr(0) if there isn't one. This is only used for testing.

func SendFile

func SendFile(dstFD *FD, src int, remain int64) (int64, error)

SendFile wraps the sendfile system call.

type FD

FD is a file descriptor. The net and os packages use this type as a field of a larger type representing a network connection or OS file.

type FD struct {

        // System file descriptor. Immutable until Close.
        Sysfd int

        // Whether this is a streaming descriptor, as opposed to a
        // packet-based descriptor like a UDP socket. Immutable.
        IsStream bool

        // Whether a zero byte read indicates EOF. This is false for a
        // message based socket connection.
        ZeroReadIsEOF bool
        // contains filtered or unexported fields
}

func (*FD) Accept

func (fd *FD) Accept() (int, syscall.Sockaddr, string, error)

Accept wraps the accept network call.

func (*FD) Close

func (fd *FD) Close() error

Close closes the FD. The underlying file descriptor is closed by the destroy method when there are no remaining references.

func (*FD) Fchdir

func (fd *FD) Fchdir() error

Fchdir wraps syscall.Fchdir.

func (*FD) Fchmod

func (fd *FD) Fchmod(mode uint32) error

Fchmod wraps syscall.Fchmod.

func (*FD) Fchown

func (fd *FD) Fchown(uid, gid int) error

Fchown wraps syscall.Fchown.

func (*FD) Fstat

func (fd *FD) Fstat(s *syscall.Stat_t) error

Fstat wraps syscall.Fstat

func (*FD) Fsync

func (fd *FD) Fsync() error

Fsync wraps syscall.Fsync.

func (*FD) Ftruncate

func (fd *FD) Ftruncate(size int64) error

Ftruncate wraps syscall.Ftruncate.

func (*FD) Init

func (fd *FD) Init(net string, pollable bool) error

Init initializes the FD. The Sysfd field should already be set. This can be called multiple times on a single FD. The net argument is a network name from the net package (e.g., "tcp"), or "file". Set pollable to true if fd should be managed by runtime netpoll.

func (*FD) Pread

func (fd *FD) Pread(p []byte, off int64) (int, error)

Pread wraps the pread system call.

func (*FD) Pwrite

func (fd *FD) Pwrite(p []byte, off int64) (int, error)

Pwrite wraps the pwrite system call.

func (*FD) RawControl

func (fd *FD) RawControl(f func(uintptr)) error

RawControl invokes the user-defined function f for a non-IO operation.

func (*FD) RawRead

func (fd *FD) RawRead(f func(uintptr) bool) error

RawRead invokes the user-defined function f for a read operation.

func (*FD) RawWrite

func (fd *FD) RawWrite(f func(uintptr) bool) error

RawWrite invokes the user-defined function f for a write operation.

func (*FD) Read

func (fd *FD) Read(p []byte) (int, error)

Read implements io.Reader.

func (*FD) ReadDirent

func (fd *FD) ReadDirent(buf []byte) (int, error)

ReadDirent wraps syscall.ReadDirent. We treat this like an ordinary system call rather than a call that tries to fill the buffer.

func (*FD) ReadFrom

func (fd *FD) ReadFrom(p []byte) (int, syscall.Sockaddr, error)

ReadFrom wraps the recvfrom network call.

func (*FD) ReadMsg

func (fd *FD) ReadMsg(p []byte, oob []byte) (int, int, int, syscall.Sockaddr, error)

ReadMsg wraps the recvmsg network call.

func (*FD) Seek

func (fd *FD) Seek(offset int64, whence int) (int64, error)

Seek wraps syscall.Seek.

func (*FD) SetBlocking

func (fd *FD) SetBlocking() error

SetBlocking puts the file into blocking mode.

func (*FD) SetDeadline

func (fd *FD) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with fd.

func (*FD) SetReadDeadline

func (fd *FD) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline associated with fd.

func (*FD) SetWriteDeadline

func (fd *FD) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the write deadline associated with fd.

func (*FD) SetsockoptByte

func (fd *FD) SetsockoptByte(level, name int, arg byte) error

SetsockoptByte wraps the setsockopt network call with a byte argument.

func (*FD) SetsockoptIPMreq

func (fd *FD) SetsockoptIPMreq(level, name int, mreq *syscall.IPMreq) error

SetsockoptIPMreq wraps the setsockopt network call with an IPMreq argument.

func (*FD) SetsockoptIPMreqn

func (fd *FD) SetsockoptIPMreqn(level, name int, mreq *syscall.IPMreqn) error

SetsockoptIPMreqn wraps the setsockopt network call with an IPMreqn argument.

func (*FD) SetsockoptIPv6Mreq

func (fd *FD) SetsockoptIPv6Mreq(level, name int, mreq *syscall.IPv6Mreq) error

SetsockoptIPv6Mreq wraps the setsockopt network call with an IPv6Mreq argument.

func (*FD) SetsockoptInet4Addr

func (fd *FD) SetsockoptInet4Addr(level, name int, arg [4]byte) error

SetsockoptInet4Addr wraps the setsockopt network call with an IPv4 address.

func (*FD) SetsockoptInt

func (fd *FD) SetsockoptInt(level, name, arg int) error

SetsockoptInt wraps the setsockopt network call with an int argument.

func (*FD) SetsockoptLinger

func (fd *FD) SetsockoptLinger(level, name int, l *syscall.Linger) error

SetsockoptLinger wraps the setsockopt network call with a Linger argument.

func (*FD) Shutdown

func (fd *FD) Shutdown(how int) error

Shutdown wraps the shutdown network call.

func (*FD) WaitWrite

func (fd *FD) WaitWrite() error

WaitWrite waits until data can be read from fd.

func (*FD) Write

func (fd *FD) Write(p []byte) (int, error)

Write implements io.Writer.

func (*FD) WriteMsg

func (fd *FD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (int, int, error)

WriteMsg wraps the sendmsg network call.

func (*FD) WriteOnce

func (fd *FD) WriteOnce(p []byte) (int, error)

WriteOnce is for testing only. It makes a single write call.

func (*FD) WriteTo

func (fd *FD) WriteTo(p []byte, sa syscall.Sockaddr) (int, error)

WriteTo wraps the sendto network call.

func (*FD) Writev

func (fd *FD) Writev(v *[][]byte) (int64, error)

Writev wraps the writev system call.

type TimeoutError

TimeoutError is returned for an expired deadline.

type TimeoutError struct{}

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

Implement the net.Error interface.

func (*TimeoutError) Temporary

func (e *TimeoutError) Temporary() bool

func (*TimeoutError) Timeout

func (e *TimeoutError) Timeout() bool