summaryrefslogtreecommitdiff
path: root/software/vendor/github.com/creack/goselect/select.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-30 16:00:32 +0200
committerxengineering <me@xengineering.eu>2024-05-30 16:00:32 +0200
commitb8ef4d11fe0d00ce0884ccf982675845b20c3ce9 (patch)
tree3beb57ff849ed74569ce325225bc819791c25a6a /software/vendor/github.com/creack/goselect/select.go
parenteab833271eeaa8d54991c11eccec9445f662a191 (diff)
downloadiot-core-b8ef4d11fe0d00ce0884ccf982675845b20c3ce9.tar
iot-core-b8ef4d11fe0d00ce0884ccf982675845b20c3ce9.tar.zst
iot-core-b8ef4d11fe0d00ce0884ccf982675845b20c3ce9.zip
software: Implement serial port detection
Diffstat (limited to 'software/vendor/github.com/creack/goselect/select.go')
-rw-r--r--software/vendor/github.com/creack/goselect/select.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/software/vendor/github.com/creack/goselect/select.go b/software/vendor/github.com/creack/goselect/select.go
new file mode 100644
index 0000000..7f2875e
--- /dev/null
+++ b/software/vendor/github.com/creack/goselect/select.go
@@ -0,0 +1,28 @@
+package goselect
+
+import (
+ "syscall"
+ "time"
+)
+
+// Select wraps syscall.Select with Go types
+func Select(n int, r, w, e *FDSet, timeout time.Duration) error {
+ var timeval *syscall.Timeval
+ if timeout >= 0 {
+ t := syscall.NsecToTimeval(timeout.Nanoseconds())
+ timeval = &t
+ }
+
+ return sysSelect(n, r, w, e, timeval)
+}
+
+// RetrySelect wraps syscall.Select with Go types, and retries a number of times, with a given retryDelay.
+func RetrySelect(n int, r, w, e *FDSet, timeout time.Duration, retries int, retryDelay time.Duration) (err error) {
+ for i := 0; i < retries; i++ {
+ if err = Select(n, r, w, e, timeout); err != syscall.EINTR {
+ return err
+ }
+ time.Sleep(retryDelay)
+ }
+ return err
+}