-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
50 lines (38 loc) · 825 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package lpd
import (
"errors"
"io"
"strings"
)
func SendCommandLine(w io.Writer, cmd byte, opts []string) (err error) {
var line []byte
line = append(line, cmd)
optString := strings.Join(opts, Separator)
line = append(line, []byte(optString)...)
line = append(line, []byte(LineEnding)...)
_, err = w.Write(line)
return
}
func CheckAcknowledge(r io.Reader) error {
buf := make([]byte, 1)
if _, err := r.Read(buf); err != nil {
return err
}
if buf[0] != Acknowledge {
return errors.New("server not acknowledged the command")
}
return nil
}
func SendAbortOnError(w io.Writer, err error) error {
if err != nil {
_, inErr := w.Write([]byte{byte(AbortJob)})
if inErr != nil {
return inErr
}
_, inErr = w.Write([]byte(LineEnding))
if inErr != nil {
return inErr
}
}
return nil
}