免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 5901 | 回复: 13
打印 上一主题 下一主题

如何用 select()来 从多个消息队列读取消息 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-05-24 15:54 |只看该作者 |倒序浏览
在 aix 4.3上, 建两个消息队列, 调用fd_set( msgid, &readset)时,出错,msgid为一消息队列id,请问如何解决

论坛徽章:
0
2 [报告]
发表于 2004-05-24 16:07 |只看该作者

如何用 select()来 从多个消息队列读取消息

是不是select()不支持消息隊列
我隻知道select()支持File 和socket描述符

论坛徽章:
0
3 [报告]
发表于 2004-05-24 16:16 |只看该作者

如何用 select()来 从多个消息队列读取消息

在aix 4.3 上man出来的

man select


------------------------------------------------------------------------------
    Base Operating System and Extensions Technical Reference, Volume 2
------------------------------------------------------------------------------

select Subroutine

Purpose

Checks the I/O status of multiple file descriptors and message queues.

Library

Standard C Library (libc.a)

Syntax

#include <sys/time.h>;

#include <sys/select.h>;

#include <sys/types.h>;

int select (Nfdsmsgs, ReadList, WriteList, ExceptList, TimeOut)

int Nfdsmsgs;

struct sellist *ReadList, *WriteList, *ExceptList;

struct timeval *TimeOut;

还有这个结构
struct sellist

{

int fdsmask[F];        /* file descriptor bit mask  */

int msgids[M];         /* message queue identifiers */

};
应该能用于消息队列

论坛徽章:
0
4 [报告]
发表于 2004-05-24 16:21 |只看该作者

如何用 select()来 从多个消息队列读取消息

把代碼貼出來,還有出錯提示

论坛徽章:
0
5 [报告]
发表于 2004-05-24 16:25 |只看该作者

如何用 select()来 从多个消息队列读取消息

??

论坛徽章:
0
6 [报告]
发表于 2004-05-24 16:33 |只看该作者

如何用 select()来 从多个消息队列读取消息

int msgids[M]; /* message queue identifiers */
此消息隊列不是操作系統概念中的消息隊列吧

论坛徽章:
0
7 [报告]
发表于 2004-05-24 16:36 |只看该作者

如何用 select()来 从多个消息队列读取消息

#include <sys/time.h>;
#include <sys/select.h>;
#include <sys/types.h>;
#include "crtl.h"
main() {
char file_name[50];
char s_para[50];
int  snd_key = 0;
int  rcv_key = 0;
int  msgsnd_id = 0;
int  msgrcv_id = 0;
int  maxfd;
int  FdReady;
fd_set readset;

memset( s_para, 0, sizeof(s_para) );

FD_ZERO( &readset );
memset( file_name, 0, sizeof(file_name) );
snprintf( file_name, 49, "%s/confpara/para.ini", getenv("SCHE_PATH" );



/*--------读取发送消息队列的键值----------------------------------*/
memset( s_para, 0, sizeof(s_para) );
if( read_para( file_name, "MSGSENDKEY", s_para) == 0 )
return(-1);
snd_key = StrToInt16WithSize(s_para, sizeof(s_para) );

/*--------读取接收消息队列的键值----------------------------------*/
memset( s_para, 0, sizeof(s_para) );

      if( read_para( file_name, "MSGRECVKEY", s_para) == 0 )
              return(-1);
      rcv_key = StrToInt16WithSize(s_para, sizeof(s_para) );


      if( (msgsnd_id = msg_accessing( snd_key ) ) < 0 )
              return( -1 );

      if( (msgrcv_id = msg_accessing( rcv_key ) ) < 0 ) {
              return( -1 );
      }
       printf(" snd_id = %d, rcv_id= %d\n", msgsnd_id, msgrcv_id);

       if( msgsnd_id >; msgrcv_id ) {
               maxfd = msgsnd_id;
       } else {
               maxfd = msgrcv_id;
       }
/*上面是连接消息队列*/
       FD_ZERO( &readset);
       FD_SET( msgsnd_id, &readset );/*51行*/       FD_SET( msgrcv_id, &readset );
       FdReady = select( maxfd+1, &readset, 0, 0, 0 );
       printf( "fd %d is ready.\n", FdReady );
}
运行后出core了,dbx core的信息是:Segmentation fault in main at line 51 in file "select.c"

论坛徽章:
0
8 [报告]
发表于 2004-05-24 16:42 |只看该作者

如何用 select()来 从多个消息队列读取消息

如果不是消息队列,那么 “Checks the I/O status of multiple file descriptors and message queues”有怎么解释呢?
I/O status of multiple file descriptors 应该是文件描述符,比如socket之类的。“and message queues" 的 "and" 又如何解释呢。

论坛徽章:
0
9 [报告]
发表于 2004-05-24 18:46 |只看该作者

如何用 select()来 从多个消息队列读取消息

既然select的第2,3,4 个参数在楼主的AIX系统上不是fd_set指针类型,而是结构struct sellist指针类型,那么就应该把消息队列的id放入这个结构的msgids元素中,把描述符号放入fdsmask元素中。

我真的还没见过这样的select呢,长见识了。

论坛徽章:
0
10 [报告]
发表于 2004-05-24 19:43 |只看该作者

如何用 select()来 从多个消息队列读取消息

用 poll 吧,简单一些,不过对 消息队列 用 select 和 poll 都不可移植啊。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP