免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: nde
打印 上一主题 下一主题

请教蓝色键盘:关于name stream pipe的用法问题 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2003-12-02 13:25 |只看该作者

请教蓝色键盘:关于name stream pipe的用法问题

哦,我想当然了... postfix用的是I_SENDFD方式的流...
另外,精华区有相关的文章,挺详细的呀?http://chinaunix.net/jh/23/107530.html

论坛徽章:
0
12 [报告]
发表于 2003-12-02 15:03 |只看该作者

请教蓝色键盘:关于name stream pipe的用法问题

原帖由 "mmHunter" 发表:
哦,我想当然了... postfix用的是I_SENDFD方式的流...
另外,精华区有相关的文章,挺详细的呀?http://chinaunix.net/jh/23/107530.html


你真是个热心人,多谢了。
那篇文章我看过,作者蓝色键盘,这个帖子题目就是想请教他的。那篇文章的主要内容就是man spx输出的结果。其中uname stream pipe“无名”流管道的部分我已试验过OK,进一步试验named stream pipe“有名”流管道时遇到问题-create/open/write OK,read errno=5。这是man spx以及那篇文章中都没有提到的。我用google搜索过/dev/spx都没有找到相关信息。

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
13 [报告]
发表于 2003-12-04 15:28 |只看该作者

请教蓝色键盘:关于name stream pipe的用法问题

可惜我没有sco的环境。

不过我看了一下说明,通过spx建立无名管道,需要打开这个设备两次,
并通过ioctl对这两个描述符建立对应的联系。之后就和通常的pipe操作一样了。希望以下的代码对你有所帮助,并且,也讲述到了如何通过spx建立有名管道,以及传递文件描述符。

http://osr5doc.ca.caldera.com:457/cgi-bin/man/man?spx+HW

  1. Examples
  2. A routine to create an unnamed bi-directional stream pipe in the manner of pipe(S):
  3. #include <unistd.h>;
  4. #include <sys/types.h>;
  5. #include <sys/fcntl.h>;
  6. #include <sys/stream.h>;
  7. #include <sys/stropts.h>;
  8. #include <sys/stat.h>;
  9. #include <termio.h>;
  10. #include <signal.h>;
  11. #define SPX        "/dev/spx"

  12. int spipe(fd)
  13. int *fd;
  14. {
  15.    struct strfdinsert s;
  16.    long p;

  17.    if ( ( fd[0] = open(SPX, O_RDWR) ) < 0 )
  18.           return(-1);
  19.    if ( ( fd[1] = open(SPX, O_RDWR) ) < 0 ) /* open different minor */
  20.           return(-1);

  21.    s.ctlbuf.buf = (caddr_t) &p ;
  22.    s.ctlbuf.maxlen = s.ctlbuf.len = sizeof(long);
  23.    s.databuf.buf = (caddr_t) NULL;
  24.    s.databuf.maxlen = s.databuf.len = -1;
  25.    s.fildes = fd[1];
  26.    s.offset = s.flags = 0;

  27.    if ( ioctl(fd[0], I_FDINSERT, &s) < 0 ) /* join loop drivers */
  28.         return(-1);
  29.    return(0);
  30. }

  31. A routine to create a named stream pipe from a unnamed one (this requires root privilege):
  32.    int nspipe(fd, pipename)
  33.    int *fd;
  34.    char *pipename;
  35.    {
  36.      struct stat status;
  37.      int omask;
  38.    
  39.      if ( spipe(fd) < 0 )
  40.            return(-1);
  41.    
  42.      if ( fstat(fd[0],&status) < 0 )
  43.            return(-1);
  44.    
  45.      unlink(pipename);
  46.      omask = umask(0);
  47.      if ( mknod(pipename, S_IFCHR|0666, status.st_rdev) < 0 ) /* create node */
  48.            return(-1);
  49.      umask(omask);
  50.    
  51.      return(0);
  52.    }

  53. A routine to pass a file descriptor to another process:
  54.    int passfd(fd, sendfd)
  55.    int fd, sendfd;
  56.    {
  57.       if ( ioctl(fd, I_SENDFD, sendfd) < 0 ) /* send descriptor sendfd */
  58.            return(-1);
  59.    }

  60. A routine to receive a file descriptor from a process:
  61.    int recvfd(fd)
  62.    int fd;
  63.    {
  64.            struct strrecvfd s;
  65.    
  66.            if ( ioctl(fd, I_RECVFD, (char *) &s) < 0 )
  67.                    return(-1);
  68.    
  69.    /*        s.uid        received effective user ID of sender
  70.            s.gid        received effective group ID of sender */
  71.           
  72.            return(s.fd);        /* received file descriptor */
  73.    }

复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP