Exemple #1
0
// Stream.Write writes the given data to the stream,
// blocking until the data has been written.
func (s *Stream) Write(data []byte) (int, error) {
	var err C.int
	written := C.pa_simple_write(
		s.simple,
		unsafe.Pointer(&data[0]),
		C.size_t(len(data)),
		&err,
	)
	if err == C.PA_OK {
		return int(written), nil
	}
	return int(written), errorFromCode(err)
}
Exemple #2
0
// Write writes data to server.
func (w *Writer) Write(data []byte) error {
	cdata := (*reflect.SliceHeader)(unsafe.Pointer(&data))
	C.pa_simple_write(
		w.Conn.simple,
		unsafe.Pointer(cdata.Data),
		C.size_t(len(data)),
		&w.Conn.err.no,
	)
	if w.Conn.err.no != C.int(0) {
		return w.Conn.err
	}

	return nil
}