Skip to content

Commit

Permalink
added DeadlineHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
photostorm committed Oct 28, 2023
1 parent 7f5c495 commit e9c1f00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 4 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func Open() (Pty, Tty, error) {
// FdHolder surfaces the Fd() method of the underlying handle.
type FdHolder interface {
Fd() uintptr
}

// DeadlineHolder surfaces the SetDeadline() method to sets the read and write deadlines.
type DeadlineHolder interface {
SetDeadline(t time.Time) error
}

Expand Down
14 changes: 8 additions & 6 deletions io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ var mu sync.Mutex
func TestReadDeadline(t *testing.T) {
ptmx, success := prepare(t)

err := ptmx.SetDeadline(time.Now().Add(timeout / 10))
if err != nil {
if errors.Is(err, os.ErrNoDeadline) {
t.Skipf("deadline is not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
} else {
t.Fatalf("error: set deadline: %v\n", err)
if ptmxd, ok := ptmx.(DeadlineHolder); ok {
err := ptmxd.SetDeadline(time.Now().Add(timeout / 10))
if err != nil {
if errors.Is(err, os.ErrNoDeadline) {
t.Skipf("deadline is not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
} else {
t.Fatalf("error: set deadline: %v\n", err)
}
}
}

Expand Down

0 comments on commit e9c1f00

Please sign in to comment.