免费注册 查看新帖 |

Chinaunix

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

消息队列问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-01 17:55 |只看该作者 |倒序浏览
请那位高手帮我看一下下面代码中bit_map这个变量干什么用的,最好详细说一下,谢谢!!!
client_talk_server(tx, px, ps_type)
struct  optdata *tx;
struct  pend px[MAX_PEND];
short   ps_type;
{
   static short winno=0;
   int overtime();

   int        qid23, qid24, pid, fd;
   int        ii,i, j;
   char *sp, s[80], s1[80];
   int bl, blkno, tmp_blkno;
   char sblk[300+1];
   char sss[80];
   short count,backinfo;
   unsigned int bit_map;

/* TEST COMMUNICATION LINE STATE        */
   if ((qid23= msgget(ZJKEY23, 0x1ff)) == -1) {
        printf("get qid23 =%d",qid23);
        getchar();
        return(-1);
   }
   if ((qid24= msgget(ZJKEY24, 0x1ff)) == -1){
        printf("get qid24 =%d",qid24);
        getchar();
        return(-1);
   }
/* Generate the communication buffer printf("write qid23 appid=%ld",appid);*/
   if (cmno==smno)       
        buf.mtype= MTYPE_ICBSS;
   else       
        buf.mtype= smno;
   buf.stype= MTYPE_ICBSS;
   if ((pid= getpid())== -1) return(-1);
   appid= pid+ MAX_MACHINE;
   comid= cmno;
   buf.appid= appid;
   buf.comid= comid;

   sp= buf.mdata;
   i=0;
   sprintf(sp+i,"%1d",winno);
   i+= L_WINNO;
   sprintf(sp+i,"%02d",ps_type);
   i+= MS_ACTYPE;
   sp= '0';
   i+= L_HANDLEFLAG;
   bit_map = 0;
   i+= 4; /**** 预留 bit_map 空间***/

   if(tx->optcode[0]!=0) {
        sprintf(sp+i, "%-4s", tx->optcode);
        i+= MS_CODE;
        bit_map=bit_map|0x1;
   }
   bit_map=bit_map<<1;
   if(tx->brno[0]!=0) {
        sprintf(sp+i, "%-3s", tx->brno);
        i+= MS_OP_BR;
        bit_map=bit_map|0x1;
          }
   bit_map=bit_map<<1;
  ......(省略)
   bit_map=bit_map<<1;
   if(tx->ttyno[0]!=0) {
        sprintf(sp+i, "%-8s", tx->ttyno);
        i+= MS_TTYNO;
        bit_map=bit_map|0x1;
        }

        sprintf(sp+i, "%-5s", tx->lo_country);
        i+= MS_LOC_COUNTRY;

        sprintf(sp+i, "%-5s", tx->tr_country);
        i+= MS_TR_COUNTRY;

   bit_map=bit_map<<1;
   if(tx->item[0]!=0) {
        sprintf(sp+i, "%-6s", tx->item);
        i+= MS_ITEM;
        bit_map=bit_map|0x1;
   }
   sp= '\0';

   memcpy(sp+4,&bit_map,4);  /*** write bit_map ***/

/* SENDING DATA TO MESSAGE QUEUE q23   */
   if (msgsnd(qid23,&buf,i+BUFCTL+1,0) == -1)
      return(-1);
/*    RECEIVING DATA FROM MESSAGE QUEUE q24        */
   for (i=1; i<20; i++)
        if (i!=SIGALRM&&i!=SIGUSR2) signal(i, SIG_IGN);
   signal(SIGALRM,overtime);
   alarm(RECETIME);
   if ((bl=msgrcv(qid24,&buf,MSGSIZ,appid,0)) == -1) {
        printf("appid=%ld",appid);       
        printf("msgrcv error11111");
        alarm(0);
        if (errno == EINTR)  return(-1);
        else   return(-1);
   }
   alarm(0);
   sp= buf.mdata;
   sp[bl-4]= '\0';
   i=0;
   i+= L_WINNO;
   ps_type= stoint(sp+i ,MS_ACTYPE);
   i+= MS_ACTYPE;
   i+= L_HANDLEFLAG;

   i+= 4; /*** skip bit_map ***/
   ii=i;
   memcpy(&bit_map,sp+4,4); /*** get bit_map value ***/

   winno= (winno+1)% WINDOWSIZE;

   
  
   if((bit_map&0x80000000)!=0) {
        stostr(sp+i, tx->optcode, MS_CODE);
        tx->optcode[MS_CODE]=0;
        i+= MS_CODE;
   }
   bit_map=bit_map<<1;  

   printf("%d",bit_map);
   if((bit_map&0x80000000)!=0) {
        stostr(sp+i, tx->brno, MS_OP_BR);
        i+= MS_OP_BR;
   }
   bit_map=bit_map<<1;  

   if((bit_map&0x80000000)!=0) {
        stostr(sp+i, tx->acc, MS_ACC);
        i+= MS_ACC;
        }
   bit_map=bit_map<<1;  
     
.....(省略)

   stostr(sp+i, tx->lo_country, MS_LOC_COUNTRY);
   i+= MS_LOC_COUNTRY;

   stostr(sp+i, tx->tr_country, MS_TR_COUNTRY);
   i+= MS_TR_COUNTRY;

   if((bit_map&0x80000000)!=0) {
        stostr(sp+i, tx->item, MS_ITEM);
        i+= MS_ITEM;
   }

   return(0);
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP