| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1249 人关注过本帖
标题:msgrcv函数
取消只看楼主 加入收藏
jingzitakk66
Rank: 1
等 级:新手上路
帖 子:198
专家分:0
注 册:2009-5-1
结帖率:98.68%
收藏
已结贴  问题点数:30 回复次数:0 
msgrcv函数
程序能顺利编译,在运行时红色部分会出现错误:c_msgrcv: Argument list too long,我找了好久也不知道哪错了

#include"stdio.h"
#include"assert.h"
#define mask 0xff
#include"unistd.h"
#include"sys/types.h"
#include"sys/ipc.h"
#define msgtyp_1 1
#define msgtyp_2 2
#define BUFSIZE 196
void print_(int position,int *buf)
{
    int *p = buf;
    int i = 0,k = 0,address = 0;
      printf("packet %d header:\n ",position);
    printf("Sync byte :0x%.4x\n", buf[0]);
    printf("transport_error_indicator :0x%.4x\n",buf[1]);
    printf("payload_unit_start_indicator :0x%.4x\n",buf[2]);
    printf("transport priority :0x%.4x\n",buf[3]);
    printf("PID :0x%.4x\n",buf[4]);
    printf("transport_scrambling_control :0x%.4x\n",buf[5]);
    printf("adaptation_field_control :0x%.4x\n",buf[6]);
    printf("continuity_counter :0x%.4x\n",buf[7]);
    printf("Other content\n");
    printf("%.4x :",address&mask);
    for(i = 8;i < 196;i++)
    {
        if(k > 14)
        {
            printf("\n%.4x :",address = address+k&mask);
            k = 0;
        }
        printf("%.2x ",buf[i]&mask);
        k++;
    }
}
void send_head( char *buf,int *buf1,unsigned int position)
{
    buf1[0] = mask & buf[0];
    buf1[1] = mask &(buf[1]&128)>>7;
     buf1[2] = mask &(buf[1]&64)>>6;
    buf1[3] = (buf[1]&32)>>5&mask;
    buf1[4] = (((buf[1]&31)<<8)+buf[2])&mask;
    buf1[5] = mask&(buf[3]&192)>>6;
    buf1[6] = ((buf[3]&48)>>4)&mask;
    buf1[7] =((buf[3]&15))&mask;
}
      
void send_other(char *buf,int *buf1)
{
    int i;
    for(i = 8;i < 196;i++)
    {
        buf1[i] = buf[i-8];
    }
}
int analyze(unsigned int position,int *buf1)
{
    char buf[188] = {0};
     FILE *fp1;
    unsigned int count = 0;
   
    fp1 = fopen("./test.trp","rb");
    assert(NULL != fp1);
    clearerr(fp1);
    while(fread(buf,1,1,fp1) == 1 && buf[0] != 0x47)
    ;//NULL statement
    fseek(fp1,-1,SEEK_CUR);
    while(fread(buf,1,188,fp1)== 188 )
    {
        if(count == position)
        {
            send_head(buf,buf1,position);
            send_other(buf,buf1);
      
            return ;
        }
        else ++count;
    }

    if(feof == 0)
        perror("read");
    else
        buf1[0] = -1;
}
struct msgp
{
    long msgtyp;
    int buf[BUFSIZE];
}msg;
main()
{
    pid_t pc;
    key_t key;
    int qid;
    if((key = ftok("./",'A')) < 0)
    {
        perror("ftok");
        exit(1);
    }
   
    if((qid = msgget(key,IPC_CREAT | 0666)) < 0)
    {
        perror("msgget");
        exit(1);
    }
    pc = fork();
    if(pc < 0)
    {
        printf("fock error\n");
        exit(1);
    }
    else if(pc == 0 )
    {
        int pos;
        while(1)
        {
            if(msgrcv(qid,&msg,4*BUFSIZE,msgtyp_1,0) < 0)
            {
                perror("c_msgrcv");
                exit(1);
            }
      
            pos = msg.buf[0];   
            analyze(pos,msg.buf);   
            msg.msgtyp = msgtyp_2;
      
            if(msgsnd(qid,&msg,sizeof(msg),0) < 0)
            {
                perror("c_msgsnd");
                exit(1);
            }
      
        }
    }
    else
    {
        int pos;
        int i;
    while(1)
    {
        printf("cmd>");
        scanf("%u",&pos);//the number pos start from 0
        //send the number of position
        msg.msgtyp = msgtyp_1;
        msg.buf[0] = pos;
   
        if(msgsnd(qid,&msg,sizeof(msg)-4,0) < 0)
        {
            perror("p_msgsnd");
            exit(1);
        }
   
        //recevie data,if msg.buf[0]== -1,pass the position range
        if(msgrcv(qid,&msg,sizeof(msg)-4,msgtyp_2,0) < 0)
        {
            perror("p_msgrcv");
            exit(1);
        }
        if(msg.buf[0] == -1)
            printf("The number of position pass the range\n");
        else
        {
            print_(pos,msg.buf);
        }
   
    }
    }
}
搜索更多相关主题的帖子: msgrcv 函数 
2009-08-29 00:35
快速回复:msgrcv函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026512 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved