URN Logo
UNIX Resources » Linux » China Linux Forum » C/C++编程版 » 63 » how to use /dev/epoll ??
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  TI专版
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
how to use /dev/epoll ??
how to use /dev/epoll ?? - gxcooo [2004-02-21 00:01 | 1,093 byte(s)]
 
可以直接打开 /dev/epoll - oknet [2004-02-23 17:21 | 2,129 byte(s)]
 
Re: 可以直接打开 /dev/epoll - gxcooo [2004-02-23 19:18 | 598 byte(s)]
 
Re: how to use /dev/epoll ?? - mylen [2004-02-21 01:06 | 129 byte(s)]
 
Re: how to use /dev/epoll ?? - gxcooo [2004-02-21 01:30 | 184 byte(s)]
 
Re: how to use /dev/epoll ?? - mylen [2004-02-21 01:44 | 222 byte(s)]
 
Re: how to use /dev/epoll ?? - gxcooo [2004-02-21 01:56 | 264 byte(s)]
 
Subject: how to use /dev/epoll ??
Author: gxcooo    Posted: 2004-02-21 00:01    Length: 1,093 byte(s)
[Original] [Print] [Top]
#include <stdlib.h>
#include <sys/epoll.h>
#include <errno.h>
#include <string.h>

int main(int argc,char** argv)
{
if(epoll_create(1024)==-1)
{
printf("epoll_create failed(%s) ",strerror(errno));
}
else
{
printf("epoll_create sucess ");
}
return 0;
}


我用的是Gentoo1.4 ,kernel 2.6.3,gcc version 3.3.2 20031218,上面程序编译时提示:
gxcooo@localhost epoll $ gcc -o test test.c
/tmp/ccQ03ase.o(.text+0x18): In function `main':
: warning: warning: epoll_create is not implemented and will always fail
运行时:
gxcooo@localhost epoll $ ./test
epoll_create failed(Function not implemented)


难道gun/linux2.6.3并没有自带epoll?
----
[Original] [Print] [Top]
Subject: Re: how to use /dev/epoll ??
Author: mylen    Posted: 2004-02-21 01:06    Length: 129 byte(s)
[Original] [Print] [Top]
glibc没实现epoll的几个函数,把glibc升级到新版本就可以了,我在rh9下升级到kernel2.6也是这个错误,用fedora core 1升到2.6就一切OK了。
----
风车的翼子依然转着
可是磨盘上
却是空的...
[Original] [Print] [Top]
Subject: Re: how to use /dev/epoll ??
Author: gxcooo    Posted: 2004-02-21 01:30    Length: 184 byte(s)
[Original] [Print] [Top]
呵呵,谢谢师兄,还不睡啊〉?
我用的glibc是glibc-2.3.2-r9,刚emerge的,看来是不支持
RedHat's glibc-2.3.2 builds support it:)
自己装一个epoll-lib-0.11.tar.gz
----
[Original] [Print] [Top]
Subject: Re: how to use /dev/epoll ??
Author: mylen    Posted: 2004-02-21 01:44    Length: 222 byte(s)
[Original] [Print] [Top]
刚把智冠三国演义1翻出来重温旧梦,呵呵
开始我也用了epolllib,可是总make不过去,后来懒的弄了,干脆升成fedora+2.6.1,不用epolllib也可以使用epoll api了,感觉epolllib只是一个过渡的东西。
期待fedora core 2中:)
----
风车的翼子依然转着
可是磨盘上
却是空的...
[Original] [Print] [Top]
Subject: Re: how to use /dev/epoll ??
Author: gxcooo    Posted: 2004-02-21 01:56    Length: 264 byte(s)
[Original] [Print] [Top]
等epolllib融入glibc稳定版。。。
哈哈 可以工作了
localhost bin # ./epoll-pipetest
child-run=11346 fd=4
child-run=11347 fd=5
child-run=11348 fd=6
child-run=11349 fd=7
child-run=11350 fd=8
----
[Original] [Print] [Top]
Subject: 可以直接打开 /dev/epoll
Author: oknet    Posted: 2004-02-23 17:21    Length: 2,129 byte(s)
[Original] [Print] [Top]
/* open /dev/epoll */

if ((kdpfd = open("/dev/epoll", O_RDWR)) == -1) {
perror("open() /dev/epoll");
return -1;
}

/* set maxsfd */
if (ioctl(kdpfd, EP_ALLOC, maxsfd))
{
perror("ioctl() /dev/epoll");
close(kdpfd);
return -1;
}

/* create a mmap block for epoll */
if ((map = (char *) mmap(NULL, mapsize, PROT_READ,
MAP_PRIVATE, kdpfd, 0)) == (char *) -1)
{
perror("mmap() /dev/epoll");
ioctl(kdpfd, EP_FREE, 0);
close(kdpfd);
return -1;
}

/* add file descriptors */
struct pollfd pfd;

pfd.fd = fd;
pfd.events = POLLIN | POLLOUT | POLLERR | POLLHUP;
pfd.revents = 0;
if (write(kdpfd, &pfd, sizeof(pfd)) != sizeof(pfd)) {
/* report error */
}

/* enumerate events on descriptors */
struct pollfd *pfds;
struct evpoll evp;

for (;;) {
evp.ep_timeout = STD_SCHED_TIMEOUT;
evp.ep_resoff = 0;

nfds = ioctl(kdpfd, EP_POLL, &evp);
pfds = (struct pollfd *) (map + evp.ep_resoff);
for (ii = 0; ii < nfds; ii++, pfds++) {
// do_some_action(pfds.fd, pfds.revents);
}
}

/* remove descriptors */
pfd.fd = fd;
pfd.events = POLLREMOVE;
pfd.revents = 0;
if (write(kdpfd, &pfd, sizeof(pfd)) != sizeof(pfd)) {
/* report error */
}

http://epoll.hackerdojo.com/
----
[Original] [Print] [Top]
Subject: Re: 可以直接打开 /dev/epoll
Author: gxcooo    Posted: 2004-02-23 19:18    Length: 598 byte(s)
[Original] [Print] [Top]
谢谢楼上的,在《Scalable Network Programming》中看到这么一段:
The disadvantage of /dev/epoll is that it is just a patch. Linus does not like
new pseudo devices in the kernel.
He says we already have a dispatcher for the syscalls in the kernel, so if we
want to add something, we add a syscall and not a device or an ioctl.
So the author of /dev/epoll redid the API using syscalls. This API is was
merged into Linux 2.5 (since 2.5.51 even in the documented form ;-) ).
It is now the recommended API for event notification in Linux 2.6.
----
[Original] [Print] [Top]
« Previous thread
向高手请教linux下C语言网络编程的一个二难问题
C/C++编程版
63
Next thread »
紧急求助,关于自定义信号
     

Copyright © 2007~2009 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
webmaster: webmaster@unixresources.net
This page created on 2009-09-07 16:44:34, cost 0.0210311412811 ms.