From 6c3a439455e5dd4c1d9c8088fe2d27596721c5e0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 18 Aug 2022 10:36:04 +0530 Subject: [PATCH] Use the io.Reader interface --- tools/cmd/at/main.go | 4 +++- tools/utils/io.go | 19 +++++++++++++++++++ tools/utils/sockets.go | 5 +++-- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tools/utils/io.go diff --git a/tools/cmd/at/main.go b/tools/cmd/at/main.go index 4658fc71a..a09244463 100644 --- a/tools/cmd/at/main.go +++ b/tools/cmd/at/main.go @@ -98,7 +98,9 @@ func send_rc_command(rc *utils.RemoteControlCmd, timeout float64) (err error) { if err != nil { return } - println(string(d)) + r := utils.BytesReader{Data: d} + + println(string(r.Data)) return } diff --git a/tools/utils/io.go b/tools/utils/io.go new file mode 100644 index 000000000..29bcc4311 --- /dev/null +++ b/tools/utils/io.go @@ -0,0 +1,19 @@ +package utils + +import ( + "io" +) + +type BytesReader struct { + Data []byte + Pos int64 +} + +func (self *BytesReader) Read(b []byte) (n int, err error) { + if self.Pos >= int64(len(self.Data)) { + return 0, io.EOF + } + n = copy(b, self.Data[self.Pos:]) + self.Pos += int64(n) + return +} diff --git a/tools/utils/sockets.go b/tools/utils/sockets.go index 245e9a2fd..c27bce5fd 100644 --- a/tools/utils/sockets.go +++ b/tools/utils/sockets.go @@ -2,9 +2,10 @@ package utils import ( "fmt" - "github.com/seancfoley/ipaddress-go/ipaddr" "runtime" "strings" + + "github.com/seancfoley/ipaddress-go/ipaddr" ) func Cut(s string, sep string) (string, string, bool) { @@ -21,7 +22,7 @@ func ParseSocketAddress(spec string) (network string, addr string, err error) { return } if network == "unix" { - if strings.HasSuffix(addr, "@") && runtime.GOOS != "linux" { + if strings.HasPrefix(addr, "@") && runtime.GOOS != "linux" { err = fmt.Errorf("Abstract UNIX sockets are only supported on Linux. Cannot use: %s", spec) } return