Example #1
0
func (v *VirStream) Write(p []byte) (int, error) {
	n := C.virStreamSend(v.ptr, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(len(p)))
	if n < 0 {
		return 0, GetLastError()
	}
	if n == 0 {
		return 0, io.EOF
	}

	return int(n), nil
}
Example #2
0
// Write writes a series of bytes to the stream. This method may block the
// calling application for an arbitrary amount of time. Once an application has
// finished sending data it should call Finish to wait for successful
// confirmation from the driver, or detect any error.
// This method may not be used if a stream source has been registered.
// Errors are not guaranteed to be reported synchronously with the call, but may
// instead be delayed until a subsequent call.
// This function is equivalent to the libvirt function "Send" but it has been
// renamed to "Write" in order to implement the standard interface io.Writer.
func (str Stream) Write(data []byte) (int, error) {
	cData := C.CString(string(data))
	defer C.free(unsafe.Pointer(cData))

	l := len(data)

	str.log.Printf("sending %v bytes to stream...\n", l)
	cRet := C.virStreamSend(str.virStream, cData, C.size_t(l))
	ret := int32(cRet)

	if ret < 0 {
		err := LastError()
		str.log.Printf("an error occurred: %v\n", err)
		return 0, err
	}

	str.log.Printf("%v bytes sent\n", ret)

	return int(ret), nil
}
Example #3
0
func (s *VirStream) Send(data []byte, size int) int {
	cBytes := C.virStreamSend(s.ptr, (*C.char)(unsafe.Pointer(&data[0])), C.size_t(size))
	return int(cBytes)
}