• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Prayer

            在一般中尋求卓越
            posts - 1256, comments - 190, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
            其他的不管,只是關(guān)注一下alarm的用法,設(shè)定了msgrcv超時。


            環(huán)境是redhat9
            當把發(fā)送緩沖中寫入大于8位數(shù)據(jù)時 可以成功發(fā)送但只能收到8位信息

            代碼如下
            //定義
            struct msgbuf  //消息結(jié)構(gòu)
            {
                    long mtype;
                    char mtext[100];
            }msgbuf;
                                                                                            


            //創(chuàng)建消息隊列
            void  creatque()
            {
                                                                                                                                                           
                    static int msg_que_id=-1;
                    struct sigaction action;
                    /*檢查是否存在的要創(chuàng)建的消息隊列,如果存在到 就刪除它*/
                    msg_que_id=msgget(BOOKING_KEY,0);
                    if(msg_que_id!=-1){
                            if(msgctl(msg_que_id,IPC_RMID,0)==-1){
                                    perror("remove old message");
                                    exit(1);
                            }
                    }
                    /*創(chuàng)建消息隊列*/
                    msg_que_id=msgget(BOOKING_KEY,IPC_CREAT|0666);
                    if(msg_que_id==-1){
                            perror("creat new message list");
                            exit(1);
                    }
                    /*忽略其它一些參數(shù)*/
                    action.sa_handler=SIG_IGN;
                    action.sa_flags=0;
                    sigemptyset(&action.sa_mask);
                    sigaction(SIGINT,&action,NULL);
                    sigaction(SIGQUIT,&action,NULL);
                    sigaction(SIGHUP,&action,NULL);
            }

            //發(fā)消息
            void control(char *c)
            {
                    int send_len;
                    int msg_que_id=-1;
                    struct msgbuf send_msg;
                    memset(send_msg.mtext,'\0',sizeof(send_msg.mtext));
                    send_len=sizeof(long)+sizeof(int);
                    msg_que_id=msgget(BOOKING_KEY,0);
                    if(msg_que_id==-1){
                            perror("get message list id");
                            exit(1);
                    }
                                                                                            
                                                                                            
                    if(!strncasecmp(c,"lk",2)){/*連接狀態(tài)信號*/
                            send_msg.mtype=httpd_stoped;
                            sprintf(send_msg.mtext,"linking");
                            if(msgsnd(msg_que_id,&send_msg,send_len,0)&lt;0){
                                    perror("send message");
                                    exit(1);
                            }
                    }
            }

            //接收消息
            void *other_key(void *data)
            {
                    int msg_que_id=-1;
                    int rece_len,send_len;
                    struct msgbuf rece_msg;
                    memset(rece_msg.mtext,'\0',sizeof(rece_msg.mtext));
                    send_len=sizeof(long)+sizeof(int);
                    msg_que_id=msgget(BOOKING_KEY,0);
                    if(msg_que_id==-1){
                            perror("get message list id");
                            exit(1);
                    }
                    while(1){
                            /*定時器定時LKTIMEOUTs來接收30s一次的連接狀態(tài)信號,*/
                            /*如果時間到而沒有接收到信號則判斷接收方關(guān)閉了監(jiān)視端,服務器將中斷此次連接*/
                                                                                                                                                   
                            alarm(35);
                            rece_len=msgrcv(msg_que_id,&rece_msg,sizeof(msgbuf)-sizeof(long),(int)httpd_stoped,0);
                            if(rece_len&lt;0){
                                    perror("receive message");
                                    exit(1);
                            }
                            if(!strcmp(rece_msg.mtext,"linking")){
                                  alarm(0);
                            }
                            else if(!strcmp(rece_msg.mtext,"q")){
                                     if(msgsnd(msg_que_id,&rece_msg,send_len,0)&lt;0){/*把取出的結(jié)束信息再寫回去(因為一條信息只能被取一次)*/
                                             perror("send message");               /*而取出一次只能結(jié)束一個進程*/
                                             exit(1);
                                     }
                                     exit(1);
                            }
                                                                                                                                                   
                                                                                                                                                   
            }
            }

            Feedback

            # re: 我創(chuàng)建的消息隊列為什么最大只能接收到8位信息--只關(guān)注alarm的用法  回復  更多評論   

            2009-04-30 16:14 by 半島刀客
            在msgsnd的長度參數(shù),最好不要用sizeof()...,請直接用定長試試
            国产亚洲美女精品久久久| 亚洲欧美日韩精品久久亚洲区 | 国产精品亚洲综合专区片高清久久久| 久久精品国产精品亚洲精品| 日韩十八禁一区二区久久| 国产欧美久久一区二区| 久久亚洲色一区二区三区| 久久99亚洲网美利坚合众国| 亚洲欧美精品一区久久中文字幕 | 久久人妻少妇嫩草AV无码蜜桃| 综合久久国产九一剧情麻豆| 久久这里只精品国产99热| 蜜桃麻豆WWW久久囤产精品| 久久无码av三级| 精品久久无码中文字幕| 久久精品一区二区三区AV| 久久嫩草影院免费看夜色| 久久精品国产精品青草| 久久精品中文闷骚内射| 婷婷久久香蕉五月综合加勒比| 日韩美女18网站久久精品| 久久精品国产精品亚洲下载| 97久久精品无码一区二区| 久久精品人人做人人爽电影 | 少妇内射兰兰久久| 久久久久国产精品嫩草影院| 热久久最新网站获取| 青草久久久国产线免观| 青青草原综合久久大伊人导航| 国产精品99久久不卡| 国产香蕉97碰碰久久人人| 国产精品熟女福利久久AV| 久久99国产精品久久99果冻传媒 | 国产成人无码精品久久久免费 | 亚洲国产小视频精品久久久三级 | 中文字幕乱码久久午夜| 中文字幕久久波多野结衣av| 人妻无码αv中文字幕久久 | 亚洲精品乱码久久久久久蜜桃| 久久99亚洲综合精品首页| 青青热久久国产久精品 |