Esempio n. 1
0
// msgop(2)
// ssize_t msgrcv(int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg);
func msgrcv(key int, mtype int, buffer *C.sysv_msg, strSize int, flags int) ([]byte, int, error) {
	length, err := C.msgrcv(C.int(key), unsafe.Pointer(buffer), C.size_t(strSize), C.long(mtype), C.int(flags))

	if err != nil {
		return nil, 0, err
	}

	return C.GoBytes(unsafe.Pointer(&buffer.mtext), C.int(length)), int(buffer.mtype), nil
}
Esempio n. 2
0
// Receive retrieves a message from the queue.
func (mq MessageQueue) Receive(maxlen uint, msgtyp int64, flags *MQRecvFlags) ([]byte, int64, error) {
	b := make([]byte, maxlen+8)

	rc, err := C.msgrcv(
		C.int(mq),
		unsafe.Pointer(&b[0]),
		C.size_t(maxlen),
		C.long(msgtyp),
		C.int(flags.flags()),
	)
	if rc == -1 {
		return nil, 0, err
	}

	mtyp := deserialize(b[:8])
	return b[8 : rc+8], mtyp, nil
}