diff --git a/device/uapi.go b/device/uapi.go index 2843a4c..370ad4e 100644 --- a/device/uapi.go +++ b/device/uapi.go @@ -7,7 +7,6 @@ package device import ( "bufio" - "bytes" "errors" "fmt" "io" @@ -33,7 +32,7 @@ func (s IPCError) ErrorCode() int64 { return s.int64 } -func (device *Device) IpcGetOperation(w io.StringWriter) error { +func (device *Device) IpcGetOperation(w io.Writer) error { lines := make([]string, 0, 100) send := func(line string) { lines = append(lines, line) @@ -99,7 +98,7 @@ func (device *Device) IpcGetOperation(w io.StringWriter) error { // send lines (does not require resource locks) for _, line := range lines { - _, err := w.WriteString(line + "\n") + _, err := io.WriteString(w, line+"\n") if err != nil { return &IPCError{ipc.IpcErrorIO} } @@ -397,22 +396,16 @@ func (device *Device) IpcSetOperation(r io.Reader) error { return nil } - - func (device *Device) IpcGet() (string, error) { - buf := new(bytes.Buffer) - writer := bufio.NewWriter(buf) - if err := device.IpcGetOperation(writer); err != nil { - return "", err - } - if err := writer.Flush(); err != nil { + buf := new(strings.Builder) + if err := device.IpcGetOperation(buf); err != nil { return "", err } return buf.String(), nil } func (device *Device) IpcSet(uapiConf string) error { - return device.IpcSetOperation(bufio.NewReader(strings.NewReader(uapiConf))) + return device.IpcSetOperation(strings.NewReader(uapiConf)) } func (device *Device) IpcHandle(socket net.Conn) {