Exemple #1
0
func (c *CoreImpl) ReadMessage(handle MojoHandle, flags MojoReadMessageFlags) (MojoResult, []byte, []MojoHandle, uint32, uint32) {
	var num_bytes, num_handles C.uint32_t
	if result := C.MojoReadMessage(handle.cType(), nil, &num_bytes, nil, &num_handles, flags.cType()); result != C.MOJO_RESULT_RESOURCE_EXHAUSTED {
		return (MojoResult)(result), nil, nil, 0, 0
	}
	msg := make([]byte, (uint32)(num_bytes))
	attached := make([]MojoHandle, (uint32)(num_handles))
	result := C.MojoReadMessage(handle.cType(), cArrayBytes(msg), &num_bytes, cArrayMojoHandle(attached), &num_handles, (C.MojoReadMessageFlags)(flags))
	return (MojoResult)(result), msg, attached, (uint32)(num_bytes), (uint32)(num_handles)
}
Exemple #2
0
func (c *CGoSystem) ReadMessage(handle uint32, flags uint32) (result uint32, buf []byte, handles []uint32) {
	var numBytes, numHandles C.uint32_t
	cHandle := C.MojoHandle(handle)
	cFlags := C.MojoReadMessageFlags(flags)
	if r := C.MojoReadMessage(cHandle, nil, &numBytes, nil, &numHandles, cFlags); r != C.MOJO_RESULT_RESOURCE_EXHAUSTED {
		return uint32(r), nil, nil
	}
	var bufPtr unsafe.Pointer
	if numBytes != 0 {
		buf = make([]byte, int(numBytes))
		bufPtr = unsafe.Pointer(&buf[0])
	}
	var handlesPtr *C.MojoHandle
	if numHandles != 0 {
		handles = make([]uint32, int(numHandles))
		handlesPtr = (*C.MojoHandle)(unsafe.Pointer(&handles[0]))
	}
	r := C.MojoReadMessage(cHandle, bufPtr, &numBytes, handlesPtr, &numHandles, cFlags)
	return uint32(r), buf, handles
}