processIncomingStream is called once we've successfully sent a request to libvirt. It writes the responses back to the stream passed by the caller until libvirt sends a packet with statusOK or an error.
(c chan response, inStream io.Writer)
| 319 | // libvirt. It writes the responses back to the stream passed by the caller |
| 320 | // until libvirt sends a packet with statusOK or an error. |
| 321 | func (l *Libvirt) processIncomingStream(c chan response, inStream io.Writer) (response, error) { |
| 322 | for { |
| 323 | resp, err := l.getResponse(c) |
| 324 | if err != nil { |
| 325 | return resp, err |
| 326 | } |
| 327 | |
| 328 | // StatusOK indicates end of stream |
| 329 | if resp.Status == socket.StatusOK { |
| 330 | return resp, nil |
| 331 | } |
| 332 | |
| 333 | // FIXME: this smells. |
| 334 | // StatusError is handled in getResponse, so this must be StatusContinue |
| 335 | // StatusContinue is only valid here for stream packets |
| 336 | // libvirtd breaks protocol and returns StatusContinue with an |
| 337 | // empty response Payload when the stream finishes |
| 338 | if len(resp.Payload) == 0 { |
| 339 | return resp, nil |
| 340 | } |
| 341 | if inStream != nil { |
| 342 | _, err = inStream.Write(resp.Payload) |
| 343 | if err != nil { |
| 344 | return response{}, err |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | func (l *Libvirt) getResponse(c chan response) (response, error) { |
| 351 | resp, ok := <-c |
no test coverage detected