Exemple #1
0
// Send places a new message onto the queue
func (mq MessageQueue) Send(mtyp int64, body []byte, flags *MQSendFlags) error {
	b := make([]byte, len(body)+8)
	copy(b[:8], serialize(mtyp))
	copy(b[8:], body)

	rc, err := C.msgsnd(
		C.int(mq),
		unsafe.Pointer(&b[0]),
		C.size_t(len(body)),
		C.int(flags.flags()),
	)
	if rc == -1 {
		return err
	}
	return nil
}
Exemple #2
0
// msgop(2)
// int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg)
func msgsnd(key int, message []byte, buffer *C.sysv_msg, maxSize int, mtype int, flags int) error {
	if len(message) > maxSize {
		return errors.New(MessageBiggerThanBuffer)
	}

	msgSize := C.size_t(len(message))

	buffer.mtype = C.long(mtype)
	if msgSize > 0 {
		C.memcpy(unsafe.Pointer(&buffer.mtext), unsafe.Pointer(&message[0]), msgSize)
	}

	_, err := C.msgsnd(C.int(key), unsafe.Pointer(buffer), msgSize, C.int(flags))

	return err
}