Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os/File: add stubs for os.File Deadlines #4465

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/os/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,29 @@ func (f *File) SyscallConn() (conn syscall.RawConn, err error) {
return
}

// SetDeadline sets the read and write deadlines for a File.
// Calls to SetDeadline for files that do not support deadlines will return ErrNoDeadline
// This stub always returns ErrNoDeadline.
// A zero value for t means I/O operations will not time out.
func (f *File) SetDeadline(t time.Time) error {
if f.handle == nil {
return ErrClosed
}
return f.setDeadline(t)
}

// SetReadDeadline sets the deadline for future Read calls and any
// currently-blocked Read call.
func (f *File) SetReadDeadline(t time.Time) error {
return f.setReadDeadline(t)
}

// SetWriteDeadline sets the deadline for any future Write calls and any
// currently-blocked Write call.
func (f *File) SetWriteDeadline(t time.Time) error {
return f.setWriteDeadline(t)
}

// fd is an internal interface that is used to try a type assertion in order to
// call the Fd() method of the underlying file handle if it is implemented.
type fd interface {
Expand Down
23 changes: 22 additions & 1 deletion src/os/file_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ func Chtimes(name string, atime time.Time, mtime time.Time) error {
return ErrNotImplemented
}

// setDeadline sets the read and write deadline.
func (f *File) setDeadline(t time.Time) error {
if t.IsZero() {
return nil
}
return ErrNotImplemented
}

// setReadDeadline sets the read deadline, not yet implemented
func (f *File) setReadDeadline(_ time.Time) error {
// A zero value for t means Read will not time out.
func (f *File) setReadDeadline(t time.Time) error {
if t.IsZero() {
return nil
}
return ErrNotImplemented
}

// setWriteDeadline sets the write deadline, not yet implemented
// A zero value for t means Read will not time out.
func (f *File) setWriteDeadline(t time.Time) error {
if t.IsZero() {
return nil
}
return ErrNotImplemented
}
Loading