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

Method SendPacket

socket/socket.go:296–344  ·  view source on GitHub ↗

SendPacket sends a packet to libvirt on the socket connection.

(
	serial int32,
	proc uint32,
	program uint32,
	payload []byte,
	typ uint32,
	status uint32,
)

Source from the content-addressed store, hash-verified

294
295// SendPacket sends a packet to libvirt on the socket connection.
296func (s *Socket) SendPacket(
297 serial int32,
298 proc uint32,
299 program uint32,
300 payload []byte,
301 typ uint32,
302 status uint32,
303) error {
304 p := packet{
305 Header: Header{
306 Program: program,
307 Version: constants.ProtocolVersion,
308 Procedure: proc,
309 Type: typ,
310 Serial: serial,
311 Status: status,
312 },
313 }
314
315 size := int(unsafe.Sizeof(p.Len)) + int(unsafe.Sizeof(p.Header))
316 if payload != nil {
317 size += len(payload)
318 }
319 p.Len = uint32(size)
320
321 if s.isDisconnected() {
322 // this mirrors what a lot of net code return on use of a no
323 // longer valid connection
324 return syscall.EINVAL
325 }
326
327 s.mu.Lock()
328 defer s.mu.Unlock()
329
330 err := binary.Write(s.writer, binary.BigEndian, p)
331 if err != nil {
332 return err
333 }
334
335 // write payload
336 if payload != nil {
337 err = binary.Write(s.writer, binary.BigEndian, payload)
338 if err != nil {
339 return err
340 }
341 }
342
343 return s.writer.Flush()
344}
345
346// SendStream sends a stream of packets to libvirt on the socket connection.
347func (s *Socket) SendStream(serial int32, proc uint32, program uint32,

Callers 2

SendStreamMethod · 0.95
requestStreamMethod · 0.80

Calls 2

isDisconnectedMethod · 0.95
WriteMethod · 0.80

Tested by

no test coverage detected