device: allow pipelining UAPI requests

The original spec ends with \n\n especially for this reason.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2021-01-25 19:00:43 +01:00
parent a29767dda6
commit 18e47795e5

View file

@ -380,9 +380,6 @@ func (device *Device) IpcSet(uapiConf string) error {
} }
func (device *Device) IpcHandle(socket net.Conn) { func (device *Device) IpcHandle(socket net.Conn) {
// create buffered read/writer
defer socket.Close() defer socket.Close()
buffered := func(s io.ReadWriter) *bufio.ReadWriter { buffered := func(s io.ReadWriter) *bufio.ReadWriter {
@ -391,8 +388,7 @@ func (device *Device) IpcHandle(socket net.Conn) {
return bufio.NewReadWriter(reader, writer) return bufio.NewReadWriter(reader, writer)
}(socket) }(socket)
defer buffered.Flush() for {
op, err := buffered.ReadString('\n') op, err := buffered.ReadString('\n')
if err != nil { if err != nil {
return return
@ -403,6 +399,14 @@ func (device *Device) IpcHandle(socket net.Conn) {
case "set=1\n": case "set=1\n":
err = device.IpcSetOperation(buffered.Reader) err = device.IpcSetOperation(buffered.Reader)
case "get=1\n": case "get=1\n":
nextByte, err := buffered.ReadByte()
if err != nil {
return
}
if nextByte != '\n' {
err = ipcErrorf(ipc.IpcErrorInvalid, "trailing character in UAPI get: %c", nextByte, err)
break
}
err = device.IpcGetOperation(buffered.Writer) err = device.IpcGetOperation(buffered.Writer)
default: default:
device.log.Error.Println("invalid UAPI operation:", op) device.log.Error.Println("invalid UAPI operation:", op)
@ -421,4 +425,6 @@ func (device *Device) IpcHandle(socket net.Conn) {
} else { } else {
fmt.Fprintf(buffered, "errno=0\n\n") fmt.Fprintf(buffered, "errno=0\n\n")
} }
buffered.Flush()
}
} }