poll

package
v0.0.0-...-9ea5951 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2020 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

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

Constants

This section is empty.

Variables

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

Accept4Func is used to hook the accept4 call.

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

AcceptFunc is used to hook the accept call.

View Source
var CloseFunc func(int) error = syscall.Close

CloseFunc is used to hook the close call.

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

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

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

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.

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

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

View Source
var ErrTimeout error = &TimeoutError{}

ErrTimeout is returned for an expired deadline.

View Source
var TestHookDidWritev = func(wrote int) {}

TestHookDidWritev is a hook for testing writev.

Functions

func DupCloseOnExec

func DupCloseOnExec(fd int) (int, string, error)

DupCloseOnExec dups fd and marks it close-on-exec. DupCloseOnExec 创建 fd 副本 , 并且设置 CLOEXEC 标志

func IsPollDescriptor

func IsPollDescriptor(fd uintptr) bool

IsPollDescriptor reports whether fd is the descriptor being used by the poller. This is only used for testing. IsPollDescriptor 判读 fd 是否是轮询器正在使用的文件描述符。这仅用于测试。

func SendFile

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

SendFile wraps the sendfile system call.

func Splice

func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string, err error)

Splice transfers at most remain bytes of data from src to dst, using the splice system call to minimize copies of data from and to userspace.

Splice creates a temporary pipe, to serve as a buffer for the data transfer. src and dst must both be stream-oriented sockets.

If err != nil, sc is the system call which caused the error.

Splice 尽可能多的从 src 到 dst 拷贝数据,使用 splice 系统调用减少来回用户空间的数据拷贝。 Splice 创建一个临时管道,用作数据传输的缓冲区。 src 和 dst 都必须是面向流的套接字 如果 err!= nil,则 sc 是导致错误的系统调用。

Types

type FD

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 // 读取到 0 是否表示是 EOF
	// contains filtered or unexported fields
}

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. FD 是文件描述符。 net 和 os 包中大量的类型将此 FD 用作表示网络连接或 OS 文件的字段。

func (*FD) Accept

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

Accept wraps the accept network call. ReadFrom 包装 accept 网络调用

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. Close 关闭 FD , 没有引用时候调用 destroy 函数关闭文件描述符

func (*FD) Dup

func (fd *FD) Dup() (int, string, error)

Dup duplicates the file descriptor. Dup 创建 fd 副本 ,已经设置了 O_CLOEXEC 标志

func (*FD) Fchdir

func (fd *FD) Fchdir() error

Fchdir wraps syscall.Fchdir. ReadFrom 包装 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 ReadFrom 包装 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. Init 初始化 FD 。Sysfd 字段应该已经设置。 可以在单个 FD 上多次调用此命令。 net 参数是网络包中的网络名称(例如 "tcp")或 "file"。 如果 pollable 为 true ,则将 fd 交给运行时 netpoll 管理。

func (*FD) Pread

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

Pread wraps the pread system call. Pread 包装 pread 系统调用,用于带偏移量地原子的从文件中读取数据,执行后,文件偏移指针不变。

func (*FD) Pwrite

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

Pwrite wraps the pwrite system call. Pwrite 包装 pwrite 系统调用,用于带偏移量地原子的从文件中读取数据,执行后,文件偏移指针不变。多个线程同时写,可能存在覆盖问题。

func (*FD) RawControl

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

RawControl invokes the user-defined function f for a non-IO operation. RawControl 为非 IO 操作调用用户定义的函数 f 。

func (*FD) RawRead

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

RawRead invokes the user-defined function f for a read operation. RawRead 调用用户定义的函数 f 进行读取操作。

func (*FD) RawWrite

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

RawWrite invokes the user-defined function f for a write operation. RawWrite 调用用户定义的函数 f 进行写入操作。

func (*FD) Read

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

Read implements io.Reader. Read 实现 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. ReadFrom 包装 syscall.ReadDirent ,最终调用 getdents64 系统调用 读取目录结构,获取到的 buf 需要解析 ,解析过程可以参考 syscall.ParseDirent

func (*FD) ReadFrom

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

ReadFrom wraps the recvfrom network call. ReadFrom 包装 recvfrom 网络调用

func (*FD) ReadMsg

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

ReadMsg wraps the recvmsg network call. ReadFrom 包装 recvmsg 网络调用

func (*FD) Seek

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

Seek wraps syscall.Seek. Seek 包装 seek 系统调用

func (*FD) SetBlocking

func (fd *FD) SetBlocking() error

SetBlocking puts the file into blocking mode. SetBlocking 设置为阻塞模式

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. Shutdown shutdown 系统调用

func (*FD) WaitWrite

func (fd *FD) WaitWrite() error

WaitWrite waits until data can be read from fd. WaitWrite 等待读

func (*FD) Write

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

Write implements io.Writer. Write 实现 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. WriteMsg 包装 sendmsg 网络调用

func (*FD) WriteOnce

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

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

func (*FD) WriteTo

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

WriteTo wraps the sendto network call. WriteTo 包装 sendto 网络调用

func (*FD) Writev

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

Writev wraps the writev system call.

type TimeoutError

type TimeoutError struct{}

TimeoutError is returned for an expired deadline.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL