poll
packagestandard libraryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
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 theruntime scheduler.
Index¶
- Variables
- func CopyFileRange(dst, src *FD, remain int64) (written int64, handled bool, err error)
- func DupCloseOnExec(fd int) (int, string, error)
- func IsPollDescriptor(fd uintptr) bool
- func SendFile(dstFD *FD, src uintptr, size int64) (n int64, err error, handled bool)
- func Splice(dst, src *FD, remain int64) (written int64, handled bool, err error)
- type DeadlineExceededError
- type FD
- func (fd *FD) Accept() (int, syscall.Sockaddr, string, error)
- func (fd *FD) Close() error
- func (fd *FD) Dup() (int, string, 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) GetsockoptInt(level, name int) (int, 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) ReadFromInet4(p []byte, from *syscall.SockaddrInet4) (int, error)
- func (fd *FD) ReadFromInet6(p []byte, from *syscall.SockaddrInet6) (int, error)
- func (fd *FD) ReadMsg(p []byte, oob []byte, flags int) (int, int, int, syscall.Sockaddr, error)
- func (fd *FD) ReadMsgInet4(p []byte, oob []byte, flags int, sa4 *syscall.SockaddrInet4) (int, int, int, error)
- func (fd *FD) ReadMsgInet6(p []byte, oob []byte, flags int, sa6 *syscall.SockaddrInet6) (int, int, int, 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) WriteMsgInet4(p []byte, oob []byte, sa *syscall.SockaddrInet4) (int, int, error)
- func (fd *FD) WriteMsgInet6(p []byte, oob []byte, sa *syscall.SockaddrInet6) (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) WriteToInet4(p []byte, sa *syscall.SockaddrInet4) (int, error)
- func (fd *FD) WriteToInet6(p []byte, sa *syscall.SockaddrInet6) (int, error)
- func (fd *FD) Writev(v *[][]byte) (int64, error)
- type String
- type SysFile
Constants¶
This section is empty.
Variables¶
Accept4Func is used to hook the accept4 call.
AcceptFunc is used to hook the accept call.
var CloseFunc func(int)error =syscall.CloseCloseFunc is used to hook the close call.
var ErrDeadlineExceedederror = &DeadlineExceededError{}ErrDeadlineExceeded is returned for an expired deadline.This is exported by the os package as os.ErrDeadlineExceeded.
var ErrFileClosing =errors.New("use of closed file")ErrFileClosing is returned when a file descriptor is used after ithas been closed.
var ErrNetClosing = errNetClosing{}ErrNetClosing is returned when a network descriptor is used afterit has been closed.
var ErrNoDeadline =errors.New("file type does not support deadline")ErrNoDeadline is returned when a request is made to set a deadlineon a file type that does not use the poller.
var ErrNotPollable =errors.New("not pollable")ErrNotPollable is returned when the file or socket is not suitablefor event notification.
var TestHookDidSendFile = func(dstFD *FD, srcuintptr, writtenint64, errerror, handledbool) {}var TestHookDidWritev = func(wroteint) {}TestHookDidWritev is a hook for testing writev.
Functions¶
funcCopyFileRange¶added ingo1.15
CopyFileRange copies at most remain bytes of data from src to dst, usingthe copy_file_range system call. dst and src must refer to regular files.
funcDupCloseOnExec¶added ingo1.11
DupCloseOnExec dups fd and marks it close-on-exec.
funcIsPollDescriptor¶added ingo1.12
IsPollDescriptor reports whether fd is the descriptor being used by the poller.This is only used for testing.
IsPollDescriptor should be an internal detail,but widely used packages access it using linkname.Notable members of the hall of shame include:
- github.com/opencontainers/runc
Do not remove or change the type signature.See go.dev/issue/67401.
funcSendFile¶
SendFile wraps the sendfile system call.
It copies data from src (a file descriptor) to dstFD,starting at the current position of src.It updates the current position of src to after thecopied data.
If size is zero, it copies the rest of src.Otherwise, it copies up to size bytes.
The handled return parameter indicates whether SendFilewas able to handle some or all of the operation.If handled is false, sendfile was unable to perform the copy,has not modified the source or destination,and the caller should perform the copy using a fallback implementation.
funcSplice¶added ingo1.11
Splice transfers at most remain bytes of data from src to dst, using thesplice system call to minimize copies of data from and to userspace.
Splice gets a pipe buffer from the pool or creates a new one if needed, to serve as a buffer for the data transfer.src and dst must both be stream-oriented sockets.
Types¶
typeDeadlineExceededError¶added ingo1.15
type DeadlineExceededError struct{}DeadlineExceededError is returned for an expired deadline.
func (*DeadlineExceededError)Error¶added ingo1.15
func (e *DeadlineExceededError) Error()string
Implement the net.Error interface.The string is "i/o timeout" because that is what was returnedby earlier Go versions. Changing it may break programs thatmatch on error strings.
func (*DeadlineExceededError)Temporary¶added ingo1.15
func (e *DeadlineExceededError) Temporary()bool
func (*DeadlineExceededError)Timeout¶added ingo1.15
func (e *DeadlineExceededError) Timeout()bool
typeFD¶
type FD struct {// System file descriptor. Immutable until Close.Sysfdint// Platform dependent state of the file descriptor.SysFile// Whether this is a streaming descriptor, as opposed to a// packet-based descriptor like a UDP socket. Immutable.IsStreambool// Whether a zero byte read indicates EOF. This is false for a// message based socket connection.ZeroReadIsEOFbool// contains filtered or unexported fields}FD is a file descriptor. The net and os packages use this type as afield of a larger type representing a network connection or OS file.
func (*FD)Close¶
Close closes the FD. The underlying file descriptor is closed by thedestroy method when there are no remaining references.
func (*FD)GetsockoptInt¶added ingo1.21.0
GetsockoptInt wraps the getsockopt network call with an int argument.
func (*FD)Init¶
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)RawControl¶
RawControl invokes the user-defined function f for a non-IOoperation.
func (*FD)ReadDirent¶
ReadDirent wraps syscall.ReadDirent.We treat this like an ordinary system call rather than a callthat tries to fill the buffer.
func (*FD)ReadFromInet4¶added ingo1.18
ReadFromInet4 wraps the recvfrom network call for IPv4.
func (*FD)ReadFromInet6¶added ingo1.18
ReadFromInet6 wraps the recvfrom network call for IPv6.
func (*FD)ReadMsgInet4¶added ingo1.18
func (fd *FD) ReadMsgInet4(p []byte, oob []byte, flagsint, sa4 *syscall.SockaddrInet4) (int,int,int,error)
ReadMsgInet4 is ReadMsg, but specialized for syscall.SockaddrInet4.
func (*FD)ReadMsgInet6¶added ingo1.18
func (fd *FD) ReadMsgInet6(p []byte, oob []byte, flagsint, sa6 *syscall.SockaddrInet6) (int,int,int,error)
ReadMsgInet6 is ReadMsg, but specialized for syscall.SockaddrInet6.
func (*FD)SetBlocking¶added ingo1.10
SetBlocking puts the file into blocking mode.
func (*FD)SetDeadline¶
SetDeadline sets the read and write deadlines associated with fd.
func (*FD)SetReadDeadline¶
SetReadDeadline sets the read deadline associated with fd.
func (*FD)SetWriteDeadline¶
SetWriteDeadline sets the write deadline associated with fd.
func (*FD)SetsockoptByte¶
SetsockoptByte wraps the setsockopt network call with a byte argument.
func (*FD)SetsockoptIPMreq¶
SetsockoptIPMreq wraps the setsockopt network call with an IPMreq argument.
func (*FD)SetsockoptIPMreqn¶
SetsockoptIPMreqn wraps the setsockopt network call with an IPMreqn argument.
func (*FD)SetsockoptIPv6Mreq¶
SetsockoptIPv6Mreq wraps the setsockopt network call with an IPv6Mreq argument.
func (*FD)SetsockoptInet4Addr¶
SetsockoptInet4Addr wraps the setsockopt network call with an IPv4 address.
func (*FD)SetsockoptInt¶
SetsockoptInt wraps the setsockopt network call with an int argument.
func (*FD)SetsockoptLinger¶
SetsockoptLinger wraps the setsockopt network call with a Linger argument.
func (*FD)WriteMsgInet4¶added ingo1.18
WriteMsgInet4 is WriteMsg specialized for syscall.SockaddrInet4.
func (*FD)WriteMsgInet6¶added ingo1.18
WriteMsgInet6 is WriteMsg specialized for syscall.SockaddrInet6.
func (*FD)WriteToInet4¶added ingo1.18
WriteToInet4 wraps the sendto network call for IPv4 addresses.
func (*FD)WriteToInet6¶added ingo1.18
WriteToInet6 wraps the sendto network call for IPv6 addresses.
typeString¶added ingo1.22.0
type Stringstring
String is an internal string definition for methods/functionsthat is not intended for use outside the standard libraries.
Other packages in std that import internal/poll and have someexported APIs (now we've got some in net.rawConn) which are only usedinternally and are not intended to be used outside the standard libraries,Therefore, we make those APIs use internal types like poll.FD or poll.Stringin their function signatures to disable the usability of these APIs fromexternal codebase.
Source Files¶
- copy_file_range_linux.go
- copy_file_range_unix.go
- errno_unix.go
- fd.go
- fd_fsync_posix.go
- fd_mutex.go
- fd_poll_runtime.go
- fd_posix.go
- fd_unix.go
- fd_unixjs.go
- fd_writev_unix.go
- hook_cloexec.go
- hook_unix.go
- iovec_unix.go
- sendfile.go
- sendfile_unix.go
- sock_cloexec.go
- sockopt.go
- sockopt_linux.go
- sockopt_unix.go
- sockoptip.go
- splice_linux.go
- writev.go