MCPcopy Create free account
hub / github.com/digitalocean/go-libvirt / SendStream

Method SendStream

socket/socket.go:347–376  ·  view source on GitHub ↗

SendStream sends a stream of packets to libvirt on the socket connection.

(serial int32, proc uint32, program uint32,
	stream io.Reader, abort chan bool)

Source from the content-addressed store, hash-verified

345
346// SendStream sends a stream of packets to libvirt on the socket connection.
347func (s *Socket) SendStream(serial int32, proc uint32, program uint32,
348 stream io.Reader, abort chan bool) error {
349 // Keep total packet length under 4 MiB to follow possible limitation in libvirt server code
350 buf := make([]byte, 4*MiB-unsafe.Sizeof(_p))
351 for {
352 select {
353 case <-abort:
354 return s.SendPacket(serial, proc, program, nil, Stream, StatusError)
355 default:
356 }
357 n, err := stream.Read(buf)
358 if n > 0 {
359 err2 := s.SendPacket(serial, proc, program, buf[:n], Stream, StatusContinue)
360 if err2 != nil {
361 return err2
362 }
363 }
364 if err != nil {
365 if err == io.EOF {
366 return s.SendPacket(serial, proc, program, nil, Stream, StatusOK)
367 }
368 // keep original error
369 err2 := s.SendPacket(serial, proc, program, nil, Stream, StatusError)
370 if err2 != nil {
371 return err2
372 }
373 return err
374 }
375 }
376}

Callers 1

requestStreamMethod · 0.80

Calls 1

SendPacketMethod · 0.95

Tested by

no test coverage detected