Exemple #1
0
// Remove deletes the queue.
// This will also awake all waiting readers and writers with EIDRM.
func (mq MessageQueue) Remove() error {
	rc, err := C.msgctl(C.int(mq), C.IPC_RMID, nil)
	if rc == -1 {
		return err
	}
	return nil
}
Exemple #2
0
// Stat produces information about the queue.
func (mq MessageQueue) Stat() (*MQInfo, error) {
	mqds := C.struct_msqid_ds{}

	rc, err := C.msgctl(C.int(mq), C.IPC_STAT, &mqds)
	if rc == -1 {
		return nil, err
	}

	mqinf := MQInfo{
		Perms: IpcPerms{
			OwnerUID:   int(mqds.msg_perm.uid),
			OwnerGID:   int(mqds.msg_perm.gid),
			CreatorUID: int(mqds.msg_perm.cuid),
			CreatorGID: int(mqds.msg_perm.cgid),
			Mode:       uint16(mqds.msg_perm.mode),
		},
		LastSend:   time.Unix(int64(mqds.msg_stime), 0),
		LastRcv:    time.Unix(int64(mqds.msg_rtime), 0),
		LastChange: time.Unix(int64(mqds.msg_ctime), 0),
		MsgCount:   uint(mqds.msg_qnum),
		MaxBytes:   uint(mqds.msg_qbytes),
		LastSender: int(mqds.msg_lspid),
		LastRcver:  int(mqds.msg_lrpid),
	}
	return &mqinf, nil
}
Exemple #3
0
// Set updates parameters of the queue.
func (mq MessageQueue) Set(mqi *MQInfo) error {
	mqds := &C.struct_msqid_ds{
		msg_perm: C.struct_ipc_perm{
			uid:  C.__uid_t(mqi.Perms.OwnerUID),
			gid:  C.__gid_t(mqi.Perms.OwnerGID),
			mode: C.ushort(mqi.Perms.Mode & 0x1FF),
		},
		msg_qbytes: C.msglen_t(mqi.MaxBytes),
	}

	rc, err := C.msgctl(C.int(mq), C.IPC_SET, mqds)
	if rc == -1 {
		return err
	}
	return nil
}
Exemple #4
0
// msgctl(2)
// int msgctl(int msqid, int cmd, struct msqid_ds *buf);
func msgctl(key int, cmd int) (*C.struct_msqid_ds, error) {
	info := new(C.struct_msqid_ds)
	_, err := C.msgctl(C.int(key), C.int(cmd), info)

	return info, err
}