Movatterモバイル変換


[0]ホーム

URL:


poll

packagestandard library
go1.25.5Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License:BSD-3-ClauseImports:10Imported by:0

Details

Repository

cs.opensource.google/go/go

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

Constants

This section is empty.

Variables

Accept4Func is used to hook the accept4 call.

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 ErrDeadlineExceedederror = &DeadlineExceededError{}

ErrDeadlineExceeded is returned for an expired deadline.This is exported by the os package as os.ErrDeadlineExceeded.

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

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

View Source
var ErrNetClosing = errNetClosing{}

ErrNetClosing is returned when a network descriptor is used afterit has been closed.

View Source
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.

View Source
var ErrNotPollable =errors.New("not pollable")

ErrNotPollable is returned when the file or socket is not suitablefor event notification.

View Source
var TestHookDidSendFile = func(dstFD *FD, srcuintptr, writtenint64, errerror, handledbool) {}
View Source
var TestHookDidWritev = func(wroteint) {}

TestHookDidWritev is a hook for testing writev.

Functions

funcCopyFileRangeadded ingo1.15

func CopyFileRange(dst, src *FD, remainint64) (writtenint64, handledbool, errerror)

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.

funcDupCloseOnExecadded ingo1.11

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

DupCloseOnExec dups fd and marks it close-on-exec.

funcIsPollDescriptoradded ingo1.12

func IsPollDescriptor(fduintptr)bool

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

func SendFile(dstFD *FD, srcuintptr, sizeint64) (nint64, errerror, handledbool)

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.

funcSpliceadded ingo1.11

func Splice(dst, src *FD, remainint64) (writtenint64, handledbool, errerror)

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

typeDeadlineExceededErroradded ingo1.15

type DeadlineExceededError struct{}

DeadlineExceededError is returned for an expired deadline.

func (*DeadlineExceededError)Erroradded 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)Temporaryadded ingo1.15

func (e *DeadlineExceededError) Temporary()bool

func (*DeadlineExceededError)Timeoutadded 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)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 thedestroy method when there are no remaining references.

func (*FD)Dupadded ingo1.11

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

Dup duplicates the file descriptor.

func (*FD)Fchdir

func (fd *FD) Fchdir()error

Fchdir wraps syscall.Fchdir.

func (*FD)Fchmod

func (fd *FD) Fchmod(modeuint32)error

Fchmod wraps syscall.Fchmod.

func (*FD)Fchown

func (fd *FD) Fchown(uid, gidint)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(sizeint64)error

Ftruncate wraps syscall.Ftruncate.

func (*FD)GetsockoptIntadded ingo1.21.0

func (fd *FD) GetsockoptInt(level, nameint) (int,error)

GetsockoptInt wraps the getsockopt network call with an int argument.

func (*FD)Init

func (fd *FD) Init(netstring, pollablebool)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, offint64) (int,error)

Pread wraps the pread system call.

func (*FD)Pwrite

func (fd *FD) Pwrite(p []byte, offint64) (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-IOoperation.

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 callthat 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)ReadFromInet4added ingo1.18

func (fd *FD) ReadFromInet4(p []byte, from *syscall.SockaddrInet4) (int,error)

ReadFromInet4 wraps the recvfrom network call for IPv4.

func (*FD)ReadFromInet6added ingo1.18

func (fd *FD) ReadFromInet6(p []byte, from *syscall.SockaddrInet6) (int,error)

ReadFromInet6 wraps the recvfrom network call for IPv6.

func (*FD)ReadMsg

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

ReadMsg wraps the recvmsg network call.

func (*FD)ReadMsgInet4added 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)ReadMsgInet6added 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)Seek

func (fd *FD) Seek(offsetint64, whenceint) (int64,error)

Seek wraps syscall.Seek.

func (*FD)SetBlockingadded ingo1.10

func (fd *FD) SetBlocking()error

SetBlocking puts the file into blocking mode.

func (*FD)SetDeadline

func (fd *FD) SetDeadline(ttime.Time)error

SetDeadline sets the read and write deadlines associated with fd.

func (*FD)SetReadDeadline

func (fd *FD) SetReadDeadline(ttime.Time)error

SetReadDeadline sets the read deadline associated with fd.

func (*FD)SetWriteDeadline

func (fd *FD) SetWriteDeadline(ttime.Time)error

SetWriteDeadline sets the write deadline associated with fd.

func (*FD)SetsockoptByte

func (fd *FD) SetsockoptByte(level, nameint, argbyte)error

SetsockoptByte wraps the setsockopt network call with a byte argument.

func (*FD)SetsockoptIPMreq

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

SetsockoptIPMreq wraps the setsockopt network call with an IPMreq argument.

func (*FD)SetsockoptIPMreqn

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

SetsockoptIPMreqn wraps the setsockopt network call with an IPMreqn argument.

func (*FD)SetsockoptIPv6Mreq

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

SetsockoptIPv6Mreq wraps the setsockopt network call with an IPv6Mreq argument.

func (*FD)SetsockoptInet4Addr

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

SetsockoptInet4Addr wraps the setsockopt network call with an IPv4 address.

func (*FD)SetsockoptInt

func (fd *FD) SetsockoptInt(level, name, argint)error

SetsockoptInt wraps the setsockopt network call with an int argument.

func (*FD)SetsockoptLinger

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

SetsockoptLinger wraps the setsockopt network call with a Linger argument.

func (*FD)Shutdown

func (fd *FD) Shutdown(howint)error

Shutdown wraps syscall.Shutdown.

func (*FD)WaitWrite

func (fd *FD) WaitWrite()error

WaitWrite waits until data can be written to 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, sasyscall.Sockaddr) (int,int,error)

WriteMsg wraps the sendmsg network call.

func (*FD)WriteMsgInet4added ingo1.18

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

WriteMsgInet4 is WriteMsg specialized for syscall.SockaddrInet4.

func (*FD)WriteMsgInet6added ingo1.18

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

WriteMsgInet6 is WriteMsg specialized for syscall.SockaddrInet6.

func (*FD)WriteOnceadded ingo1.10

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, sasyscall.Sockaddr) (int,error)

WriteTo wraps the sendto network call.

func (*FD)WriteToInet4added ingo1.18

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

WriteToInet4 wraps the sendto network call for IPv4 addresses.

func (*FD)WriteToInet6added ingo1.18

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

WriteToInet6 wraps the sendto network call for IPv6 addresses.

func (*FD)Writev

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

Writev wraps the writev system call.

typeStringadded 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.

typeSysFileadded ingo1.21.0

type SysFile struct {// contains filtered or unexported fields}

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp