time.go 758 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (c) 2022 Tailscale Inc & AUTHORS. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build windows
  5. package wingoes
  6. import (
  7. "errors"
  8. "time"
  9. "golang.org/x/sys/windows"
  10. )
  11. var (
  12. // ErrDurationOutOfRange means that a time.Duration is too large to be able
  13. // to be specified as a valid Win32 timeout value.
  14. ErrDurationOutOfRange = errors.New("duration is out of timeout range")
  15. )
  16. // DurationToTimeoutMilliseconds converts d into a timeout usable by Win32 APIs.
  17. func DurationToTimeoutMilliseconds(d time.Duration) (uint32, error) {
  18. millis := d.Milliseconds()
  19. if millis >= windows.INFINITE {
  20. return 0, ErrDurationOutOfRange
  21. }
  22. return uint32(millis), nil
  23. }