Пример #1
0
func mq_send(q mqd_t, data []byte, priority int) error {
	errno := C.mq_send(C.mqd_t(q), (*C.char)(unsafe.Pointer(&data[0])), C.size_t(len(data)), C.uint(priority))
	if errno < 0 {
		return fmt.Errorf("some error")
	}
	return nil
}
Пример #2
0
func mq_receive(q mqd_t) ([]byte, int, error) {
	attr, err := mq_getattr(q)
	if err != nil {
		return nil, 0, err
	}
	data := make([]byte, attr.mq_msgsize)
	var priority C.uint
	sz, err := C.mq_receive(C.mqd_t(q), (*C.char)(unsafe.Pointer(&data[0])), C.size_t(attr.mq_msgsize), &priority)
	if sz < 0 {
		return nil, 0, err
	}
	return data[:sz], int(priority), nil
}
Пример #3
0
func mq_getattr(q mqd_t) (mq_attr, error) {
	var attr mq_attr
	var cattr C.struct_mq_attr
	res, err := C.mq_getattr(C.mqd_t(q), &cattr)
	if res < 0 {
		return attr, err
	}
	attr.mq_flags = int(cattr.mq_flags)
	attr.mq_maxmsg = int(cattr.mq_maxmsg)
	attr.mq_msgsize = int(cattr.mq_msgsize)
	attr.mq_curmsgs = int(cattr.mq_curmsgs)
	return attr, nil
}
Пример #4
0
func mq_close(q mqd_t) {
	C.mq_close(C.mqd_t(q))
}