QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1061|回复: 2

怎样让消息队列接受函数不阻塞

[复制链接]
发表于 2004-1-9 12:03:18 | 显示全部楼层 |阅读模式
msgrcv()函数如果接受不到指定的消息,将会阻塞,如果要让它不阻塞,在哪儿设置"IPC_NOWAIT"呢?
发表于 2004-1-9 12:16:32 | 显示全部楼层
这些东西
man里面都有
建议好好看看

msgrcv
------

      int msgrcv (int msqid, struct msgbuf *msgp, int msgsz, long msgtyp,
                              int msgflg);

    * msqid  : id obtained by a call to msgget.

    * msgsz  : maximum size of message to receive.

    * msgp   : allocated by user to store the message in.

    * msgtyp :
           0 => get first message on queue.

           > 0 => get first message of matching type.

           < 0 => get message with least type  which is <= abs(msgtyp).

    * msgflg :
           IPC_NOWAIT : Return immediately if message not found.

           MSG_NOERROR : The message is truncated if it is larger than
           msgsz.

           MSG_EXCEPT : Used with msgtyp > 0 to receive any msg except
           of specified type.

    * returns : size of message if found. -1 on error.

    The first message that meets the `msgtyp' specification is
identified. For msgtyp < 0, the entire queue is searched for the
message with the smallest type.

    If its length is smaller than msgsz or if the user specified the
MSG_NOERROR flag, its text and type are copied to msgp->mtext and
msgp->mtype, and it is taken off the queue.

    The `msg_cbytes', `msg_qnum', `msg_lrpid', and `msg_rtime' fields
are updated. Writers waiting on the queue are awakened.

Errors:
E2BIG  : msg bigger than msgsz and MSG_NOERROR not specified.
EACCES : Do not have permission for reading the queue.
EFAULT : msgp not accessible.
EIDRM  : msg queue was removed.
EINTR  : msg not found ... would have slept but ... was interrupted.
EINVAL : msgsz > msgmax or msgsz < 0, msqid < 0 or unused.
ENOMSG : msg of requested type not found and IPC_NOWAIT specified.
回复

使用道具 举报

 楼主| 发表于 2004-1-9 15:22:39 | 显示全部楼层
thank you
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-9 03:01 , Processed in 0.056223 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表