免费注册 查看新帖 |

Chinaunix

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

关于mkfifo问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-08-13 20:02 |只看该作者 |倒序浏览
写了一个mkfifo程序,总是出现莫明其妙的问题,现在贴出来,请大家帮指点一下。
这是write 函数
int main(int argc, char **argv)
{
  int r_value = 0;
  ix_uint32 i_rbyte = 0;
  ix_uint8 i_type = 0;
  ix_uint8 r_log_buf[2048] = {0};
  ix_uint8 r_dbg_buf[2048] = {0};
  ix_uint8 fd = 0;
  ix_uint8 i_count = 0;
  ix_uint32 read_wbyte = 0;
  ix_uint8 i_stat = 0;
  if (argc < 4)
  {
      fprintf(stderr, "the argc is error \n";
      exit(0);
  }
  /*r_value = daemon_init();  
  if (r_value != 0)
  {
      exit(0);
  }
  */
  i_type = atoi(*(argv + 1));
  i_count = atoi(*(argv + 2));
  mkfifo_create(MKFIFO_LOG_PATH);
  mkfifo_create(MKFIFO_DBG_PATH);

  if (i_type == 1)
  {
    fd = fifo_open(MKFIFO_LOG_PATH);
  }
  else
  {
    fd = fifo_open(MKFIFO_DBG_PATH);
  }
  
  while(i_count--)
  {
     /* i_rbyte = ntb_app_read(&i_type, r_buf);
      if (i_rbyte < 0)
      {
          fprintf(stderr, "daemon fun i_rbyte is error\n";
          continue;
      }
      if (i_rbyte != 1024)
      {
          fprintf(stderr, "recv byte not 1024\n";
      }
      */

      if (i_type == PACKET_TYPE_LOG)
      {
     /*   if(i_stat == 0)
          mkfifo_create(MKFIFO_LOG_PATH);

          fd = fifo_open(MKFIFO_LOG_PATH);
          */
          memcpy(r_log_buf, *(argv + 3), strlen(*(argv + 3)));
          //read_wbyte = write(i_log_fd, r_buf, 204;
          read_wbyte = write(fd, r_log_buf, 204;
          if (read_wbyte == -1)
          {
              fprintf(stderr, "write log is error\n";
              return -1;
          }

      }

      if (i_type == PACKET_TYPE_DEBUG)
      {
       /*   if(i_stat == 0)
          mkfifo_create(MKFIFO_DBG_PATH);

          fd = fifo_open(MKFIFO_DBG_PATH);
          */
          memcpy(r_dbg_buf, *(argv + 3), strlen(*(argv + 3)));
          //read_wbyte = write(i_dbg_fd, r_buf, 204;
          read_wbyte = write(fd, r_dbg_buf, 204;
          if (read_wbyte == -1)
          {
              fprintf(stderr, "write debug is error\n";
              return -1;
          }


      }

     // i_stat = 1;
      fifo_close(fd);
  }
  //fifo_close(fd);
  return 0;
}
××××××××××××××××××××分隔线××××××××××××××××××××××××
这是read 函数
int main(int argc, char** argv)
{
    char r_buf[2050] = {0};
    int  fd = 0;
    int  r_size = 0;
    int  r_type = 0;
    int  ret_size = 0;
    if (argc < 3)
    {
      perror("argc is error\n";
    }
    r_type=atoi(argv[1]);
    r_size=atoi(argv[2]);
    //fd = open(FIFO_SERVER, O_RDONLY, 0);
    if (r_type == 1)
    {
      fd = open(FIFO_LOG_SERVER, O_RDONLY, 0);
    }
    else
    {
      fd = open(FIFO_DBG_SERVER, O_RDONLY, 0);
    }
    if (fd == -1)
    {
      printf("open is error\n";
      return -1;
    }
    printf("the fd is %d\n", fd);
    r_buf[2050 - 1] = '\0';
    while(1)
    {
       if (r_type == 1)
       {
         fd = open(FIFO_LOG_SERVER, O_RDONLY, 0);
       }
       else
       {
         fd = open(FIFO_DBG_SERVER, O_RDONLY, 0);
       }

     ret_size = read(fd, r_buf, r_size);
     if (ret_size == -1)
      {
        printf("no data \n";
      }
     printf("the ret_size is %s\n", r_buf);
     close(fd);
    }
    return 0;
}
由于考虑到循环中反复open文件,可能会降低效率,因此希望一直是open状态。但是总是出现奇怪的现象,第一次可以正常,但是后边总是错误。请大家帮看一下。

论坛徽章:
0
2 [报告]
发表于 2007-08-13 23:03 |只看该作者
问题已经解决了.谢谢!

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
3 [报告]
发表于 2007-08-13 23:42 |只看该作者
原帖由 nebula2005 于 2007-8-13 23:03 发表
问题已经解决了.谢谢!

怎么解决的?
贴出来可以帮助以后遇到同样问题的
人。

论坛徽章:
0
4 [报告]
发表于 2008-04-24 11:22 |只看该作者
问题怎么解决的,楼主也说一下塞
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP