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:
parent
a29767dda6
commit
18e47795e5
|
@ -380,9 +380,6 @@ func (device *Device) IpcSet(uapiConf string) error {
|
|||
}
|
||||
|
||||
func (device *Device) IpcHandle(socket net.Conn) {
|
||||
|
||||
// create buffered read/writer
|
||||
|
||||
defer socket.Close()
|
||||
|
||||
buffered := func(s io.ReadWriter) *bufio.ReadWriter {
|
||||
|
@ -391,8 +388,7 @@ func (device *Device) IpcHandle(socket net.Conn) {
|
|||
return bufio.NewReadWriter(reader, writer)
|
||||
}(socket)
|
||||
|
||||
defer buffered.Flush()
|
||||
|
||||
for {
|
||||
op, err := buffered.ReadString('\n')
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -403,6 +399,14 @@ func (device *Device) IpcHandle(socket net.Conn) {
|
|||
case "set=1\n":
|
||||
err = device.IpcSetOperation(buffered.Reader)
|
||||
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)
|
||||
default:
|
||||
device.log.Error.Println("invalid UAPI operation:", op)
|
||||
|
@ -421,4 +425,6 @@ func (device *Device) IpcHandle(socket net.Conn) {
|
|||
} else {
|
||||
fmt.Fprintf(buffered, "errno=0\n\n")
|
||||
}
|
||||
buffered.Flush()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue