红联Linux门户
Linux帮助

《unix环境高级编程》中的open服务器问题

发布时间:2009-05-03 16:16:39来源:红联作者:qq274255093
[i=s] 本帖最后由 qq274255093 于 2009-5-3 16:18 编辑 [/i]

我正在看《unix环境高级编程》,在测试17章进程高级通信中的open服务器2时,发现在serv_listen函数中的ioctl(fd[1],I_PUSH,"connld")执行时,总是返回小于0的值,因此服务器端根本建不起来。从错误类型看,是第二、三个参数出了问题。但实在是找不出是什么原因错。
另外在编译时,总是警告说fattach函数没有implemented,不知道怎么回事,感觉已经把大多数头文件include了。
本人还是菜鸟,在网上搜索了一下,问这个问题的人还挺多的,就是没人回答,请高手相助,感激不尽!!!

以下是书上给的代码:
******************************************************************
#include "apue.h"
#include
#include

/* pipe permissions: user rw, group rw, others rw */
#define FIFO_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)

/*
* Establish an endpoint to listen for connect requests.
* Returns fd if all OK, <0 on error
*/
int
serv_listen(const char *name)
{
int tempfd;
int fd[2];

/*
* Create a file: mount point for fattach().
*/
unlink(name);
if ((tempfd = creat(name, FIFO_MODE)) < 0)
return(-1);
if (close(tempfd) < 0)
return(-2);
if (pipe(fd) < 0)
return(-3);
/*
* Push connld & fattach() on fd[1].
*/
if (ioctl(fd[1], I_PUSH, "connld") < 0) { /*就是这句有问题!!*/
close(fd[0]);
close(fd[1]);
return(-4);
}
if (fattach(fd[1], name) < 0) {
close(fd[0]);
close(fd[1]);
return(-5);
}
close(fd[1]); /* fattach holds this end open */

return(fd[0]); /* fd[0] is where client connections arrive */
}
******************************************************************
文章评论

共有 8 条评论

  1. sunkien 于 2010-08-02 15:02:01发表:

    不是高手就帮助顶

  2. gujingyu 于 2010-07-12 21:09:21发表:

    试试4.3BSD的源码吧 估计你的系统不支持SVR4标准吧

  3. qq274255093 于 2009-05-08 13:09:44发表:

    高手在哪里啊??

  4. qq274255093 于 2009-05-05 20:12:05发表:

    {:2_91:}自己顶

  5. qq274255093 于 2009-05-05 19:59:04发表:

    高手在哪里啊??

  6. qq274255093 于 2009-05-04 12:55:35发表:

    大侠们,来看看吧

  7. ufnhliou 于 2009-05-03 16:34:01发表:

    我不是高手

  8. qq274255093 于 2009-05-03 16:19:06发表:

    高手在哪里啊??{:2_98:}